Skip to content
Snippets Groups Projects
Unverified Commit ef4170a7 authored by Cam Saul's avatar Cam Saul
Browse files

Merge branch 'hyperunique' [ci drivers]

parents 55b7665c 2e1c6e1f
No related branches found
No related tags found
No related merge requests found
......@@ -70,27 +70,40 @@
;;; ### Sync
(defn- describe-table-field [druid-field-type field-name]
(defn- do-segment-metadata-query [details datasource]
(do-query details {"queryType" "segmentMetadata"
"dataSource" datasource
"intervals" ["1999-01-01/2114-01-01"]
"analysisTypes" []
"merge" true}))
(defn- druid-type->base-type [field-type]
(case field-type
"STRING" :type/Text
"FLOAT" :type/Float
"LONG" :type/Float
"hyperUnique" :type/DruidHyperUnique
:type/Float))
(defn- describe-table-field [[field-kw {:keys [type]}]]
;; all dimensions are Strings, and all metrics as JS Numbers, I think (?)
;; string-encoded booleans + dates are treated as strings (!)
(assoc (case druid-field-type
:metric {:database-type "metric", :base-type :type/Float}
:dimension {:database-type "dimension", :base-type :type/Text})
:name field-name))
{:name (name field-kw)
:base-type (druid-type->base-type type)
:database-type type})
(defn- describe-table [database table]
(ssh/with-ssh-tunnel [details-with-tunnel (:details database)]
(let [{:keys [dimensions metrics]} (GET (details->url details-with-tunnel "/druid/v2/datasources/" (:name table) "?interval=1900-01-01/2100-01-01"))]
(let [{:keys [columns]} (first (do-segment-metadata-query details-with-tunnel (:name table)))]
{:schema nil
:name (:name table)
:fields (set (concat
;; every Druid table is an event stream w/ a timestamp field
[{:name "timestamp"
:database-type "timestamp"
:base-type :type/DateTime
:pk? true}]
(map (partial describe-table-field :dimension) dimensions)
(map (partial describe-table-field :metric) metrics)))})))
;; every Druid table is an event stream w/ a timestamp field
[{:name "timestamp"
:database-type "timestamp"
:base-type :type/DateTime
:pk? true}]
(map describe-table-field (dissoc columns :__time))))})))
(defn- describe-database [database]
{:pre [(map? (:details database))]}
......
......@@ -73,9 +73,10 @@
(extend-protocol IDimensionOrMetric
Field (dimension-or-metric? [{:keys [base-type]}]
(cond
(isa? base-type :type/Text) :dimension
(isa? base-type :type/Float) :metric
(isa? base-type :type/Integer) :metric))
(isa? base-type :type/Text) :dimension
(isa? base-type :type/Float) :metric
(isa? base-type :type/Integer) :metric
(isa? base-type :type/DruidHyperUnique) :metric))
DateTimeField (dimension-or-metric? [this]
(dimension-or-metric? (:field this))))
......@@ -217,6 +218,16 @@
(defn- ag:filtered [filtr aggregator] {:type :filtered, :filter filtr, :aggregator aggregator})
(defn- ag:distinct [field output-name]
(if (= (:base-type field) :type/DruidHyperUnique)
{:type :hyperUnique
:name output-name
:fieldName (->rvalue field)}
{:type :cardinality
:name output-name
:fieldNames [(->rvalue field)]}))
(defn- ag:count
([output-name] {:type :count, :name output-name})
([field output-name] (ag:filtered (filter:not (filter:nil? field))
......@@ -243,9 +254,7 @@
:fields [{:type :fieldAccess, :fieldName sum-name}
{:type :fieldAccess, :fieldName count-name}]}]}])
[:distinct _] [[(or output-name-kwd :distinct___count)]
{:aggregations [{:type :cardinality
:name (or output-name :distinct___count)
:fieldNames [(->rvalue ag-field)]}]}]
{:aggregations [(ag:distinct ag-field (or output-name :distinct___count))]}]
[:sum _] [[(or output-name-kwd :sum)] {:aggregations [(ag:doubleSum ag-field (or output-name :sum))]}]
[:min _] [[(or output-name-kwd :min)] {:aggregations [(ag:doubleMin ag-field (or output-name :min))]}]
[:max _] [[(or output-name-kwd :max)] {:aggregations [(ag:doubleMax ag-field (or output-name :max))]}])))
......
......@@ -67,6 +67,7 @@
(derive :type/Boolean :type/*)
(derive :type/Enum :type/*)
(derive :type/DruidHyperUnique :type/*)
;;; Text-Like Types: Things that should be displayed as text for most purposes but that *shouldn't* support advanced
;;; filter options like starts with / contains
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment