Skip to content

Commit

Permalink
Fix bug with or/or-join when shortcircuiting resolve-clause
Browse files Browse the repository at this point in the history
  • Loading branch information
galdre authored and tonsky committed Feb 15, 2024
1 parent 658390a commit 251ac43
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/datascript/query.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@
(= attrs-a attrs-b)
(Relation. attrs-a (into (vec tuples-a) tuples-b))

(not (same-keys? attrs-a attrs-b))
(and (not (same-keys? attrs-a attrs-b))
(seq tuples-a) ; could be empty because
(seq tuples-b)) ; a query short-circuited
(raise "Can’t sum relations with different attrs: " attrs-a " and " attrs-b
{:error :query/where})

Expand Down
20 changes: 18 additions & 2 deletions test/datascript/test/query_or.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,23 @@
(or-join [?e]
(and [?e :age ?a]
[?e2 :age ?a]))]
#{1 2 3 4 5 6})
#{1 2 3 4 5 6}

[(or-join [?e ?n]
(and [?e :age 30] ; no matches, so this branch short-circuits
[?e :name ?n])
(and [?e :age 20]
[?e :name ?n]))
[(ground "Ivan") ?n]]
#{2 6}

[(or
(and [?e :age 30] ; no matches, so this branch short-circuits
[?e :name ?n])
(and [?e :age 20]
[?e :name ?n]))
[(ground "Ivan") ?n]]
#{2 6})

;; #348
(is (= #{[1] [3] [4] [5]}
Expand Down Expand Up @@ -184,4 +200,4 @@
(d/q '[:find ?e
:where (or-join [[?e]]
[?e :name "Ivan"])]
@test-db))))
@test-db))))

0 comments on commit 251ac43

Please sign in to comment.