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
input = {"Root"=>[{"1"=>[{"4"=>"leaf4", "5"=>"leaf5"}]}, {"2"=>[{"6"=>"leaf6", "7"=>"leaf7"}]}]} | |
def traverse(path = "") | |
self.each do|key, value| | |
if value.is_a?(Hash) | |
path += "#{key}=>" | |
value.traverse(path) | |
else | |
if value.is_a?(Array) | |
path += "#{key}=>" |
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 contrib/piggybank/java/piggybank.jar | |
DEFINE SUBSTRING org.apache.pig.piggybank.evaluation.string.SUBSTRING(); | |
A = load 'gutenberg/sample.txt'; | |
C = foreach A generate SUBSTRING((chararray)$0, 0, 5); | |
dump C; |
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
A = load '/tmp/alice.txt'; | |
B = foreach A generate flatten(TOKENIZE((chararray)$0)) as word; | |
C = filter B by word matches '\\w+'; | |
D = group C by word; | |
E = foreach D generate COUNT(C), group; | |
store E into '/tmp/alice_wordcount'; |
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
# CLOSURES IN RUBY Paul Cantrell http://innig.net | |
# Email: username "cantrell", domain name "pobox.com" | |
# I recommend executing this file, then reading it alongside its output. | |
# | |
# Alteratively, you can give yourself a sort of Ruby test by deleting all the comments, | |
# then trying to guess the output of the code! | |
# A closure is a block of code which meets three criteria: | |
# |