Browse files

Issue #58: ??- now allows for an optional query name

??- now supports an optional first string argument, which will be used
as the name of the query and will show up in the JobTracker UI.
  • Loading branch information...
1 parent bcf2165 commit 6d14435514af708ae1e9d035bd37d4f92b4e2311 @sthuebner committed Jun 30, 2012
Showing with 18 additions and 10 deletions.
  1. +12 −9 src/clj/cascalog/api.clj
  2. +6 −1 test/cascalog/api_secondary_test.clj
View
21 src/clj/cascalog/api.clj
@@ -210,15 +210,18 @@
"Executes one or more queries and returns a seq of seqs of tuples
back, one for each subquery given.
- Syntax: (??- sink1 query1 sink2 query2 ...)"
- [& subqueries]
- ;; TODO: should be checking for flow name here
- (io/with-fs-tmp [fs tmp]
- (hadoop/mkdirs fs tmp)
- (let [outtaps (for [q subqueries] (hfs-seqfile (str tmp "/" (u/uuid))))
- bindings (mapcat vector outtaps subqueries)]
- (apply ?- bindings)
- (doall (map rules/get-sink-tuples outtaps)))))
+ Syntax: (??- query1 query2 ...) or (??- query-name query1 query2 ...)
+
+ If the first argument is a string, that will be used as the name
+ for the query and will show up in the JobTracker UI."
+ [& args]
+ (let [[name [& subqueries]] (rules/parse-exec-args args)]
+ (io/with-fs-tmp [fs tmp]
+ (hadoop/mkdirs fs tmp)
+ (let [outtaps (for [q subqueries] (hfs-seqfile (str tmp "/" (u/uuid))))
+ bindings (mapcat vector outtaps subqueries)]
+ (apply ?- name bindings)
+ (doall (map rules/get-sink-tuples outtaps))))))
(defmacro ?<-
"Helper that both defines and executes a query in a single call.
View
7 test/cascalog/api_secondary_test.clj
@@ -133,7 +133,12 @@
(<- [?n2]
(nums ?n)
(inc ?n :> ?n2)
- (:distinct false))))))
+ (:distinct false)))
+ (is (= '(([1] [2]))
+ (??- "flow3"
+ (<- [?n]
+ (nums ?n)
+ (:distinct false))))))))
(deftest test-data-structure
(let [src [[1 5] [5 6] [8 2]]

0 comments on commit 6d14435

Please sign in to comment.