Skip to content

Commit 17b4fad

Browse files
committed
(PDB-5161) engine: use parse-field instead of string operations
Replace various remaining uses of string operations like splitting a field on #"\." with parse-field.
1 parent 0507e0b commit 17b4fad

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/puppetlabs/puppetdb/query_eng/engine.clj

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,7 +2062,9 @@
20622062
"Argument \"{0}\" is incompatible with numeric field \"{1}\"."
20632063
value (name field))))))
20642064

2065-
[[(:or ">" ">=" "<" "<=") (field :guard #(not (str/includes? % "."))) _]]
2065+
[[(:or ">" ">=" "<" "<=")
2066+
(field :guard #(= (count (parse/parse-field %)) 1))
2067+
_]]
20662068
(let [col-type (get-in query-context [:projections field :type])]
20672069
(when-not (or (vec? field)
20682070
(contains? #{:numeric :timestamp :jsonb-scalar}
@@ -2366,8 +2368,9 @@
23662368
:value value}))
23672369

23682370
[["=" column-name value]]
2369-
(let [colname (first (str/split column-name #"\."))
2370-
cinfo (get-in query-rec [:projections colname])]
2371+
;; FIXME: pass parsed representation down
2372+
(let [[top & path] (parse/parse-field column-name)
2373+
cinfo (get-in query-rec [:projections (:name top)])]
23712374
(case (:type cinfo)
23722375
:timestamp
23732376
(map->BinaryExpression {:operator :=
@@ -2384,7 +2387,7 @@
23842387
:value (facts/factpath-to-string value)})
23852388

23862389
:queryable-json
2387-
(if (string/includes? column-name "[")
2390+
(if (some #(= ::parse/indexed-field-part (:kind %)) path)
23882391
(map->JsonbPathBinaryExpression {:field column-name
23892392
:column-data cinfo
23902393
:value value
@@ -2442,8 +2445,9 @@
24422445
(map str value))})))
24432446

24442447
[[(op :guard #{">" "<" ">=" "<="}) column-name value]]
2445-
(let [colname (first (str/split column-name #"\."))
2446-
{:keys [type] :as cinfo} (get-in query-rec [:projections colname])]
2448+
;; FIXME: pass parsed representation down
2449+
(let [[top & path] (parse/parse-field column-name)
2450+
{:keys [type] :as cinfo} (get-in query-rec [:projections (:name top)])]
24472451
(cond
24482452
(= :timestamp type)
24492453
(map->BinaryExpression {:operator (keyword op)
@@ -2498,8 +2502,9 @@
24982502
(map->NullExpression {:column cinfo :null? value})))
24992503

25002504
[["~" column-name value]]
2501-
(let [colname (first (str/split column-name #"\."))
2502-
cinfo (get-in query-rec [:projections colname])]
2505+
;; FIXME: pass parsed representation down
2506+
(let [[top] (parse/parse-field column-name)
2507+
cinfo (get-in query-rec [:projections (:name top)])]
25032508
(case (:type cinfo)
25042509
:array
25052510
(map->ArrayRegexExpression {:column cinfo :value value})

0 commit comments

Comments
 (0)