-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Update aggs code generation to be more explicit about required methods #121749
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
Update aggs code generation to be more explicit about required methods #121749
Conversation
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.
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
080b6c3 to
a7042e6
Compare
a7042e6 to
be957db
Compare
|
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 |
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 is enforced in 57d34e4 please let me know if that should be merged as well.
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.
That commit looks good to me. It exists already right? So enforcing it looks fine
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 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 |
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.
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() |
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 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
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 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.
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'll think how to handle this. Thanks for the pointer!
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 tried to change it and currently it fails because of:
Lines 21 to 25 in 2c205e3
| 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:
Lines 22 to 28 in 3aeb7d5
| 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.
💔 Backport failed
You can use sqren/backport to manually backport by running |
elastic#121749) (cherry picked from commit 7deaacd)
This introduces various changes to make it easier to understand error output from Aggs code generation.
For example missing
MaxBytesRefAggregator#combineIntermediatenow results induring code generation. Previously it resulted in multiple code compilation errors in generated code without any hints on how to resolve them.