-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[ES|QL] Render aggregate_metric_double #122660
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
Merged
limotova
merged 9 commits into
elastic:main
from
limotova:rendering-aggregate-metric-double
Feb 20, 2025
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ecb53f6
[ES|QL] Render aggregate_metric_double
limotova a82dc92
Merge branch 'main' into rendering-aggregate-metric-double
limotova e93448c
address comments
limotova 4b2e597
Update docs/changelog/122660.yaml
limotova d9e6422
fix changelog
limotova bd8d67d
add label to metric enum
limotova c457e8d
[CI] Auto commit changes from spotless
ddc0c1c
Merge branch 'main' into rendering-aggregate-metric-double
limotova c3c1a1d
change to IllegalStateException
limotova File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pr: 122660 | ||
| summary: Render `aggregate_metric_double` | ||
| area: "ES|QL" | ||
| type: enhancement | ||
| issues: [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...k/esql/expression/function/scalar/convert/ToStringFromAggregateMetricDoubleEvaluator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.esql.expression.function.scalar.convert; | ||
|
|
||
| import org.apache.lucene.util.BytesRef; | ||
| import org.elasticsearch.compute.data.Block; | ||
| import org.elasticsearch.compute.data.BytesRefBlock; | ||
| import org.elasticsearch.compute.data.CompositeBlock; | ||
| import org.elasticsearch.compute.data.Vector; | ||
| import org.elasticsearch.compute.operator.DriverContext; | ||
| import org.elasticsearch.compute.operator.EvalOperator; | ||
| import org.elasticsearch.xpack.esql.core.tree.Source; | ||
|
|
||
| import static org.elasticsearch.xpack.esql.type.EsqlDataTypeConverter.aggregateMetricDoubleBlockToString; | ||
|
|
||
| public class ToStringFromAggregateMetricDoubleEvaluator extends AbstractConvertFunction.AbstractEvaluator { | ||
| public ToStringFromAggregateMetricDoubleEvaluator(EvalOperator.ExpressionEvaluator field, Source source, DriverContext driverContext) { | ||
| super(driverContext, field, source); | ||
| } | ||
|
|
||
| @Override | ||
| protected String name() { | ||
| return "ToStringFromAggregateMetricDouble"; | ||
| } | ||
|
|
||
| @Override | ||
| protected Block evalVector(Vector v) { | ||
| return evalBlock(v.asBlock()); | ||
| } | ||
|
|
||
| private static BytesRef evalValue(CompositeBlock compositeBlock, int index) { | ||
| return new BytesRef(aggregateMetricDoubleBlockToString(compositeBlock, index)); | ||
| } | ||
|
|
||
| @Override | ||
| public Block evalBlock(Block b) { | ||
| CompositeBlock block = (CompositeBlock) b; | ||
| int positionCount = block.getPositionCount(); | ||
| try (BytesRefBlock.Builder builder = driverContext.blockFactory().newBytesRefBlockBuilder(positionCount)) { | ||
| for (int p = 0; p < positionCount; p++) { | ||
| if (block.isNull(p)) { | ||
| builder.appendNull(); | ||
| } else { | ||
| builder.appendBytesRef(evalValue(block, p)); | ||
| } | ||
| } | ||
| return builder.build(); | ||
| } | ||
| } | ||
|
|
||
| public static class Factory implements EvalOperator.ExpressionEvaluator.Factory { | ||
| private final Source source; | ||
| private final EvalOperator.ExpressionEvaluator.Factory field; | ||
|
|
||
| public Factory(EvalOperator.ExpressionEvaluator.Factory field, Source source) { | ||
| this.field = field; | ||
| this.source = source; | ||
| } | ||
|
|
||
| @Override | ||
| public EvalOperator.ExpressionEvaluator get(DriverContext context) { | ||
| return new ToStringFromAggregateMetricDoubleEvaluator(field.get(context), source, context); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I implemented this to just return the max of all the blocks, not sure if we wanted to go with some other logic? (Like end early if a block ever returns getValueCount of 1)
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.
I think we can avoid this - see my comment in the evaluator.
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.
I think we do still need some way of computing this for CompositeBlock though, I ran into it here
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.
I see. It's fine to use the max count here, but I think it's less error-prone not to implement this method. Alternatively, can we check the data type and convert the value at that position within the composite block in valueAtPosition? I'm also fine leaving it as is.
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.
I think it would make sense to adjust this later
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.
Maybe we can add an assertion or check that this logic is only valid for aggregate_metric_double fields? We can add this in a follow up given that this functionality is only available in snapshot builds. Can you add this to the list of tasks?