-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor AggregationResponse #368
Refactor AggregationResponse #368
Conversation
16e1780
to
91f0ac2
Compare
@@ -449,7 +449,9 @@ object HttpExecutorSpec extends IntegrationSpec { | |||
.refreshTrue | |||
) | |||
aggregation = | |||
termsAggregation(name = "aggregationString", field = TestDocument.stringField.keyword) | |||
termsAggregation(name = "aggregationString", field = TestDocument.stringField.keyword).withSubAgg( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, update name of this test also.
case str if str.contains("filter#") => | ||
Some(field -> data.unsafeAs[FilterAggregationResponse](FilterAggregationResponse.decoder)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove filter
?
case str if str.contains("filter#") => | ||
(field.split("#")(1), data.asInstanceOf[FilterAggregationResponse]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here also.
private[elasticsearch] object FilterAggregationResponse extends JsonDecoderOps { | ||
implicit val decoder: JsonDecoder[FilterAggregationResponse] = Obj.decoder.mapOrFail { case Obj(fields) => | ||
val allFields = fields.flatMap { case (field, data) => | ||
private[elasticsearch] sealed trait BucketDecoder extends JsonDecoderOps { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add 'JsonDecoderOps' in this sealed trait too?
03b3938
to
565db38
Compare
Some(field -> data.unsafeAs[Int]) | ||
case _ => | ||
val objFields = data.unsafeAs[Obj].fields.toMap | ||
val allFields = BucketDecoder(fields).allFields |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we are using BucketDecoder
this way, maybe we don't even need this class to be implicit
and then there is no need for sealed trait
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we do this, we should probably revert changes about JsonDecoderOps
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also rebase this PR (introduce changes from percentile ranks aggregation).
565db38
to
d1561c0
Compare
@@ -118,6 +118,112 @@ private[elasticsearch] object AvgAggregationResponse { | |||
implicit val decoder: JsonDecoder[AvgAggregationResponse] = DeriveJsonDecoder.gen[AvgAggregationResponse] | |||
} | |||
|
|||
case class BucketDecoder(fields: Chunk[(String, Json)]) extends JsonDecoderOps { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this case class private.
val allFields = BucketDecoder(fields).allFields | ||
val docCount = allFields("doc_count").asInstanceOf[Int] | ||
val subAggs = BucketDecoder(fields).subAggs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are creating this two times BucketDecoder(fields)
. Extract this in val before these three vals.
} | ||
} | ||
}.toMap | ||
val allFields = BucketDecoder(fields).allFields |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here also.
e0bf016
to
87b054d
Compare
No description provided.