From 8103004c4ebeb638c873e6cacae9fdf3e7877548 Mon Sep 17 00:00:00 2001 From: Austin Blatt Date: Fri, 17 Sep 2021 11:40:30 -0700 Subject: [PATCH] (PDB-5278) Fix group by dotted fact path with forward slash 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. --- src/puppetlabs/puppetdb/query_eng/engine.clj | 2 +- test/puppetlabs/puppetdb/http/inventory_test.clj | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/puppetlabs/puppetdb/query_eng/engine.clj b/src/puppetlabs/puppetdb/query_eng/engine.clj index b289b8ec9f..12295771d0 100644 --- a/src/puppetlabs/puppetdb/query_eng/engine.clj +++ b/src/puppetlabs/puppetdb/query_eng/engine.clj @@ -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) diff --git a/test/puppetlabs/puppetdb/http/inventory_test.clj b/test/puppetlabs/puppetdb/http/inventory_test.clj index 2fd64af253..19d13a52d5 100644 --- a/test/puppetlabs/puppetdb/http/inventory_test.clj +++ b/test/puppetlabs/puppetdb/http/inventory_test.clj @@ -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}