Druidry - Druid Java Client

Druidry is an open-source Java based utility library which supports creating query to Druid and connection handling with Druid

License

License

Categories

Categories

druid Data Databases
GroupId

GroupId

in.zapr.druid
ArtifactId

ArtifactId

druidry
Last Version

Last Version

3.1
Release Date

Release Date

Type

Type

jar
Description

Description

Druidry - Druid Java Client
Druidry is an open-source Java based utility library which supports creating query to Druid and connection handling with Druid
Project URL

Project URL

https://github.com/zapr-oss/druidry
Source Code Management

Source Code Management

https://github.com/zapr-oss/druidry

Download druidry

How to add to project

<!-- https://jarcasting.com/artifacts/in.zapr.druid/druidry/ -->
<dependency>
    <groupId>in.zapr.druid</groupId>
    <artifactId>druidry</artifactId>
    <version>3.1</version>
</dependency>
// https://jarcasting.com/artifacts/in.zapr.druid/druidry/
implementation 'in.zapr.druid:druidry:3.1'
// https://jarcasting.com/artifacts/in.zapr.druid/druidry/
implementation ("in.zapr.druid:druidry:3.1")
'in.zapr.druid:druidry:jar:3.1'
<dependency org="in.zapr.druid" name="druidry" rev="3.1">
  <artifact name="druidry" type="jar" />
</dependency>
@Grapes(
@Grab(group='in.zapr.druid', module='druidry', version='3.1')
)
libraryDependencies += "in.zapr.druid" % "druidry" % "3.1"
[in.zapr.druid/druidry "3.1"]

Dependencies

compile (12)

Group / Artifact Type Version
joda-time : joda-time jar 2.9.7
com.fasterxml.jackson.core : jackson-databind jar 2.9.10.4
com.fasterxml.jackson.datatype : jackson-datatype-joda jar 2.9.9
org.projectlombok : lombok jar 1.18.10
ch.qos.logback : logback-classic jar 1.2.1
ch.qos.logback : logback-core jar 1.2.1
org.apache.commons : commons-lang3 jar 3.5
org.glassfish.jersey.core : jersey-client jar 2.26
org.glassfish.jersey.media : jersey-media-json-jackson jar 2.26
org.glassfish.jersey.inject : jersey-hk2 jar 2.26
org.glassfish.jersey.connectors : jersey-apache-connector jar 2.26
com.google.guava : guava jar 23.0

test (2)

Group / Artifact Type Version
org.testng : testng jar 6.11
org.skyscreamer : jsonassert jar 1.4.0

Project Modules

There are no modules declared in this project.

Welcome to project Druidry!

build_status License: Apache License 2 javadoc

Druid is an extremely popular tool to perform OLAP queries on event data. Druid drives real-time dashboards in most of the organisations right now. We@Zapr love Druid! Therefore we want to contribute towards making Druid, even more, friendlier to the ever expanding community.

We want to make the process of deep meaningful conversations with Druid little easier. What do we mean is that we don’t want developers to write big, scary JSON anymore but instead use a simple Java-based query generator to help with the querying.

Creating JSON freely can cause tedious bugs such as date type mistakes or spelling mistakes and potentially code can get bigger and messier and less readable. So, in reality, we want to keep the main focus of querying to be the use-case, not the type-checks.

We are excited to know whether you liked it or loved it, so please reach out to us at [email protected]

Description

Druidry is an open-source Java based utility library which supports creating query to Druid automatically taking care of following,

  • Type checking.
  • Spelling Checks.
  • Code reviewability and readability.

This library is still growing and does not support each and every constructs, however it supports the most common one used internally @Zapr.

Getting Started

Prerequisite

  • Maven
  • Java 8

Usage

Add this in your pom.xml (assuming maven based project)

        <dependency>
            <groupId>in.zapr.druid</groupId>
            <artifactId>druidry</artifactId>
            <version>${LATEST_VERSION}</version>
        </dependency>

Replace ${LATEST_VERSION} with latest release version

Examples

Taking from Druid's example query

{
     "queryType": "topN",
     "dataSource": "sample_data",
     "dimension": "sample_dim",
     "threshold": 5,
     "metric": "count",
     "granularity": "all",
     "filter": {
        "type": "and",
          "fields": [
            {
              "type": "selector",
              "dimension": "dim1",
              "value": "some_value"
            },
            {
              "type": "selector",
              "dimension": "dim2",
              "value": "some_other_val"
            }
          ]
     },
     "aggregations": [
        {
          "type": "longSum",
          "name": "count",
          "fieldName": "count"
        },
        {
          "type": "doubleSum",
          "name": "some_metric",
          "fieldName": "some_metric"
        }
     ],
     "postAggregations": [
         {
            "type": "arithmetic",
            "name": "sample_divide",
            "fn": "/",
            "fields": [
              {
                "type": "fieldAccess",
                "name": "some_metric",
                "fieldName": "some_metric"
              },
              {
                "type": "fieldAccess",
                "name": "count",
                "fieldName": "count"
              }
            ]
         }
      ],
      "intervals": [
        "2013-08-31T00:00:00.000/2013-09-03T00:00:00.000"
      ]
}
SelectorFilter selectorFilter1 = new SelectorFilter("dim1", "some_value");
SelectorFilter selectorFilter2 = new SelectorFilter("dim2", "some_other_val");

