Skip to content

Commit

Permalink
Don't treat isNull as a constant (#708)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwwoelfel authored Jan 14, 2025
1 parent 5509d0a commit d4b357b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
2 changes: 0 additions & 2 deletions server/src/instant/db/datalog.clj
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@
(def variable? (fn [x]
(and (symbol? x) (not= x '_))))

(def constant? (comp not symbol?))

(def named-variable? (partial uspec/tagged-as? :variable))
(def named-constant? (partial uspec/tagged-as? :constant))

Expand Down
19 changes: 10 additions & 9 deletions server/src/instant/db/instaql.clj
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,15 @@
(grow-paths path)))})

(and (map? v) (contains? v :$isNull) (= true (:$isNull v)))
;; If the where cond has `$isNull=true`, then we
;; need it should match if any of the intermediate
;; paths are null
(let [path (string/split (name k) #"\.")]
{:or (concat [[[path v]]]
(map (fn [p]
[[p {:$isNull true}]])
(grow-paths path)))})
;; If the where cond has `$isNull=true`, then we need it to
;; match if any of the intermediate paths are null
(let [path (string/split (name k) #"\.")
conds (map (fn [p]
[[p {:$isNull true}]])
(grow-paths path))]
(if (= 1 (count conds))
{:and conds}
{:or conds}))

:else [(string/split (name k) #"\.") v]))

Expand Down Expand Up @@ -568,7 +569,7 @@
[?e attr-id 5] => 5
[5 attr-id ?v] => 5"
[[e _ v :as _attr-pat]]
(some d/constant? [e v]))
(some attr-pat/constant-component? [e v]))

(defn- optimize-attr-pats
"Given a list of attr pats, this tries to return a list that will be more
Expand Down
6 changes: 5 additions & 1 deletion server/src/instant/db/model/attr_pat.clj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
)]
(if v-actualized? v-idx e-idx)))

(defn constant-component? [component]
(and (not (symbol? component))
(not (:$isNull component))))

(defn component-actualized?
"A component is actualized if:
a. It is a constant
Expand All @@ -57,7 +61,7 @@
[?bookshelves books-attr ?books]] ;; ?bookshelves is actualized (it's been bound)
"
[seen component]
(or (d/constant? component)
(or (constant-component? component)
(seen component)))

(defn attr-by-id
Expand Down

0 comments on commit d4b357b

Please sign in to comment.