Skip to content

Commit 004d943

Browse files
committed
(PDB-5161) Drop json-contains; inline the code in the one caller
Remove json-contains in favor of just inlining the code since there's only one caller, and it's perhaps a bit more immediately obvious what's going on. Explain the code's purpose a bit.
1 parent d482ebd commit 004d943

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/puppetlabs/puppetdb/query_eng/engine.clj

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,10 +1528,15 @@
15281528

15291529
JsonContainsExpression
15301530
(-plan->sql [{:keys [field column-data array-in-path]} options]
1531-
(su/json-contains (if (instance? SqlRaw (:field column-data))
1532-
(-> column-data :field :s)
1533-
field)
1534-
array-in-path))
1531+
(let [f (if (instance? SqlRaw (:field column-data))
1532+
(-> column-data :field :s)
1533+
field)]
1534+
;; This distinction is necessary (at least) because @> cannot
1535+
;; traverse into arrays, but should be otherwise preferred
1536+
;; because it can use an index.
1537+
(if array-in-path
1538+
(hcore/raw (format "%s #> ? = ?" f))
1539+
(hcore/raw (format "%s @> ?" f)))))
15351540

15361541
FnBinaryExpression
15371542
(-plan->sql [{:keys [value function args operator]} options]

src/puppetlabs/puppetdb/scf/storage_utils.clj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,6 @@
244244
(hcore/raw
245245
(format "%s = ANY(?)" (first (hfmt/format column)))))
246246

247-
(defn json-contains
248-
[field array-in-path]
249-
(if array-in-path
250-
(hcore/raw (format "%s #> ? = ?" field))
251-
(hcore/raw (format "%s @> ?" field))))
252-
253247
(defn jsonb-path-binary-expression
254248
"Produce a predicate that compares against nested value with op and checks the
255249
existence of a (presumably) top-level value. The existence check is necessary

0 commit comments

Comments
 (0)