AndFilter filter = new AndFilter(Arrays.asList(selectorFilter1, selectorFilter2));

DruidAggregator aggregator1 = new LongSumAggregator("count", "count");
DruidAggregator aggregator2 = new DoubleSumAggregator("some_metric", "some_metric");

FieldAccessPostAggregator fieldAccessPostAggregator1
        = new FieldAccessPostAggregator("some_metric", "some_metric");

FieldAccessPostAggregator fieldAccessPostAggregator2
        = new FieldAccessPostAggregator("count", "count");

DruidPostAggregator postAggregator = ArithmeticPostAggregator.builder()
        .name("sample_divide")
        .function(ArithmeticFunction.DIVIDE)
        .fields(Arrays.asList(fieldAccessPostAggregator1, fieldAccessPostAggregator2))
        .build();

DateTime startTime = new DateTime(2013, 8, 31, 0, 0, 0, DateTimeZone.UTC);
DateTime endTime = new DateTime(2013, 9, 3, 0, 0, 0, DateTimeZone.UTC);
Interval interval = new Interval(startTime, endTime);

Granularity granularity = new SimpleGranularity(PredefinedGranularity.ALL);
DruidDimension dimension = new SimpleDimension("sample_dim");
TopNMetric metric = new SimpleMetric("count");

DruidTopNQuery query = DruidTopNQuery.builder()
        .dataSource("sample_data")
        .dimension(dimension)
        .threshold(5)
        .topNMetric(metric)
        .granularity(granularity)
        .filter(filter)
        .aggregators(Arrays.asList(aggregator1, aggregator2))
        .postAggregators(Collections.singletonList(postAggregator))
        .intervals(Collections.singletonList(interval))
        .build();

ObjectMapper mapper = new ObjectMapper();
String requiredJson = mapper.writeValueAsString(query);
DruidConfiguration config =  DruidConfiguration
               .builder()
               .host("druid.io")
               .endpoint("druid/v2/")
               .build();

DruidClient client = new DruidJerseyClient(druidConfiguration);
client.connect();
List<DruidResponse> responses = client.query(query, DruidResponse.class);
client.close();

Supported Features

Queries

  • Aggregation Queries
    • TopN
    • TimeSeries
    • GroupBy
  • DruidScanQuery
  • DruidSelectQuery

Aggregators

  • Cardinality
  • Count
  • DoubleMax
  • DoubleMin
  • DoubleSum
  • DoubleLast
  • DoubleFirst
  • FloatFirst
  • FloatLast
  • Filtered
  • HyperUnique
  • Javascript
  • LongMax
  • LongMin
  • LongSum
  • LongFirst
  • LongLast
  • DistinctCount
  • Histogram
  • Data Sketches
    • ThetaSketch
    • TupleSketch
    • QuantilesSketch
    • HllSketchBuild
    • HllSketchMerge

Filters

  • And
  • Bound
  • In
  • Interval (Without Extraction Function)
  • Javascript
  • Not
  • Or
  • Regex
  • Search (Without Extraction Function)
  • Selector

Post Aggregators

  • Arithmetic
  • Constant
  • FieldAccess
  • HyperUniqueCardinality
  • Javascript
  • Data Sketches
    • Theta Sketch
      • ThetaSketchEstimate
      • ThetaSketchSetOp
    • Tuple Sketch
      • TupleSketchToEstimate
      • TupleSketchToEstimateAndBounds
      • TupleSketchToNumEntries
      • TupleSketchToMeans
      • TupleSketchToVariances
      • TupleSketchToQuantilesSketch
      • TupleSketchSetOp
      • TupleSketchTTest
      • TupleSketchToString
    • Quantiles Sketch
      • QuantilesSketchToQuantile
      • QuantilesSketchToQuantiles
      • QuantilesSketchToHistogram
      • QuantilesSketchToString
    • HLL Sketch
      • HllSketchEstimateWithBounds
      • HllSketchUnion
      • HllSketchToString

Virtual Columns

  • Expression

Granularity

  • Duration
  • Period
  • Predefined

Contact

For any features or bugs, please raise it in issues section

If anything else, get in touch with us at [email protected]

in.zapr.druid

ZAPR Media Labs

Versions

Version
3.1
3.0
2.14
2.13
2.12
2.11
2.10
2.9
2.8
2.7
2.6
2.5
2.4
2.3
2.2
2.1
2.0
1.5
1.4
1.3
1.2
1.1
1.0