-
Couldn't load subscription status.
- Fork 176
Add udf interface #3374
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
Add udf interface #3374
Conversation
Signed-off-by: xinyual <xinyual@amazon.com>
Signed-off-by: xinyual <xinyual@amazon.com>
Signed-off-by: xinyual <xinyual@amazon.com>
Signed-off-by: xinyual <xinyual@amazon.com>
| } | ||
| } | ||
|
|
||
| static List<RexNode> translateArgument( |
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 this is a framework work, we will change this method frequently, could you add some comments to explain this method for developers
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.
Sure, already added.
| package org.opensearch.sql.calcite.udf; | ||
|
|
||
| public interface Accumulator { | ||
| Object result(); |
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.
- some comments for this method.
- could it be moved to class
UserDefinedAggFunction.javasince it is only used for UDAF - how about name to
value() - as a accumulator, do we need another method
merge()to merge two Acc objects.
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.
- Already done.
- Already done.
- Already done.
- Can you elaborate more in which scenario we may need to do so? Accumulator is something like
AggregationState, do we need to consider merge 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.
4
The merge method in an Accumulator is used to combine two accumulators into one. It's particularly important in distributed computing scenarios where partial results from different workers/nodes need to be combined into a final result. In parallel processing, different partitions of data might be processed by different workers.
Example:
class CountAccumulator implements Accumulator<Integer> {
private int count = 0;
public void add(Integer value) {
count++;
}
public void merge(Accumulator other) {
// Combine the counts from both accumulators
count += ((CountAccumulator)other).count;
}
}Seems it's not required in current framework since SQL plugin is running in coordinator node only.
|
|
||
| Object result(S accumulator); | ||
|
|
||
| // Add values to the accumulator |
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.
use javadoc /** */ before signature.
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.
Done.
| public interface UserDefinedAggFunction<S extends Accumulator> { | ||
| S init(); | ||
|
|
||
| Object result(S accumulator); |
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.
in UDF, the method name is eval, should we change to eval either?
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.
For the function name of agg function, it's defined in calcite here https://github.com/apache/calcite/blob/1793ba79a328c61fb42842f443334cc1353c985f/core/src/main/java/org/apache/calcite/schema/impl/AggregateFunctionImpl.java#L91. We cannot modify them. I will left comment.
| package org.opensearch.sql.calcite.udf; | ||
|
|
||
| public interface UserDefinedFunction { | ||
| Object eval(Object... args); |
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.
Add comments.
| @@ -0,0 +1,55 @@ | |||
| package org.opensearch.sql.calcite.udf.udaf; | |||
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.
copyright header missing
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.
Done.
| return hits; | ||
| } | ||
|
|
||
| public void add(Object value) { |
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 add be a part of interface method signature?
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 just compare the interface AggregationState. I think we could just make sure we have add in UserDefinedAggFunction. For Accumulator, they can implement their own functions.
|
Add |
|
|
Signed-off-by: xinyual <xinyual@amazon.com>
| */ | ||
| interface Accumulator { | ||
| /** | ||
| * @return the final aggregation value |
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.
Have you run ./gradlew spotlessApply before pushing?
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.
Forget to run. Just rerun the push.
| S init(); | ||
|
|
||
| /** | ||
| * |
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.
format issue
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.
Done.
| @Override | ||
| public Object result() { | ||
| public Object value() { | ||
| return hits; | ||
| } |
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.
Code indentation problem, please run ./gradlew spotlessApply
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.
Done.
Signed-off-by: xinyual <xinyual@amazon.com>
6668aa8
into
opensearch-project:feature/calcite-engine
* add udf/udaf interface and take/sqrt function Signed-off-by: xinyual <xinyual@amazon.com> * add UT Signed-off-by: xinyual <xinyual@amazon.com> * add POW, Atan, Atan2 and corresponding UT Signed-off-by: xinyual <xinyual@amazon.com> * apply spotless Signed-off-by: xinyual <xinyual@amazon.com> * fix table for join it Signed-off-by: xinyual <xinyual@amazon.com> * add java doc Signed-off-by: xinyual <xinyual@amazon.com> * apply spotless Signed-off-by: xinyual <xinyual@amazon.com> --------- Signed-off-by: xinyual <xinyual@amazon.com>
* add udf/udaf interface and take/sqrt function Signed-off-by: xinyual <xinyual@amazon.com> * add UT Signed-off-by: xinyual <xinyual@amazon.com> * add POW, Atan, Atan2 and corresponding UT Signed-off-by: xinyual <xinyual@amazon.com> * apply spotless Signed-off-by: xinyual <xinyual@amazon.com> * fix table for join it Signed-off-by: xinyual <xinyual@amazon.com> * add java doc Signed-off-by: xinyual <xinyual@amazon.com> * apply spotless Signed-off-by: xinyual <xinyual@amazon.com> --------- Signed-off-by: xinyual <xinyual@amazon.com>
Description
This pr is main:
a. Directly map to calcite built-in function, but need modification for argument (optional). e.g. Atan/Atan2/pow
b. cannot find suitable built-in function, need to write our own logic. E.g. sqrt function, take aggregation function
./gradlew :integ-test:integTest --tests 'CalciteIT' succeed locally
Related Issues
Resolves #[Issue number to be closed when this PR is merged]
#3310
Check List
--signoff.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.