如何将以下Python函数longToDigitArray
转换为HiveQL UDAF?我不熟悉Java。
# convert source (e.g. 2305843012434919424, into a list of source flags)
# Desired behavior:
# Input: longToDigitArray(2305843012434919424)
# Output: [31, 32, 62]
def longToDigitArray(x):
a=[]
i=1
try:
x=long(x)
except:
return(a)
while (x!=0):
if (x & 1): # "Bitwise AND" &: Returns a 1 in each bit position for which the corresponding bits of both operands are 1's.
a.append(i)
x = (x >> 1) # bitwise right-shift 1
i = i+1
return(a)
感谢任何见解。