我的猪剧本里有一个元组:
((,v1,fb,fql))我知道我可以从左边选择元素,如$0 (空白),$1 ("v1")等等,但是我可以从右边选择元素吗?元组将是不同的长度,但我总是想得到最后一个元素。
发布于 2014-04-04 01:07:52
但是,您可以编写一个python来提取它:
# 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) ;https://stackoverflow.com/questions/22774596
复制相似问题