Skip to content

Commit adb8997

Browse files
committed
add description for each function
Signed-off-by: xinyual <xinyual@amazon.com>
1 parent 32bfaa8 commit adb8997

6 files changed

Lines changed: 29 additions & 0 deletions

File tree

core/src/main/java/org/opensearch/sql/expression/function/CollectionUDF/ArrayFunctionImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
import org.opensearch.sql.expression.function.UDFOperandMetadata;
2929

3030
// TODO: Support array of mixture types.
31+
32+
/**
33+
* create an array with input values. We will infer a least restricted type, for example array(1,
34+
* "demo") -> ["1", "demo"]
35+
*/
3136
public class ArrayFunctionImpl extends ImplementorUDF {
3237
public ArrayFunctionImpl() {
3338
super(new ArrayImplementor(), NullPolicy.ANY);

core/src/main/java/org/opensearch/sql/expression/function/CollectionUDF/ExistsFunctionImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
import org.opensearch.sql.expression.function.ImplementorUDF;
2020
import org.opensearch.sql.expression.function.UDFOperandMetadata;
2121

22+
/**
23+
* The function check whether existing one of element inside array can meet the lambda function. The
24+
* function should also return boolean. For example, array=array(1, -2, -1), forall(array, x -> x >
25+
* 0) = true
26+
*/
2227
public class ExistsFunctionImpl extends ImplementorUDF {
2328
public ExistsFunctionImpl() {
2429
super(new ExistsImplementor(), NullPolicy.ALL);

core/src/main/java/org/opensearch/sql/expression/function/CollectionUDF/FilterFunctionImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
import org.opensearch.sql.expression.function.ImplementorUDF;
2121
import org.opensearch.sql.expression.function.UDFOperandMetadata;
2222

23+
/**
24+
* The function filter the element in the array by the lambda function. The function should return
25+
* boolean. For example, array=array(1, 2, -1) filter(array, x -> x > 0) = [1, 2]
26+
*/
2327
public class FilterFunctionImpl extends ImplementorUDF {
2428
public FilterFunctionImpl() {
2529
super(new FilterImplementor(), NullPolicy.ANY);

core/src/main/java/org/opensearch/sql/expression/function/CollectionUDF/ForallFunctionImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
import org.opensearch.sql.expression.function.ImplementorUDF;
2020
import org.opensearch.sql.expression.function.UDFOperandMetadata;
2121

22+
/**
23+
* The function check whether all element inside array can meet the lambda function. The function
24+
* should also return boolean. For example, array=array(1, 2, -1), forall(array, x -> x > 0) = false
25+
*/
2226
public class ForallFunctionImpl extends ImplementorUDF {
2327
public ForallFunctionImpl() {
2428
super(new ForallImplementor(), NullPolicy.ALL);

core/src/main/java/org/opensearch/sql/expression/function/CollectionUDF/ReduceFunctionImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
import org.opensearch.sql.expression.function.ImplementorUDF;
3131
import org.opensearch.sql.expression.function.UDFOperandMetadata;
3232

33+
/**
34+
* The function will first use acc_function to go through all element and return value to the acc.
35+
* Then apply reduce function to the acc if exists. For example, array=array(1, 2, 3), reduce(array,
36+
* 0, (acc, x) -> acc + x) = 6, reduce(array, 0, (acc, x) -> acc + x, acc -> acc * 10) = 60
37+
*/
3338
public class ReduceFunctionImpl extends ImplementorUDF {
3439
public ReduceFunctionImpl() {
3540
super(new ReduceImplementor(), NullPolicy.ANY);

core/src/main/java/org/opensearch/sql/expression/function/CollectionUDF/TransformFunctionImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
import org.opensearch.sql.expression.function.ImplementorUDF;
2929
import org.opensearch.sql.expression.function.UDFOperandMetadata;
3030

31+
/**
32+
* The function transform the element of array one by one using lambda. For example, array=array(1,
33+
* 2, 3), transform(array, x -> x + 2) = [3, 4, 5] Transform can accept one more argument like (x,
34+
* i) -> x + i, where i is the index of element in array. For example, array=array(1, 2, 3),
35+
* transform(array, (x, i) -> x + i) = [1, 3, 5]
36+
*/
3137
public class TransformFunctionImpl extends ImplementorUDF {
3238
public TransformFunctionImpl() {
3339
super(new TransformImplementor(), NullPolicy.ANY);

0 commit comments

Comments
 (0)