Apache pig 猪:从右边算位置?
我的猪脚本中有一个元组:Apache pig 猪:从右边算位置?,apache-pig,Apache Pig,我的猪脚本中有一个元组: ((,v1,fb,fql)) 我知道我可以从左边选择$0(空白)、$1(“v1”)等元素,但我可以从右边选择元素吗?元组的长度不同,但我始终希望得到最后一个元素 你不能。但是,您可以编写python UDF来提取它: # Make sure to include the appropriate ouputSchema def getFromBack(TUPLE, pos): # gets elements from the back of TUPLE
((,v1,fb,fql))
我知道我可以从左边选择$0(空白)、$1(“v1”)等元素,但我可以从右边选择元素吗?元组的长度不同,但我始终希望得到最后一个元素 你不能。但是,您可以编写python UDF来提取它:
# Make sure to include the appropriate ouputSchema
def getFromBack(TUPLE, pos):
# gets elements from the back of TUPLE
# You can also do TUPLE[-pos], but this way it starts at 0 which is closer
# to Pig
return TUPLE[::-1][pos]
# This works the same way as above, but may be faster
# return TUPLE[-(pos + 1)]
用起来像:
register 'myudf.py' using jython as pythonUDFs ;
B = FOREACH A GENERATE pythonUDFs.getFromBack(T, 0) ;