Skip to content

Conversation

@idegtiarenko
Copy link
Contributor

@idegtiarenko idegtiarenko commented Feb 5, 2025

This introduces various changes to make it easier to understand error output from Aggs code generation.

For example missing MaxBytesRefAggregator#combineIntermediate now results in

> java.lang.IllegalArgumentException: Requires method public static void org.elasticsearch.compute.aggregation.MaxBytesRefAggregator#combineIntermediate(org.elasticsearch.compute.aggregation.MaxBytesRefAggregator.SingleState, org.apache.lucene.util.BytesRef, boolean)

during code generation. Previously it resulted in multiple code compilation errors in generated code without any hints on how to resolve them.

@idegtiarenko idegtiarenko added >non-issue Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) :Analytics/ES|QL AKA ESQL v9.0.0 labels Feb 5, 2025
Copy link
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

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

Nice. I like the direction very much.

# Conflicts:
#	x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/AggregatorImplementer.java
#	x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/GroupingAggregatorImplementer.java
#	x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/Types.java
@idegtiarenko idegtiarenko marked this pull request as ready for review February 6, 2025 12:21
@idegtiarenko idegtiarenko requested a review from nik9000 February 6, 2025 12:22
@elasticsearchmachine
Copy link
Collaborator

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

this.init = findRequiredMethod(declarationType, new String[] { "init", "initSingle" }, e -> true);
this.init = requireStaticMethod(
declarationType,
// This should be more restrictive and require org.elasticsearch.compute.aggregation.AggregatorState
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is enforced in 57d34e4 please let me know if that should be merged as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

That commit looks good to me. It exists already right? So enforcing it looks fine

Copy link
Contributor

@ivancea ivancea 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 the implementer API is quite better this way, and failing early with good messages will surely help a lot. Thanks!

this.init = findRequiredMethod(declarationType, new String[] { "init", "initSingle" }, e -> true);
this.init = requireStaticMethod(
declarationType,
// This should be more restrictive and require org.elasticsearch.compute.aggregation.AggregatorState
Copy link
Contributor

Choose a reason for hiding this comment

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

That commit looks good to me. It exists already right? So enforcing it looks fine

.filter(method -> nameMatcher.test(method.getSimpleName().toString()))
.filter(method -> returnTypeMatcher.test(TypeName.get(method.getReturnType())))
.filter(method -> argumentMatcher.test(method.getParameters().stream().map(it -> TypeName.get(it.asType())).toList()))
.findFirst()
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also verify that there's only 1 method with such declaration? As to avoid overloads here. Just a little extra check that could avoid potential problems, for example, when copypasting grouping/non-grouping methods.

Not sure if there's any case where overloads are required though. Maybe we could make another require...() method/overload for those specific cases

Copy link
Contributor Author

@idegtiarenko idegtiarenko Feb 6, 2025

Choose a reason for hiding this comment

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

I do not think that such situation is possible. We would have a compilation error (before code generation) when trying to compile a class with 2 methods with exactly the same signature.

With init we have a bit more relaxed arg condition as we allow any arguments. In this case I imagine it might be valid to have something like:

public static SingleState init() { return init(DEFAULT_VALUE); }
public static SingleState init(int defaultValue) { ... }

Although it is not clear what implementation is going to be picked by the code generation then.

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'll think how to handle this. Thanks for the pointer!

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 tried to change it and currently it fails because of:

class SumFloatAggregator extends SumDoubleAggregator {
public static void combine(SumState current, float v) {
current.add(v);
}

As it has 2 signatures matching:

void SumFloatAggregator#combine(SumState current, float v)
void SumDoubleAggregator#combine(SumState current, double v)

May be we should not extend SumFloatAggregator from SumDoubleAggregator.

There is another collision:

public static long combine(long current, int v) {
return Math.addExact(current, v);
}
public static long combine(long current, long v) {
return Math.addExact(current, v);
}

This usage is valid. We are using first combine to add column value to accumulator and a second one to combine 2 accumulators.

I would like not to change it and delay unique signature check for now.

@idegtiarenko idegtiarenko added auto-backport Automatically create backport pull requests when merged v9.0.0 v8.19.0 labels Feb 10, 2025
@idegtiarenko idegtiarenko merged commit 7deaacd into elastic:main Feb 10, 2025
17 checks passed
@idegtiarenko idegtiarenko deleted the aggs_code_generation branch February 10, 2025 08:40
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
9.0 Commit could not be cherrypicked due to conflicts
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 121749

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 backport pending >non-issue Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v8.19.0 v9.0.0 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants