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

Improved configuration #37

Closed anskarl closed 5 years ago

anskarl commented 5 years ago

Hi,

I would like to propose some improvements to the configuration of the Scruid library. The improvements are backward compatible with the current implementation. The only difference is that we can override any configuration parameter by defining an implicit instance of ing.wbaa.druid.DruidConfig.

Consider, for example, the following code:

import java.time.ZonedDateTime
import ing.wbaa.druid._
import scala.concurrent.duration._
import ing.wbaa.druid.definitions._

implicit val druidConf = DruidConfig(
  datasource = "some_different_datasource",
  responseParsingTimeout = 10.seconds
)

case class TimeseriesCount(count: Int)

val response = TimeSeriesQuery(
  aggregations = List(
    CountAggregation(name = "count")
  ),
  granularity = GranularityType.Week,
  intervals = List("2011-06-01/2017-06-01")
).execute()

val series: Map[ZonedDateTime, TimeseriesCount] = response.series[TimeseriesCount]    

The implicit configuration overrides the settings of application.conf or reference.conf. This can be practical for scala/ammonite scripts or notebooks, in which we would like to quickly set the settings inside the script/notebook.

bjgbeelen commented 5 years ago

Thanks btw for the PR! ;-)