Browse files

Merge pull request #88 from sthuebner/Issue#58

Issue #58: ??- now allows for an optional query name
  • Loading branch information...
2 parents 83ef76b + 6d14435 commit a7220bcf281101717d2caa58b34c083db828a513 @sritchie sritchie committed Jul 2, 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 a7220bc

Please sign in to comment.