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.
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.
Sure, already added.
| package org.opensearch.sql.calcite.udf; | ||
|
|
||
| public interface Accumulator { | ||
| Object result(); |
There was a problem hiding this comment.
- 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.
- 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.
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.
use javadoc /** */ before signature.
| public interface UserDefinedAggFunction<S extends Accumulator> { | ||
| S init(); | ||
|
|
||
| Object result(S accumulator); |
There was a problem hiding this comment.
in UDF, the method name is eval, should we change to eval either?
There was a problem hiding this comment.
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); |
| @@ -0,0 +1,55 @@ | |||
| package org.opensearch.sql.calcite.udf.udaf; | |||
| return hits; | ||
| } | ||
|
|
||
| public void add(Object value) { |
There was a problem hiding this comment.
should add be a part of interface method signature?
There was a problem hiding this comment.
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.
Have you run ./gradlew spotlessApply before pushing?
There was a problem hiding this comment.
Forget to run. Just rerun the push.
| S init(); | ||
|
|
||
| /** | ||
| * |
| @Override | ||
| public Object result() { | ||
| public Object value() { | ||
| return hits; | ||
| } |
There was a problem hiding this comment.
Code indentation problem, please run ./gradlew spotlessApply
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.