Skip to content

Commit

Permalink
(PDB-5278) Fix group by dotted fact path with forward slash
Browse files Browse the repository at this point in the history
When grouping by a keyword, honeysql will convert the keyword to SQL by
calling `name` on it. But that will not return the entire fact name when
there's a forward slash in it because Clojure interprets everything
before the forward slash as the "namespace" and everything after as the
"name".

```
=> (name :facts.foo)
"facts.foo"
=> (name :facts.f/oo)
"oo"
=> (namespace :facts.f/oo)
"facts.f"
```

This commit changes the query engine to use sql raw instead of the
keyword to avoid splitting on forward slashes.
  • Loading branch information
austb committed Dec 2, 2021
1 parent c87a69c commit 8103004
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/puppetlabs/puppetdb/query_eng/engine.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2265,7 +2265,7 @@
:field]))
;; Turn facts.foo into a double quoted keyword so that the SQL identifier `:"facts.foo"`
;; matches the extraction of (fs.volatile||fs.stable) AS "facts.foo" from the selection
(keyword (jdbc/double-quote column-or-fn-name))
(htypes/raw (jdbc/double-quote column-or-fn-name))
(or (get-in query-rec [:projections column-or-fn-name :field])
(if (some #{column-or-fn-name} (keys pdb-fns->pg-fns))
(keyword column-or-fn-name)
Expand Down
8 changes: 8 additions & 0 deletions test/puppetlabs/puppetdb/http/inventory_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@
["null?" "facts" true]
#{}

["extract" ["facts.foo"]
["group_by" "facts.foo"]]
#{{:facts.foo nil}}

["extract" ["facts.f/oo"]
["group_by" "facts.f/oo"]]
#{{:facts.f/oo nil}}

["extract" [["function", "count"] "facts.domain"]
["group_by" "facts.domain"]]
#{{:facts.domain "testing.com" :count 2}
Expand Down

0 comments on commit 8103004

Please sign in to comment.