Skip to content

Instantly share code, notes, and snippets.

@matpalm
Created July 1, 2011 03:40
Show Gist options
  • Save matpalm/1057825 to your computer and use it in GitHub Desktop.
Save matpalm/1057825 to your computer and use it in GitHub Desktop.
hadoop 0.18 counter grammar
# "a.b:1" => [["a", "b", 1]]
# "a.b:1,c.d:2" => [["a", "b", 1], ["c", "d", 2]]
grammar Hadoop18Counters
rule counter_records
counter_record ("," counter_record)* {
def to_list
items = elements[0].to_list
if elements[1]
elements[1].elements.each do |e|
items << e.elements[1].to_list
end
end
items
end
}
end
rule counter_record
group:string "." name:string ":" count:int {
def to_list
[group.text_value, name.text_value, count.text_value.to_i]
end
}
end
rule string
[^:\.]+
end
rule int
[0-9]+
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment