Skip to content

[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

Merged
merged 20 commits into from
Mar 18, 2025

Conversation

limotova
Copy link
Contributor

@limotova limotova commented Mar 11, 2025

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).

@limotova limotova force-pushed the to-aggregate-metric-double-function branch 2 times, most recently from 2af99c4 to e7bae9b Compare March 13, 2025 09:37
@limotova limotova force-pushed the to-aggregate-metric-double-function branch from e7bae9b to 2f64c49 Compare March 13, 2025 09:53
@dnhatn dnhatn self-requested a review March 13, 2025 17:51
@limotova limotova changed the title ToAggregateMetricDouble function [ES|QL] ToAggregateMetricDouble function Mar 14, 2025
Copy link
Member

@dnhatn dnhatn left a 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!


@Override
public EvalOperator.ExpressionEvaluator get(DriverContext context) {
final EvalOperator.ExpressionEvaluator eval = fieldEvaluator.get(context);
Copy link
Member

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.

Copy link
Contributor Author

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

@limotova limotova force-pushed the to-aggregate-metric-double-function branch from 2ba29f0 to 2ccfd46 Compare March 15, 2025 04:34
Copy link
Member

@martijnvg martijnvg left a 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() {
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

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) |
Copy link
Member

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?

Copy link
Member

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.

Copy link
Contributor Author

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;
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Member

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)

Copy link
Member

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++) {
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed..!

Copy link
Member

@dnhatn dnhatn left a 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 {
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

@dnhatn dnhatn left a 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!

@limotova
Copy link
Contributor Author

limotova commented Mar 18, 2025

Merging because build has passed, it's just not being reported wait nevermind this is still a draft

@limotova limotova marked this pull request as ready for review March 18, 2025 18:17
@elasticsearchmachine elasticsearchmachine added the needs:triage Requires assignment of a team area label label Mar 18, 2025
@limotova limotova added >enhancement auto-backport Automatically create backport pull requests when merged :StorageEngine/TSDB You know, for Metrics :Analytics/Compute Engine Analytics in ES|QL and removed needs:triage Requires assignment of a team area label labels Mar 18, 2025
@elasticsearchmachine elasticsearchmachine added Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) Team:StorageEngine labels Mar 18, 2025
@elasticsearchmachine
Copy link
Collaborator

Hi @limotova, I've created a changelog YAML for you.

@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-storage-engine (Team:StorageEngine)

@limotova limotova added v8.19.0 :Analytics/ES|QL AKA ESQL and removed :Analytics/Compute Engine Analytics in ES|QL labels Mar 18, 2025
@limotova limotova merged commit 08ae54e into elastic:main Mar 18, 2025
17 checks passed
@limotova limotova deleted the to-aggregate-metric-double-function branch March 18, 2025 21:39
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
8.x Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 124595

elasticsearchmachine pushed a commit that referenced this pull request Mar 18, 2025
* [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
elasticsearchmachine pushed a commit that referenced this pull request Mar 20, 2025
…5172)" (#125277)

This reverts commit 6979cad.

Adjusting the TransportVersion introduced in this commit for backporting
is nontrivial so I am reverting this until we come up with an approach
for it.
smalyshev pushed a commit to smalyshev/elasticsearch that referenced this pull request Mar 21, 2025
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).
omricohenn pushed a commit to omricohenn/elasticsearch that referenced this pull request Mar 28, 2025
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).
elasticsearchmachine pushed a commit that referenced this pull request Apr 8, 2025
* [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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/ES|QL AKA ESQL auto-backport Automatically create backport pull requests when merged >enhancement :StorageEngine/TSDB You know, for Metrics Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) Team:StorageEngine v8.19.0 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants