-
Notifications
You must be signed in to change notification settings - Fork 25.4k
[ES|QL] ToAggregateMetricDouble function #124595
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
[ES|QL] ToAggregateMetricDouble function #124595
Conversation
2af99c4
to
e7bae9b
Compare
e7bae9b
to
2f64c49
Compare
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.
The approach looks good. I've left some comments. Thanks Larisa!
...org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToAggregateMetricDouble.java
Outdated
Show resolved
Hide resolved
...org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToAggregateMetricDouble.java
Outdated
Show resolved
Hide resolved
...org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToAggregateMetricDouble.java
Outdated
Show resolved
Hide resolved
|
||
@Override | ||
public EvalOperator.ExpressionEvaluator get(DriverContext context) { | ||
final EvalOperator.ExpressionEvaluator eval = fieldEvaluator.get(context); |
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 use CastLongToDoubleEvaluator
for the single-value case.
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.
Decided to manually implement because the overhead might not be worth what we save
2ba29f0
to
2ccfd46
Compare
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 left a few questions for my understanding.
I think this looks good.
} | ||
|
||
@Override | ||
protected int valuesLength() { |
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.
Are these methods not used?
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.
They weren't necessary at this stage (and they're still not implemented on the original AggregateMetricDoubleBlockBuilder) and I had wanted to get eyes on this approach so I left them like that; I actually have a subtask in the meta-issue for figuring out what to do with these methods
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.
Since I changed it to no longer extend AbstractBlockBuilder these methods don't need to be implemented for this anymore (they're still unimplemented for AggregateMetricDoubleBlockBuilder though)
body: | ||
query: "FROM test-* | | ||
WHERE k8s.pod.uid == \"947e4ced-1786-4e53-9e0c-5c447e959507\" | | ||
EVAL rx = to_aggregate_metric_double(k8s.pod.network.rx) | |
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.
Should to_aggregate_metric_double
be injected automatically if an index pattern queries a field mapped as long in one index and aggregate_metric_double in the other index?
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.
This is required for now in ES|QL. We can discuss making this union type automatic in a follow-up.
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 added a task for this in the meta issue
@@ -285,7 +285,19 @@ private static Object valueAtOffset(Block block, int offset) { | |||
DocVector v = ((DocBlock) block).asVector(); | |||
yield new Doc(v.shards().getInt(offset), v.segments().getInt(offset), v.docs().getInt(offset)); | |||
} | |||
case COMPOSITE -> throw new IllegalArgumentException("can't read values from composite blocks"); | |||
case COMPOSITE -> { | |||
CompositeBlock compositeBlock = (CompositeBlock) block; |
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 in a follow up the usage of CompositeBlock
for aggregate metric double field be replaced with AggregateMetricDoubleBlockBuilder
?
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'm not sure I understand? There's no block creation here, just fetching the value from the block that already exists, so no building is involved
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.
Sorry, this is comment doesn't make sense here. I think I was more wondering about whether in AggregateMetricDoubleBlockBuilder
we should use build a specialized block instead of building CompositeBlock
. ComposteBlock
is very generic and using this here now I think is ok, I'm just wondering whether in the future this makes sense? (when there are more usages of CompositeBlock
)
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.
We could if we wanted, but I'm not sure it's all that important. The entire compute engine is pretty ok with runtime types and treating blocks in specific ways based on the input. We don't have a special type for utf-8 text - just bytes - so I'm not sure we'd need a special type for these blocks.
If we want it we can have it for sure, but I don't think it's all that important.
.newAggregateMetricDoubleBlockBuilder(positionCount) | ||
) { | ||
CompensatedSum compensatedSum = new CompensatedSum(); | ||
for (int p = 0; p < positionCount; p++) { |
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.
Is this iteration for multivalued fields?
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.
Indeed..!
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.
It's getting closer. Thanks @limotova.
|
||
} | ||
|
||
public static class AggregateMetricDoubleVectorBuilder extends AbstractBlockBuilder { |
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.
Should we not extend from BlockBuilder but just a Releasable here. Also should we move this to ToAggregateMetricDouble class instead?
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.
Yeah I think keeping it in ToAggregateMetricDouble makes sense, I moved it there, but that class is getting quite heavy, I wonder if the factories should be moved into a separate file?
.../compute/src/main/java/org/elasticsearch/compute/data/AggregateMetricDoubleBlockBuilder.java
Outdated
Show resolved
Hide resolved
...org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToAggregateMetricDouble.java
Outdated
Show resolved
Hide resolved
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's ready. Thanks Larisa!
...org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToAggregateMetricDouble.java
Outdated
Show resolved
Hide resolved
...org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToAggregateMetricDouble.java
Show resolved
Hide resolved
|
Hi @limotova, I've created a changelog YAML for you. |
Pinging @elastic/es-analytical-engine (Team:Analytics) |
Pinging @elastic/es-storage-engine (Team:StorageEngine) |
💔 Backport failed
You can use sqren/backport to manually backport by running |
* [ES|QL] ToAggregateMetricDouble function (#124595) This commit adds a conversion function from numerics (and aggregate metric doubles) to aggregate metric doubles. It is most useful when you have multiple indices, where one index uses aggregate metric double (e.g. a downsampled index) and another uses a normal numeric type like long or double (e.g. an index prior to downsampling). * modify docs and factory constructors
This commit adds a conversion function from numerics (and aggregate metric doubles) to aggregate metric doubles. It is most useful when you have multiple indices, where one index uses aggregate metric double (e.g. a downsampled index) and another uses a normal numeric type like long or double (e.g. an index prior to downsampling).
This commit adds a conversion function from numerics (and aggregate metric doubles) to aggregate metric doubles. It is most useful when you have multiple indices, where one index uses aggregate metric double (e.g. a downsampled index) and another uses a normal numeric type like long or double (e.g. an index prior to downsampling).
* [ES|QL] ToAggregateMetricDouble function (#124595) This commit adds a conversion function from numerics (and aggregate metric doubles) to aggregate metric doubles. It is most useful when you have multiple indices, where one index uses aggregate metric double (e.g. a downsampled index) and another uses a normal numeric type like long or double (e.g. an index prior to downsampling). * remove old docs * [ES|QL] Add ToAggregateMetricDouble example (#125518) Adds AggregateMetricDouble to the ES|QL CSV tests and examples of how to use the ToAggregateMetricDouble function * [ES|QL] Fix sorting when aggregate_metric_double present (#125191) Previously if an aggregate_metric_double was present amongst fields and you tried to sort on any (not necessarily even on the agg_metric itself) field in ES|QL, it would break the results. This commit doesn't add support for sorting _on_ aggregate_metric_double (it is unclear what aspect would be sorted), but it fixes the previous behavior. * drop old style docs again * add new style docs * [CI] Auto commit changes from spotless --------- Co-authored-by: elasticsearchmachine <infra-root+elasticsearchmachine@elastic.co>
This commit adds a conversion function from numerics (and aggregate
metric doubles) to aggregate metric doubles.
It is most useful when you have multiple indices, where one index uses
aggregate metric double (e.g. a downsampled index) and another uses a
normal numeric type like long or double (e.g. an index prior to
downsampling).