Skip to content

Commit 5e0b2d2

Browse files
author
Beau Fabry
committed
fix for ops that return nil
1 parent ba49f30 commit 5e0b2d2

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

cascalog-core/src/clj/cascalog/in_memory/platform.clj

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,13 @@
204204

205205
(defmethod op-clojure ::d/map
206206
[coll op input output]
207-
(map
208-
(fn [tuple]
209-
(let [v (s/collectify (apply op (t/select-values input tuple)))
210-
new-tuple (t/to-tuple output v)]
211-
(merge tuple new-tuple)))
212-
coll))
207+
(->> coll
208+
(map
209+
(fn [tuple]
210+
(let [v (s/collectify (or (apply op (t/select-values input tuple)) [nil]))
211+
new-tuple (t/to-tuple output v)]
212+
(merge tuple new-tuple))))
213+
(filter #(not-any? (fn [[name v]] (and (.startsWith name "?") (nil? v))) %))))
213214

214215
(defmethod op-clojure ::d/mapcat
215216
[coll op input output]

cascalog-core/src/clj/cascalog/in_memory/tuple.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
[names v]
1212
(if (= (count names) (count v))
1313
(zipmap names v)
14-
(u/throw-illegal "Output variables arity and function output arity do not match")))
14+
(u/throw-illegal (str "Output variables arity and function output arity do not match: " names " -> " v))))
1515

1616
(defn to-tuples
1717
"turns [\"n\"] and [[1] [2]] into [{\"n\" 1} {\"n\" 2}]"

cascalog-core/test/cascalog/in_memory_api_test.clj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,14 @@
2626
(is (= [{"?n" 1} {"?n" 2} {"?n" 3}]
2727
@results)))))
2828

29+
(deftest test-nil-collect
30+
(is (= [[nil]]
31+
(??<- [!nilval]
32+
([1] :> ?val)
33+
(identity nil :> !nilval)))))
34+
35+
(deftest test-nil-collect-to-not-nil-var
36+
(is (= []
37+
(??<- [?nilval]
38+
([1] :> ?val)
39+
(identity nil :> ?nilval)))))

0 commit comments

Comments
 (0)