将Python函数转换为Hive UDAF

时间:2017-04-26 20:23:51

标签: java python hive

如何将以下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)

感谢任何见解。

0 个答案:

没有答案