* Add function to allow for query execution without validation, fixes #25 - Using s/defn to allow for client to decide when to use validation - Add new function (`execute`) to keep backward compatability - Fixed error in schema for `timeseries` - Updated README.md - Remove use of swiss-arrow * as pr review
This commit is contained in:
parent
00a10d0bb8
commit
37fc967f00
3 changed files with 36 additions and 16 deletions
16
README.md
16
README.md
|
@ -71,7 +71,21 @@ Issue druid queries supplying
|
||||||
(query client random (:queryType q) q)
|
(query client random (:queryType q) q)
|
||||||
(close client))
|
(close client))
|
||||||
```
|
```
|
||||||
|
To run a query _without_ runtime validation of the query against a schema (using
|
||||||
|
the `q` from above:
|
||||||
|
```clj
|
||||||
|
(let [client (connect {:zk {:host "127.0.0.1:2181"
|
||||||
|
:discovery-path "/druid/discovery"
|
||||||
|
:node-type "druid:broker"}})]
|
||||||
|
(execute client random q)
|
||||||
|
(close client))
|
||||||
|
;; if you want to validate
|
||||||
|
(let [client (connect {:zk {:host "127.0.0.1:2181"
|
||||||
|
:discovery-path "/druid/discovery"
|
||||||
|
:node-type "druid:broker"}})]
|
||||||
|
(s/with-fn-validation (execute client random q)) ;; s is plumatic/schema
|
||||||
|
(close client))
|
||||||
|
```
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
An example using compojure-api to spawn a full druid API is located in the examples folder
|
An example using compojure-api to spawn a full druid API is located in the examples folder
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
[clojure.data.json :as json]
|
[clojure.data.json :as json]
|
||||||
[clj-druid.schemas.query :as sch]
|
[clj-druid.schemas.query :as sch]
|
||||||
[clj-druid.validations :as v]
|
[clj-druid.validations :as v]
|
||||||
[swiss.arrows :refer :all]
|
[clj-http.client :as http]
|
||||||
[clj-http.client :as http]))
|
[schema.core :as s]))
|
||||||
|
|
||||||
(defprotocol ^:private Client
|
(defprotocol ^:private Client
|
||||||
(close [this]
|
(close [this]
|
||||||
|
@ -76,17 +76,23 @@
|
||||||
(curator-client (:zk params))
|
(curator-client (:zk params))
|
||||||
(static-client (:hosts params))))
|
(static-client (:hosts params))))
|
||||||
|
|
||||||
(defn query
|
(s/defn execute
|
||||||
"Issue a druid query"
|
"Issue a druid query"
|
||||||
[client balance-strategy query-type druid-query & params]
|
([client balance-strategy druid-query :- sch/query]
|
||||||
(let [params (apply hash-map params)
|
(execute client balance-strategy druid-query {}))
|
||||||
options (-<> (into druid-query {:queryType query-type})
|
([client balance-strategy druid-query http-params]
|
||||||
(v/validate query-type)
|
(let [nodes (nodes client)]
|
||||||
(json/write-str <>)
|
|
||||||
{:body <> :as :text}
|
|
||||||
(merge params))
|
|
||||||
nodes (nodes client)]
|
|
||||||
(when (empty? nodes)
|
(when (empty? nodes)
|
||||||
(throw (Exception.
|
(throw (Exception.
|
||||||
"No druid node available for query")))
|
"No druid node available for query")))
|
||||||
(http/post (balance-strategy nodes) options)))
|
(http/post (balance-strategy nodes)
|
||||||
|
(merge {:body (json/write-str druid-query)
|
||||||
|
:as :text
|
||||||
|
:content-type :json}
|
||||||
|
http-params)))))
|
||||||
|
(defn query
|
||||||
|
"Issue a druid query with validation"
|
||||||
|
[client balance-strategy query-type druid-query & params]
|
||||||
|
(let [http-params (apply hash-map params)
|
||||||
|
query (assoc druid-query :queryType query-type)]
|
||||||
|
(s/with-fn-validation (execute client balance-strategy query http-params))))
|
||||||
|
|
|
@ -112,7 +112,7 @@ TopNs are much faster and resource efficient than GroupBys for this use case."
|
||||||
#(= :search (:queryType %)) search
|
#(= :search (:queryType %)) search
|
||||||
#(= :segmentMetadata (:queryType %)) segmentMetadata
|
#(= :segmentMetadata (:queryType %)) segmentMetadata
|
||||||
#(= :timeBoundary (:queryType %)) timeBoundary
|
#(= :timeBoundary (:queryType %)) timeBoundary
|
||||||
#(= :timeSeries (:queryType %)) timeseries
|
#(= :timeseries (:queryType %)) timeseries
|
||||||
#(= :topN (:queryType %)) topN
|
#(= :topN (:queryType %)) topN
|
||||||
#(= :select (:queryType %)) select))
|
#(= :select (:queryType %)) select))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue