Skip to content
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

Merged
merged 4 commits into from
Dec 2, 2023

Conversation

vanjaftn
Copy link
Contributor

No description provided.

@dbulaja98 dbulaja98 changed the title Refactore AggregationResponse Refactor AggregationResponse Nov 19, 2023
@vanjaftn vanjaftn force-pushed the refactor-aggregation-response branch from 16e1780 to 91f0ac2 Compare November 20, 2023 12:52
@@ -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(
Copy link
Collaborator

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.

Comment on lines -196 to -199
case str if str.contains("filter#") =>
Some(field -> data.unsafeAs[FilterAggregationResponse](FilterAggregationResponse.decoder))
Copy link
Collaborator

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?

Comment on lines -238 to -245
case str if str.contains("filter#") =>
(field.split("#")(1), data.asInstanceOf[FilterAggregationResponse])
Copy link
Collaborator

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 {
Copy link
Collaborator

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?

@vanjaftn vanjaftn force-pushed the refactor-aggregation-response branch from 03b3938 to 565db38 Compare November 20, 2023 16:00
Some(field -> data.unsafeAs[Int])
case _ =>
val objFields = data.unsafeAs[Obj].fields.toMap
val allFields = BucketDecoder(fields).allFields
Copy link
Collaborator

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.

Copy link
Collaborator

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.

Copy link
Collaborator

@dbulaja98 dbulaja98 left a 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).

@vanjaftn vanjaftn force-pushed the refactor-aggregation-response branch from 565db38 to d1561c0 Compare November 21, 2023 08:27
@@ -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 {
Copy link
Collaborator

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.

Comment on lines 270 to 272
val allFields = BucketDecoder(fields).allFields
val docCount = allFields("doc_count").asInstanceOf[Int]
val subAggs = BucketDecoder(fields).subAggs
Copy link
Collaborator

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here also.

@vanjaftn vanjaftn force-pushed the refactor-aggregation-response branch from e0bf016 to 87b054d Compare November 30, 2023 13:46
@dbulaja98 dbulaja98 merged commit 28d81b7 into lambdaworks:main Dec 2, 2023
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants