Permalink
Browse files

adding default Fields/ARGS behavior to parse-func

  • Loading branch information...
1 parent 1ef04e1 commit c3b56c1082412da9e245222dfaa49a2c4fba4faf Bradford Cross committed Feb 19, 2010
Showing with 6 additions and 7 deletions.
  1. +4 −4 src/clj/cascading/clojure/api.clj
  2. +2 −3 test/cascading/clojure/buffer_test.clj
View
8 src/clj/cascading/clojure/api.clj
@@ -81,6 +81,7 @@
; out-fields: subset of (union in-fields func-fields) that flow out of the pipe
; defaults to func-fields
+;;regarding the operation's fields declarations, if you resort to Fields/UNKNOWN, you will lose all your field names. you should deafult the fields declarations to Fields/ARGS. This means you emit the same fields that you take in via the input selector - a common scenario. If you want to add new fields or change them, you must explicitly declare them. Regarding iput selectors, Fields/All is the logical default. Chris says that - regarding the outputselector - we might tend to use Fields/Results more for each and Fields/All more for every, but perhaps fields/RESULTS is the best fit for out way of thinking.
(defn- parse-func [func-obj]
"func-obj =>
#'func
@@ -94,10 +95,9 @@
(let [spec (fn-spec (drop i func-obj))
func-var (nth func-obj i)
func-fields (or (and (= i 1) (clojure.core/first func-obj))
- ((meta func-var) :fields))]
- (when-not func-fields
- (throw (Exception. (str "no fields assocaiated with " func-obj))))
- [(fields func-fields) spec])))
+ ((meta func-var) :fields))
+ function-fields (if func-fields (fields func-fields) Fields/ARGS)]
+ [function-fields spec])))
(defn- parse-args
"arr =>
View
5 test/cascading/clojure/buffer_test.clj
@@ -26,7 +26,7 @@
(fn [in] (-> in
(c/group-by "word")
- (c/buffer [["word1" "subcount1"] #'maxbuff])))
+ (c/buffer #'maxbuff)))
[["bar" 3] ["bat" 7]]))
;;Note that you can not walk the tuple iterator more than once
@@ -49,8 +49,7 @@
(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"]
+ (c/buffer [["word" "subcount" "maxword" "maxsubcount"]
#'maxpairs])))
[["bar" 1 "bar" 3]
["bar" 2 "bar" 3]

0 comments on commit c3b56c1

Please sign in to comment.