ing-bank / scruid

Scala + Druid: Scruid. A library that allows you to compose queries in Scala, and parse the result back into typesafe classes.
Apache License 2.0
115 stars 29 forks source link

Druid Query Language (DQL) #38

Closed anskarl closed 5 years ago

anskarl commented 5 years ago

This is the implementation of Druid query language (DQL). In brief it provides the following:

GH-32

The example below demonstrates a group-by query:

case class GroupByIsAnonymous(isAnonymous: String, country: String, count: Int)

val query: GroupByQuery = DQL
    .granularity(GranularityType.Day)
    .interval("2011-06-01/2017-06-01")
    .agg(count as "count")
    .where('countryName.isNotNull)
    .groupBy('isAnonymous, 'countryName.extract(UpperExtractionFn()) as "country")
    .having('count > 100 and 'count < 200)
    .limit(10, 'count.desc(DimensionOrderType.numeric))
    .build()

val response = query.execute().map(_.list[GroupByIsAnonymous])
val result: List[GroupByIsAnonymous] = Await.result(response, 10.seconds)

In docs/dql.md you can find documentation and examples.

apollotonkosmo commented 5 years ago

+1

thelgis commented 5 years ago

+1

zaoudis commented 5 years ago

+1

bjgbeelen commented 5 years ago

Hi @anskarl thanks for your pull request. Just wanted to let you know that it;s appreciated, but I haven't found the time yet to properly look a it. Hopefully I can have a look next week. Thanks for your patience!

anskarl commented 5 years ago

@bjgbeelen no worries :)

anskarl commented 5 years ago

Hi @bjgbeelen

Thank you for the code review! I have updated the PR with the requested changes (documentation and code). I have also made any required changes to resolve the conflicts with the latest version in master branch (after the merge of PR #37).