GithubHelp home page GithubHelp logo

clj-druid's Introduction

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.

clj-druid's People

Contributors

gbuisson avatar slipset avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

clj-druid's Issues

Problems in README.md

I just started looking at this, since I need to access Druid from Clojure.

I noticed a couple of problems in the top-level README.md file:

  1. random isn't defined, as in (query client random (:queryType q) q). Maybe you meant randomize?
  2. execute isn't defined, as in (execute client random q)

Also, I'd appreciate a quick comment confirming whether this package should work (since I'm having some other exceptions). I'm using Clojure 1.8 (admittedly old).
Thanks,
Dan

Wrong Schema

Apparently

"aggregator":{"type":"filtered","aggregator":
                          {"type":"longSum"
                          ,"name":"qualityRows"
                          ,"fieldName":"count"}
                    ,"filter":
                          {"type":"not"
                          ,"field":{"type":"selector","dimension":"quality","value":null}}

Is ok for druid but doesn't pass the cli-druid aggregation schema (clj-druid.schemas.aggregation). Or more precisely it try to use aggregator schema instead of filtered aggregator schema

Update clj-http dependency

clj-druid uses version 2.0.0 of clj-http to send request to Druid. My application uses clj-druid and clj-http. I cannot use the latest version of clj-http which is 3.4.1.

Migration example

I'm currently using cli-druid version 0.2.12, which lets me connect by calling

(let [zk-client (zk/connect "zk1,zk2,zk3")]
   (druid\zk-watch-node-list zk-client "/druid/discovery/druid:broker"))

Which suits me quite well, since I'm using the zookeeper client for other stuff as well.

How would this be done in 0.2.16?

Wrong node-type in connect-with-zk docs

Doc states:

(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 "broker"}})

At least in my environment, this should be

(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"}})

example project is broken

Sounds like a dependency is missing:

Caused by: java.io.FileNotFoundException: Could not locate pjstadig/util__init.class or pjstadig/util.clj on classpath:

Make it possible to bypass validations

Even though I like the query-validations, there are times when I need to do stuff that the schemas are
not allowing. Example at hand right now is working with thetaSketches, http://druid.io/docs/latest/development/extensions-core/datasketches-aggregators.html
which is not currently supported by the schema. As a work around I do this

(defn execute*
  "Issue a druid query"
  ([client balance-strategy druid-query http-params]
   (execute* client balance-strategy druid-query http-params false))
  ([client balance-strategy druid-query http-params non-strict?]
   (let [nodes (druid/nodes client)]
     (when-not non-strict?
       (v/validate druid-query (:queryType druid-query)))
     (when (empty? nodes)
       (throw (Exception.
               "No druid node available for query")))
     (http/post (balance-strategy nodes)
                (merge {:body (json/encode druid-query)
                        :as :text
                        :content-type :json}
                       http-params)))))

in my code.

Would you want this in cli-druid? if not, please just close this issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.