From 5e9bdba77715cb3f7e995f82444250ec33908685 Mon Sep 17 00:00:00 2001 From: Sean Corfield Date: Mon, 16 Oct 2023 21:23:07 -0700 Subject: [PATCH] #510 basic facet support --- src/honey/sql.cljc | 20 ++++++++++++++++++-- src/honey/sql/helpers.cljc | 5 +++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/honey/sql.cljc b/src/honey/sql.cljc index d9935a9..63b34fe 100644 --- a/src/honey/sql.cljc +++ b/src/honey/sql.cljc @@ -63,6 +63,8 @@ :join :left-join :right-join :inner-join :outer-join :full-join :cross-join :where :group-by :having + ;; NRQL extension: + :facet :window :partition-by :order-by :limit :offset :fetch :for :lock :values :on-conflict :on-constraint :do-nothing :do-update-set :on-duplicate-key-update @@ -676,8 +678,8 @@ (defn- format-selects [k xs] (format-selects-common (sql-kw k) - (#{:select :select-distinct :from :window :delete-from - 'select 'select-distinct 'from 'window 'delete-from} + (#{:select :select-distinct :from :window :delete-from :facet + 'select 'select-distinct 'from 'window 'delete-from 'facet} k) xs)) @@ -1445,6 +1447,7 @@ :returning #'format-selects :with-data #'format-with-data ;; NRQL extensions: + :facet #'format-selector :since #'format-interval :until #'format-interval :compare-with #'format-interval @@ -2319,4 +2322,17 @@ (sql/format-expr [:over [[:array_agg {:expr [:respect-nulls :a] :order-by :a :limit 10}] {:partition-by :something}]]) + ;; doesn't work yet -- requires [:auto] + (sql/format {:select :col :from :data :timeseries :auto} {:dialect :nrql}) + (sql/format {:select [[[:latest (keyword "Elastic/Search OK Count/value")]] + [[:latest (keyword "Elastic/Search Fail Count/value")]] + [[:* 100 [:latest :Sent/rate]] "Sent/rate x 100"]] + :from :Metric + :where [:some :value] + #_[:and [:= :environment "production"] + [:= :process.name "match"]] + :facet [:some.metric :alias] + :since [1 :day :ago] + :timeseries [:auto]} + {:dialect :nrql}) ) diff --git a/src/honey/sql/helpers.cljc b/src/honey/sql/helpers.cljc index 3251931..d43f533 100644 --- a/src/honey/sql/helpers.cljc +++ b/src/honey/sql/helpers.cljc @@ -1020,6 +1020,11 @@ ;; nrql-specific helpers: +(defn facet + "(facet [:metric.name :alias])" + [& args] + (generic-1 :facet args)) + (defn since "(since 2 :days :ago)" [& args]