Skip to content

Commit 83073dd

Browse files
committed
(PDB-5161) engine: handle AST null? operator fields via parse-field
See the comments for some additional information.
1 parent d9a4238 commit 83073dd

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/puppetlabs/puppetdb/query_eng/engine.clj

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2473,17 +2473,27 @@
24732473
value op)))))
24742474

24752475
[["null?" column-name value]]
2476-
(let [maybe-dotted-path (str/split column-name #"\.")
2477-
cinfo (get-in query-rec [:projections (first maybe-dotted-path)])]
2478-
2476+
;; For now, this assumes that foo[5] and match(...) are
2477+
;; just custom fact names, and doesn't handle foo.5.bar as
2478+
;; a foo array access, to maintain backward compatibility,
2479+
;; i.e. create-json-path-extraction doesn't do anything
2480+
;; but single quote the compoents for a pg json path
2481+
;; lookup, e.g. json->'x'->'y'. If we want null? to work
2482+
;; on nested arrays, then we'll need to distinguish,
2483+
;; i.e. foo.b'ar[5].baz should become
2484+
;; foo->'b''ar'->5->'baz'.
2485+
;; cf. https://www.postgresql.org/docs/11/functions-json.html
2486+
(let [[top & path] (parse/parse-field column-name 0
2487+
{:indexes? false
2488+
:matches? false})
2489+
cinfo (get-in query-rec [:projections (:name top)])]
24792490
(if (and (= :queryable-json (:type cinfo))
2480-
(seq? (rest maybe-dotted-path)))
2491+
(seq path))
24812492
(let [field (name (h/extract-sql (:field cinfo)))
2482-
dotted-path (->> maybe-dotted-path rest (str/join "."))
2483-
json-path (->> (parse/dotted-query->path dotted-path)
2484-
(map parse/maybe-strip-escaped-quotes ))
2485-
path-extraction-field (jdbc/create-json-path-extraction field json-path)]
2486-
(map->NullExpression {:column (assoc cinfo :field (hcore/raw path-extraction-field))
2493+
json-path (->> (map :name path)
2494+
(jdbc/create-json-path-extraction field)
2495+
hcore/raw)]
2496+
(map->NullExpression {:column (assoc cinfo :field json-path)
24872497
:null? value}))
24882498
(map->NullExpression {:column cinfo :null? value})))
24892499

0 commit comments

Comments
 (0)