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

DQL API improvements in functions with varargs #44

Closed anskarl closed 5 years ago

anskarl commented 5 years ago

In scruid DQL we are using vararg in some functions. For example, to specify range filtering on dimensions that contain long millisecond values we are using the intervals operator:

'dim intervals("2011-06-01/2012-06-01", "2012-06-01/2013-06-01", ...)

This is useful on queries that we explicitly define all those intervals. When, for example, we have the desired intervals in a Sequence we can use vararg expansion:

val values = Seq"2011-06-01/2012-06-01", "2012-06-01/2013-06-01", ...)
'dim intervals(values: _*)

Similarly, in cases that the intervals are in any other iterable collection of the same type, we should first convert the collection into a Sequence and thereafter use vararg expansion.

Instead of using vararg expansion and possibly conversion to a Sequence, I propose to overload the functions and create additional ones with Iterable as argument. For example, the

// remains the same
def interval(value: String): FilteringExpression = ...

// remains the same
def intervals(first: String, second: String, rest: String*): FilteringExpression = ...

// this is the additional function
def intervals(values: Iterable[String]): FilteringExpression = ...

The same goes for operators in and notIn.

anskarl commented 5 years ago

Since the corresponding PR has been merged, I believe that this issue can be closed.