Merge branch 'master' of github.com:y42/clj-druid

This commit is contained in:
Guillaume Buisson 2016-03-17 11:09:21 +01:00
commit b134bf5cca
4 changed files with 33 additions and 11 deletions

View file

@ -1,4 +1,4 @@
(defproject y42/clj-druid "0.2.11" (defproject y42/clj-druid "0.2.12"
:description "Clojure library for Druid.io" :description "Clojure library for Druid.io"
:url "http://github.com/y42/clj-druid" :url "http://github.com/y42/clj-druid"
:license {:name "Eclipse Public License" :license {:name "Eclipse Public License"

View file

@ -54,20 +54,15 @@
:name s/Str :name s/Str
:fieldName s/Str}) :fieldName s/Str})
(declare aggregation)
(s/defschema filteredAggregator (s/defschema filteredAggregator
"A filtered aggregator wraps any given aggregator, but only aggregates the values for which the given dimension filter matches. "A filtered aggregator wraps any given aggregator, but only aggregates the values for which the given dimension filter matches.
This makes it possible to compute the results of a filtered and an unfiltered aggregation simultaneously, without having to issue multiple queries, and use both results as part of post-aggregations." This makes it possible to compute the results of a filtered and an unfiltered aggregation simultaneously, without having to issue multiple queries, and use both results as part of post-aggregations."
{:type (s/enum :filtered) {:type (s/enum :filtered)
:filter Filter :filter Filter
:aggregator (s/conditional (s/optional-key :name) s/Str
#(= :count (:type %)) countAggregator :aggregator (s/recursive #'aggregation)})
#(= :longSum (:type %)) longSumAggregator
#(= :doubleSum (:type %)) doubleSumAggregator
#(= :min (:type %)) minAggregator
#(= :max (:type %)) maxAggregator
#(= :javascript (:type %)) javascriptAggregator
#(= :cardinality (:type %)) cardinalityAggregator
#(= :hyperUnique (:type %)) hyperUniqueAggregator)})
(s/defschema aggregation (s/defschema aggregation
"Aggregations are specifications of processing over metrics available in Druid" "Aggregations are specifications of processing over metrics available in Druid"

View file

@ -45,6 +45,8 @@ Selector filters can be used as the base filters for more complex Boolean expres
#(= :regex (:type %)) regexFilter #(= :regex (:type %)) regexFilter
#(= :javascript (:type %)) javascriptFilter #(= :javascript (:type %)) javascriptFilter
#(= :spatial (:type %)) spatialFilter #(= :spatial (:type %)) spatialFilter
#(= :not (:type %)) {:type (s/enum :not)
:field (s/recursive #'Filter)}
#(or (= :or (:type %)) #(or (= :or (:type %))
(= :and (:type %))) {:type (s/enum :or :and) (= :and (:type %))) {:type (s/enum :or :and)
:fields [(s/recursive #'Filter)]})) :fields [(s/recursive #'Filter)]}))

View file

@ -104,13 +104,34 @@
:maxCoords [3 4]}} :maxCoords [3 4]}}
:pagingSpec {:pagingIdentifiers {} :threshold 5}}) :pagingSpec {:pagingIdentifiers {} :threshold 5}})
(def valid-topN-query (def valid-topN-query
(into valid-timeseries-query {:queryType :topN (into valid-timeseries-query {:queryType :topN
:dimension "dim1" :dimension "dim1"
:threshold 5 :threshold 5
:metric "count"})) :metric "count"}))
(def valid-filtered-aggregation
{:queryType :timeseries
:dataSource "dev.supercell"
:granularity :all
:intervals ["2016-03-17T07:30:10.476/2016-03-17T08:30:10.476"]
:filter {:type :selector
:dimension "project_id"
:value "vgteam-TV_Shows"}
:aggregations [{:type :filtered
:filter {:type :selector
:dimension "img-adult"
:value "false"}
:aggregator {:type :filtered
:aggregator {:type :longSum
:name "qualityRows"
:fieldName "count" }
:filter {:type :not
:field {:type :selector
:dimension "quality"
:value nil}}
:name "img-adult->false->qualityRows"}}]})
(deftest test-valid-groupby-query (deftest test-valid-groupby-query
(is (= (validate-groupby valid-groupby-query) (is (= (validate-groupby valid-groupby-query)
valid-groupby-query))) valid-groupby-query)))
@ -131,6 +152,10 @@
(is (= (validate-timeseries valid-timeseries-query) (is (= (validate-timeseries valid-timeseries-query)
valid-timeseries-query))) valid-timeseries-query)))
(deftest test-valid-filtered-aggregation
(is (= (validate-timeseries valid-filtered-aggregation)
valid-filtered-aggregation)))
(deftest test-valid-topN-query (deftest test-valid-topN-query
(is (= (validate-topN valid-topN-query) (is (= (validate-topN valid-topN-query)
valid-topN-query))) valid-topN-query)))