Skip to content

Commit

Permalink
Merge pull request #8 from asaitov/master
Browse files Browse the repository at this point in the history
DataSketches aggregator
  • Loading branch information
bjgbeelen authored Mar 27, 2018
2 parents 036ef47 + 18ac294 commit b6c7dde
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 35 deletions.
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ lazy val root = (project in file("."))
"io.circe" %% "circe-java8" % circeVersion,
"com.typesafe.akka" %% "akka-http" % "10.0.11",
"de.heikoseeberger" %% "akka-http-circe" % "1.19.0",
"ca.mrvisser" %% "sealerate" % "0.0.5",
"ch.qos.logback" % "logback-classic" % "1.1.3",
"org.scalactic" %% "scalactic" % "3.0.1",
"org.scalatest" %% "scalatest" % "3.0.1" % "test"
Expand Down
4 changes: 3 additions & 1 deletion src/main/scala/ing/wbaa/druid/DruidQuery.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package ing.wbaa.druid

import ca.mrvisser.sealerate

import ing.wbaa.druid.definitions.{ Aggregation, Dimension, Filter, Granularity, GranularityType }

import io.circe.generic.auto._
Expand All @@ -30,7 +32,7 @@ object QueryType extends EnumCodec[QueryType] {
case object TopN extends QueryType
case object GroupBy extends QueryType
case object Timeseries extends QueryType
val values = Set(TopN, GroupBy, Timeseries)
val values: Set[QueryType] = sealerate.values[QueryType]
}

sealed trait DruidQuery {
Expand Down
6 changes: 1 addition & 5 deletions src/main/scala/ing/wbaa/druid/Enum.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ trait UpperCaseEnumStringEncoder extends EnumStringEncoder { this: Enum =>
}

trait CamelCaseEnumStringEncoder extends EnumStringEncoder { this: Enum =>
private def decapitalize(input: String) = {
val chars = input.toCharArray
chars(0) = Character.toLowerCase(chars(0))
chars.mkString
}
private def decapitalize(input: String) = input.head.toLower + input.tail
def encode() = decapitalize(toString)
}

Expand Down
22 changes: 10 additions & 12 deletions src/main/scala/ing/wbaa/druid/definitions/Aggregation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
package ing.wbaa.druid
package definitions

import ca.mrvisser.sealerate
import io.circe._
import io.circe.generic.auto._
import io.circe.syntax._
import io.circe._

sealed trait AggregationType extends Enum with CamelCaseEnumStringEncoder
object AggregationType extends EnumCodec[AggregationType] {
Expand All @@ -35,18 +36,9 @@ object AggregationType extends EnumCodec[AggregationType] {
case object DoubleLast extends AggregationType
case object LongFirst extends AggregationType
case object LongLast extends AggregationType
case object ThetaSketch extends AggregationType

val values = Set(Count,
LongSum,
DoubleSum,
DoubleMax,
DoubleMin,
LongMin,
LongMax,
DoubleFirst,
DoubleLast,
LongFirst,
LongLast)
val values: Set[AggregationType] = sealerate.values[AggregationType]
}

trait Aggregation {
Expand Down Expand Up @@ -81,6 +73,7 @@ object SingleFieldAggregation {
case x: DoubleLastAggregation => x.asJson
case x: LongLastAggregation => x.asJson
case x: LongFirstAggregation => x.asJson
case x: ThetaSketchAggregation => x.asJson
}
}
}
Expand Down Expand Up @@ -116,3 +109,8 @@ case class LongFirstAggregation(name: String, fieldName: String) extends SingleF
case class LongLastAggregation(name: String, fieldName: String) extends SingleFieldAggregation {
val `type` = AggregationType.LongLast
}
case class ThetaSketchAggregation(name: String, fieldName: String, isInputThetaSketch: Boolean = false,
size: Long = 16384)
extends SingleFieldAggregation {
val `type` = AggregationType.ThetaSketch
}
5 changes: 3 additions & 2 deletions src/main/scala/ing/wbaa/druid/definitions/Filter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
package ing.wbaa.druid
package definitions

import io.circe.syntax._
import ca.mrvisser.sealerate
import io.circe._
import io.circe.generic.auto._
import io.circe.syntax._

sealed trait FilterType extends Enum with CamelCaseEnumStringEncoder

Expand All @@ -32,7 +33,7 @@ object FilterType extends EnumCodec[FilterType] {
case object Regex extends FilterType
case object Not extends FilterType
case object Javascript extends FilterType
val values = Set(And, Or, Selector, ColumnComparison, Regex, Not, Javascript)
val values: Set[FilterType] = sealerate.values[FilterType]
}

sealed trait Filter {
Expand Down
14 changes: 2 additions & 12 deletions src/main/scala/ing/wbaa/druid/definitions/Granularity.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package ing.wbaa.druid
package definitions

import io.circe._
import ca.mrvisser.sealerate

sealed trait Granularity extends Enum with SnakeCaseEnumStringEncoder

Expand All @@ -42,16 +43,5 @@ object GranularityType extends EnumCodec[Granularity] {
case object Month extends Granularity
case object Quarter extends Granularity
case object Year extends Granularity
val values = Set(All,
None,
Second,
Minute,
FifteenMinute,
ThirtyMinute,
Hour,
Day,
Week,
Month,
Quarter,
Year)
val values: Set[Granularity] = sealerate.values[Granularity]
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package ing.wbaa.druid
package ing.wbaa.druid.definitions

import org.scalatest._
import ing.wbaa.druid.definitions._

import io.circe._
import io.circe.syntax._

class GranularitySoec extends WordSpec with Matchers {
class GranularitySpec extends WordSpec with Matchers {
"Granularities" should {
"be able to encode to json" in {
implicit val granularityEncoder: Encoder[Granularity] = GranularityType.encoder
Expand Down

0 comments on commit b6c7dde

Please sign in to comment.