Skip to content

Commit b6c7dde

Browse files
authored
Merge pull request #8 from asaitov/master
DataSketches aggregator
2 parents 036ef47 + 18ac294 commit b6c7dde

File tree

7 files changed

+22
-35
lines changed

7 files changed

+22
-35
lines changed

build.sbt

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ lazy val root = (project in file("."))
6666
"io.circe" %% "circe-java8" % circeVersion,
6767
"com.typesafe.akka" %% "akka-http" % "10.0.11",
6868
"de.heikoseeberger" %% "akka-http-circe" % "1.19.0",
69+
"ca.mrvisser" %% "sealerate" % "0.0.5",
6970
"ch.qos.logback" % "logback-classic" % "1.1.3",
7071
"org.scalactic" %% "scalactic" % "3.0.1",
7172
"org.scalatest" %% "scalatest" % "3.0.1" % "test"

src/main/scala/ing/wbaa/druid/DruidQuery.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package ing.wbaa.druid
1919

20+
import ca.mrvisser.sealerate
21+
2022
import ing.wbaa.druid.definitions.{ Aggregation, Dimension, Filter, Granularity, GranularityType }
2123

2224
import io.circe.generic.auto._
@@ -30,7 +32,7 @@ object QueryType extends EnumCodec[QueryType] {
3032
case object TopN extends QueryType
3133
case object GroupBy extends QueryType
3234
case object Timeseries extends QueryType
33-
val values = Set(TopN, GroupBy, Timeseries)
35+
val values: Set[QueryType] = sealerate.values[QueryType]
3436
}
3537

3638
sealed trait DruidQuery {

src/main/scala/ing/wbaa/druid/Enum.scala

+1-5
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,7 @@ trait UpperCaseEnumStringEncoder extends EnumStringEncoder { this: Enum =>
6161
}
6262

6363
trait CamelCaseEnumStringEncoder extends EnumStringEncoder { this: Enum =>
64-
private def decapitalize(input: String) = {
65-
val chars = input.toCharArray
66-
chars(0) = Character.toLowerCase(chars(0))
67-
chars.mkString
68-
}
64+
private def decapitalize(input: String) = input.head.toLower + input.tail
6965
def encode() = decapitalize(toString)
7066
}
7167

src/main/scala/ing/wbaa/druid/definitions/Aggregation.scala

+10-12
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
package ing.wbaa.druid
1919
package definitions
2020

21+
import ca.mrvisser.sealerate
22+
import io.circe._
2123
import io.circe.generic.auto._
2224
import io.circe.syntax._
23-
import io.circe._
2425

2526
sealed trait AggregationType extends Enum with CamelCaseEnumStringEncoder
2627
object AggregationType extends EnumCodec[AggregationType] {
@@ -35,18 +36,9 @@ object AggregationType extends EnumCodec[AggregationType] {
3536
case object DoubleLast extends AggregationType
3637
case object LongFirst extends AggregationType
3738
case object LongLast extends AggregationType
39+
case object ThetaSketch extends AggregationType
3840

39-
val values = Set(Count,
40-
LongSum,
41-
DoubleSum,
42-
DoubleMax,
43-
DoubleMin,
44-
LongMin,
45-
LongMax,
46-
DoubleFirst,
47-
DoubleLast,
48-
LongFirst,
49-
LongLast)
41+
val values: Set[AggregationType] = sealerate.values[AggregationType]
5042
}
5143

5244
trait Aggregation {
@@ -81,6 +73,7 @@ object SingleFieldAggregation {
8173
case x: DoubleLastAggregation => x.asJson
8274
case x: LongLastAggregation => x.asJson
8375
case x: LongFirstAggregation => x.asJson
76+
case x: ThetaSketchAggregation => x.asJson
8477
}
8578
}
8679
}
@@ -116,3 +109,8 @@ case class LongFirstAggregation(name: String, fieldName: String) extends SingleF
116109
case class LongLastAggregation(name: String, fieldName: String) extends SingleFieldAggregation {
117110
val `type` = AggregationType.LongLast
118111
}
112+
case class ThetaSketchAggregation(name: String, fieldName: String, isInputThetaSketch: Boolean = false,
113+
size: Long = 16384)
114+
extends SingleFieldAggregation {
115+
val `type` = AggregationType.ThetaSketch
116+
}

src/main/scala/ing/wbaa/druid/definitions/Filter.scala

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
package ing.wbaa.druid
1919
package definitions
2020

21-
import io.circe.syntax._
21+
import ca.mrvisser.sealerate
2222
import io.circe._
2323
import io.circe.generic.auto._
24+
import io.circe.syntax._
2425

2526
sealed trait FilterType extends Enum with CamelCaseEnumStringEncoder
2627

@@ -32,7 +33,7 @@ object FilterType extends EnumCodec[FilterType] {
3233
case object Regex extends FilterType
3334
case object Not extends FilterType
3435
case object Javascript extends FilterType
35-
val values = Set(And, Or, Selector, ColumnComparison, Regex, Not, Javascript)
36+
val values: Set[FilterType] = sealerate.values[FilterType]
3637
}
3738

3839
sealed trait Filter {

src/main/scala/ing/wbaa/druid/definitions/Granularity.scala

+2-12
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package ing.wbaa.druid
1919
package definitions
2020

2121
import io.circe._
22+
import ca.mrvisser.sealerate
2223

2324
sealed trait Granularity extends Enum with SnakeCaseEnumStringEncoder
2425

@@ -42,16 +43,5 @@ object GranularityType extends EnumCodec[Granularity] {
4243
case object Month extends Granularity
4344
case object Quarter extends Granularity
4445
case object Year extends Granularity
45-
val values = Set(All,
46-
None,
47-
Second,
48-
Minute,
49-
FifteenMinute,
50-
ThirtyMinute,
51-
Hour,
52-
Day,
53-
Week,
54-
Month,
55-
Quarter,
56-
Year)
46+
val values: Set[Granularity] = sealerate.values[Granularity]
5747
}

src/test/scala/ing/wbaa/druid/definitions/GranularitySpec.scala

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
package ing.wbaa.druid
1+
package ing.wbaa.druid.definitions
22

33
import org.scalatest._
4-
import ing.wbaa.druid.definitions._
54

65
import io.circe._
76
import io.circe.syntax._
87

9-
class GranularitySoec extends WordSpec with Matchers {
8+
class GranularitySpec extends WordSpec with Matchers {
109
"Granularities" should {
1110
"be able to encode to json" in {
1211
implicit val granularityEncoder: Encoder[Granularity] = GranularityType.encoder

0 commit comments

Comments
 (0)