Permalink
Browse files

example buffer test with multiple passes over the sequence of tuples.

  • Loading branch information...
1 parent f523b39 commit b1c1bee22dcc7184f1f1434919cb3c69b68dff5d Bradford Cross committed Feb 19, 2010
Showing with 28 additions and 1 deletion.
  1. +28 −1 test/cascading/clojure/buffer_test.clj
@@ -1,6 +1,7 @@
(ns cascading.clojure.buffer-test
(:use clojure.test
clojure.contrib.java-utils
+ clojure.contrib.seq-utils
cascading.clojure.testing
cascading.clojure.io)
(:import (cascading.tuple Fields)
@@ -27,4 +28,30 @@
(c/buffer ["word" "subcount"] [["word1" "subcount1"] #'maxbuff]
["word1" "subcount1"])))
- [["bar" 3] ["bat" 7]]))
+ [["bar" 3] ["bat" 7]]))
+
+;;Note that you can not walk the tuple iterator more than once
+;;but you can hold on to the seq and walk that more than once.
+(defn maxpairs [it]
+ (let [maxer (fn [max-tuple next-tuple]
+ (if (> (second max-tuple) (second next-tuple))
+ max-tuple
+ next-tuple))
+ tuples (c/tuple-seq it)
+ biggest (reduce maxer tuples)
+ pairs (for [x tuples
+ :when (not (= x biggest))]
+ (flatten (cons x biggest)))]
+ pairs))
+
+(deftest buffer-test
+ (test-flow
+ (in-pipes ["word" "subcount"])
+ (in-tuples [["bar" 1] ["bat" 7] ["bar" 3] ["bar" 2] ["bat" 4]])
+ (fn [in] (-> in
+ (c/group-by "word")
+
+ (c/buffer [["word1" "subcount1" "maxword" "maxsubcount"]
+ #'maxpairs])))
+ [["bar" 1 "bar" 3] ["bar" 2 "bar" 3]
+ ["bat" 4 "bat" 7]]))

0 comments on commit b1c1bee

Please sign in to comment.