No description
Find a file
Erik Assum 37fc967f00 Add function to allow for query execution without validation, fixes #25 (#26)
* 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
2017-06-15 09:42:44 +02:00
doc initial commit 2014-09-11 16:18:25 +02:00
examples version bump 2017-01-12 15:02:15 +01:00
src/clj_druid Add function to allow for query execution without validation, fixes #25 (#26) 2017-06-15 09:42:44 +02:00
test/clj_druid Use curator for druid node discovery 2016-08-05 16:40:10 +02:00
.gitignore added example using compojure api 2015-05-21 15:35:11 +02:00
.travis.yml added travis config 2016-03-17 11:17:46 +01:00
LICENSE Update LICENSE 2015-05-22 17:25:00 +02:00
project.clj Bump to next SNAPSHOT 2017-02-27 11:45:35 +01:00
README.md Add function to allow for query execution without validation, fixes #25 (#26) 2017-06-15 09:42:44 +02:00

clj-druid

Build Status

Clojure library for Druid.

clj-druid eases druid integration providing a client as well as a set of [Schema] (https://github.com/Prismatic/schema) to validate queries. Current version is up to date with latest query API from official docs.

Installing

Add the following to your Leiningen project.clj:

latest clj-druid version

Usage

Client

Connect to a druid cluster through Zookeeper, this method supports auto detection and update of available brokers for easy HA/load balancing

(use 'clj-druid.client)
(connect {:zk {:host "127.0.0.1:2181,my-other-zk-host:2181" ; can contain multiple hosts separated by commas
               :discovery-path "/druid/discovery"
               :node-type "druid:broker"}})

you can also connect by supplying a vector of hosts, useful for dev, local testing

(use 'clj-druid.client)
(connect {:hosts ["http://127.0.0.1:8083/druid/v2"]})

Querying

Issue druid queries supplying

  • a load balance strategy [fixed random]
  • a queryType
  • a query in the following form
(def q
  {:queryType :timeseries
   :dataSource "sample_datasource"
   :granularity :day
   :filter {
     :type :and
     :fields [
       {:type :selector :dimension "sample_dimension1" :value "sample_value1"}
       {:type :or
         :fields [
           {:type :selector :dimension "sample_dimension2" :value "sample_value2"}
           {:type :selector :dimension "sample_dimension3" :value "sample_value3"}]}]}
   :aggregations [
     {:type :longSum :name "sample_name1", :fieldName "sample_fieldName1"}
     {:type :doubleSum :name "sample_name2", :fieldName "sample_fieldName2"}]
   :postAggregations [
     {:type :arithmetic
      :name "sample_divide"
      :fn "/"
      :fields [{:type :fieldAccess :name "sample_name1" :fieldName "sample_fieldName1"}
               {:type :fieldAccess :name "sample_name2" :fieldName "sample_fieldName2"}]}]

   :intervals ["2012-01-01T00:00:00.000/2012-01-03T00:00:00.000"]})
   (let [client (connect {:zk {:host "127.0.0.1:2181"
                          :discovery-path "/druid/discovery"
                          :node-type "druid:broker"}})]
     (query client random (:queryType q) q)
     (close client))

To run a query without runtime validation of the query against a schema (using the q from above:

   (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

An example using compojure-api to spawn a full druid API is located in the examples folder

git clone https://github.com/y42/clj-druid
cd clj-druid/examples
lein ring server

Have Fun!

License

Copyright © 2015 Guillaume Buisson

Distributed under the Eclipse Public License, the same as Clojure.