Last active
December 22, 2015 21:39
-
-
Save sudar/6534857 to your computer and use it in GitHub Desktop.
Writing Pig UDF function using Python. Details at http://sudarmuthu.com/blog/writing-pig-udf-functions-using-python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_length(data): | |
return len(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@outputSchema("num:long") | |
def get_length(data): | |
return len(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REGISTER 'udf.py' USING jython as pyudf | |
A = LOAD 'data.txt' USING PigStorage(); | |
B = FOREACH A GENERATE $0, pyudf.get_length($0); | |
DUMP B; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@outputSchema("num:long") | |
def get_length(data): | |
str_data = ''.join([chr(x) for x in data]) | |
return len(str_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment