Skip to content

Instantly share code, notes, and snippets.

@erasmas
Created November 12, 2014 16:54
Show Gist options
  • Save erasmas/eaff8ee6f9feb7700622 to your computer and use it in GitHub Desktop.
Save erasmas/eaff8ee6f9feb7700622 to your computer and use it in GitHub Desktop.
Using aggregations in Cascalog
(def test-tap [["a" "x1" 0 1 0]
["a" "x2" 1 0 1]
["b" "bar" 0 1 0]
["b" "foo" 1 1 0]])
(defaggregatefn dosum
([] 0)
([state val] (+ state val))
([state] [state]))
(defaggregatefn agg-strings
([] "")
([state val] (str val "|" state))
([state] [state]))
(??<- [?id ?s-out ?a-out ?b-out ?c-out]
(test-tap :> ?id ?s ?a ?b ?c)
(dosum ?a :> ?a-out)
(dosum ?b :> ?b-out)
(dosum ?c :> ?c-out)
(agg-strings ?s :> ?s-out))
;;=> (["a" "x1|x2|" 1 1 1] ["b" "bar|foo|" 1 2 0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment