Skip to content
Browse files

groupyby with sorting and updating project.clj

  • Loading branch information...
1 parent 10113df commit 228a66f16e7a393d49c936e0e0cc81cc874e1b87 Bradford Cross committed Mar 3, 2010
Showing with 23 additions and 16 deletions.
  1. +1 −1 project.clj
  2. +7 −2 src/clj/cascading/clojure/api.clj
  3. +15 −13 test/cascading/clojure/scenarios.clj
View
2 project.clj
@@ -8,6 +8,6 @@
:exclusions [javax.mail/mail janino/janino]]
[clj-json "0.2.0-SNAPSHOT"]]
:dev-dependencies [[lein-javac "0.0.2-SNAPSHOT"]
- [org.clojure/swank-clojure "1.0"]]
+ [swank-clojure "1.1.0"]]
:namespaces [cascading.clojure.api
cascading.clojure.testing])
View
9 src/clj/cascading/clojure/api.clj
@@ -170,8 +170,13 @@
"Takes Iterator<TupleEntry> and returns seq of tuples coerced to vectors."
(clojure.core/map #(Util/coerceFromTuple (.getTuple %)) (iterator-seq it)))
-(defn group-by [#^Pipe previous group-fields]
- (GroupBy. previous (fields group-fields)))
+(defn group-by
+ ([#^Pipe previous group-fields]
+ (GroupBy. previous (fields group-fields)))
+ ([previous group-fields sort-fields]
+ (GroupBy. previous (fields group-fields) (fields sort-fields)))
+ ([previous group-fields sort-fields reverse-order]
+ (GroupBy. previous (fields group-fields) (fields sort-fields) reverse-order)))
(defn first [#^Pipe previous]
(Every. previous (First.)))
View
28 test/cascading/clojure/scenarios.clj
@@ -51,16 +51,18 @@
(c/select joined ["num1" "num2" "num3"])))
[[5 1 8] [7 1 8] [6 2 7] [9 nil nil]]))
-;; (deftest group-and-aggregate-with-pred
-;; "group on x.
-;; pred ensures we have data for y.
-;; max on num."
-;; (test-flow
-;; (in-pipes {"p1" ["x" "y" "num"]})
-;; (in-tuples {"p1" [[0 1 5] [2 1 6] [0 nil 7]
-;; [0 1 1] [2 1 2] [2 nil 7] [0 nil 8]]})
-;; (fn [{p1 "p1"}]
-;; (let [grouped (c/group-by p1 ["x"])]
-;; (c/aggregate grouped
-;; ["x" "y" "num"] [["maxx" "maxy" "max"] #'predicated-max] ["maxx" "maxy" "max"])))
-;; [[0 5] [2 6]]))
+(deftest groupyby-with-sorting
+ (test-flow
+ (in-pipes {"p1" ["x" "y" "num"]
+ "p2" ["x" "y" "num"]})
+ (in-tuples {"p1" [[0 1 5] [2 1 6] [0 1 7] [1 7 9]]
+ "p2" [[0 1 7] [2 1 5] [0 1 6] [1 7 9]]})
+ (fn [{p1 "p1" p2 "p2"}]
+ (let [groups-left (c/group-by p1 ["x"] ["num"])
+ groups-right (c/group-by p2 ["y"] ["num"])
+ joined (c/join-into [groups-left groups-right]
+ [["x"]["y"]]
+ ["x1" "y1" "num1"
+ "x2" "y2" "num2"])]
+ (c/select joined ["num1" "num2"])))
+ [[5 nil] [7 nil] [9 5] [9 6] [9 7] [6 nil]]))

0 comments on commit 228a66f

Please sign in to comment.
Something went wrong with that request. Please try again.