Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@
import org.opensearch.sql.expression.function.udf.math.ConvFunction;
import org.opensearch.sql.expression.function.udf.math.DivideFunction;
import org.opensearch.sql.expression.function.udf.math.EulerFunction;
import org.opensearch.sql.expression.function.udf.math.MaxFunction;
import org.opensearch.sql.expression.function.udf.math.MinFunction;
import org.opensearch.sql.expression.function.udf.math.ModFunction;
import org.opensearch.sql.expression.function.udf.math.NumberToStringFunction;
import org.opensearch.sql.expression.function.udf.math.ScalarMaxFunction;
import org.opensearch.sql.expression.function.udf.math.ScalarMinFunction;

/** Defines functions and operators that are implemented only by PPL */
public class PPLBuiltinOperators extends ReflectiveSqlOperatorTable {
Expand Down Expand Up @@ -131,8 +131,8 @@ public class PPLBuiltinOperators extends ReflectiveSqlOperatorTable {
public static final SqlOperator DIVIDE = new DivideFunction().toUDF("DIVIDE");
public static final SqlOperator SHA2 = CryptographicFunction.sha2().toUDF("SHA2");
public static final SqlOperator CIDRMATCH = new CidrMatchFunction().toUDF("CIDRMATCH");
public static final SqlOperator MAX = new MaxFunction().toUDF("MAX");
public static final SqlOperator MIN = new MinFunction().toUDF("MIN");
public static final SqlOperator SCALAR_MAX = new ScalarMaxFunction().toUDF("SCALAR_MAX");
public static final SqlOperator SCALAR_MIN = new ScalarMinFunction().toUDF("SCALAR_MIN");

public static final SqlOperator COSH =
adaptMathFunctionToUDF(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -856,8 +856,8 @@ void populate() {
registerOperator(INTERNAL_TRANSLATE3, SqlLibraryOperators.TRANSLATE3);

// Register eval functions for PPL max() and min() calls
registerOperator(MAX, PPLBuiltinOperators.MAX);
registerOperator(MIN, PPLBuiltinOperators.MIN);
registerOperator(MAX, PPLBuiltinOperators.SCALAR_MAX);
registerOperator(MIN, PPLBuiltinOperators.SCALAR_MIN);

// Register PPL UDF operator
registerOperator(COSH, PPLBuiltinOperators.COSH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ default SqlUserDefinedFunction toUDF(String functionName, boolean isDeterministi
public boolean isDeterministic() {
return isDeterministic;
}

@Override
public SqlIdentifier getSqlIdentifier() {
// to avoid convert to sql dialog as identifier, use keyword instead
// check the code SqlUtil.unparseFunctionSyntax()
return null;
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
* MAX(value1, value2, ...) returns the maximum value from the arguments. For mixed types, strings
* have higher precedence than numbers.
*/
public class MaxFunction extends ImplementorUDF {
public class ScalarMaxFunction extends ImplementorUDF {

public MaxFunction() {
public ScalarMaxFunction() {
super(new MaxImplementor(), NullPolicy.ALL);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
* MIN(value1, value2, ...) returns the minimum value from the arguments. For mixed types, numbers
* have higher precedence than strings.
*/
public class MinFunction extends ImplementorUDF {
public class ScalarMinFunction extends ImplementorUDF {

public MinFunction() {
public ScalarMinFunction() {
super(new MinImplementor(), NullPolicy.ALL);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1300,19 +1300,19 @@ public void testExplainSortOnMeasureMultiBucketsNotMultiTermsNotPushDown() throw

@Test
public void testExplainEvalMax() throws IOException {
String expected = loadExpectedPlan("explain_eval_max.json");
assertJsonEqualsIgnoreId(
String expected = loadExpectedPlan("explain_eval_max.yaml");
assertYamlEqualsIgnoreId(
expected,
explainQueryToString(
explainQueryYaml(
"source=opensearch-sql_test_index_account | eval new = max(1, 2, 3, age, 'banana')"));
}

@Test
public void testExplainEvalMin() throws IOException {
String expected = loadExpectedPlan("explain_eval_min.json");
assertJsonEqualsIgnoreId(
String expected = loadExpectedPlan("explain_eval_min.yaml");
assertYamlEqualsIgnoreId(
expected,
explainQueryToString(
explainQueryYaml(
"source=opensearch-sql_test_index_account | eval new = min(1, 2, 3, age, 'banana')"));
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
calcite:
logical: |
LogicalSystemLimit(fetch=[10000], type=[QUERY_SIZE_LIMIT])
LogicalProject(account_number=[$0], firstname=[$1], address=[$2], balance=[$3], gender=[$4], city=[$5], employer=[$6], state=[$7], age=[$8], email=[$9], lastname=[$10], new=[SCALAR_MAX(1, 2, 3, $8, 'banana':VARCHAR)])
CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])
physical: |
EnumerableCalc(expr#0..10=[{inputs}], expr#11=[1], expr#12=[2], expr#13=[3], expr#14=['banana':VARCHAR], expr#15=[SCALAR_MAX($t11, $t12, $t13, $t8, $t14)], proj#0..10=[{exprs}], $f11=[$t15])
CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]], PushDownContext=[[PROJECT->[account_number, firstname, address, balance, gender, city, employer, state, age, email, lastname], LIMIT->10000], OpenSearchRequestBuilder(sourceBuilder={"from":0,"size":10000,"timeout":"1m","_source":{"includes":["account_number","firstname","address","balance","gender","city","employer","state","age","email","lastname"],"excludes":[]}}, requestedTotalSize=10000, pageSize=null, startFrom=0)])

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
calcite:
logical: |
LogicalSystemLimit(fetch=[10000], type=[QUERY_SIZE_LIMIT])
LogicalProject(account_number=[$0], firstname=[$1], address=[$2], balance=[$3], gender=[$4], city=[$5], employer=[$6], state=[$7], age=[$8], email=[$9], lastname=[$10], new=[SCALAR_MIN(1, 2, 3, $8, 'banana':VARCHAR)])
CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])
physical: |
EnumerableCalc(expr#0..10=[{inputs}], expr#11=[1], expr#12=[2], expr#13=[3], expr#14=['banana':VARCHAR], expr#15=[SCALAR_MIN($t11, $t12, $t13, $t8, $t14)], proj#0..10=[{exprs}], $f11=[$t15])
CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]], PushDownContext=[[PROJECT->[account_number, firstname, address, balance, gender, city, employer, state, age, email, lastname], LIMIT->10000], OpenSearchRequestBuilder(sourceBuilder={"from":0,"size":10000,"timeout":"1m","_source":{"includes":["account_number","firstname","address","balance","gender","city","employer","state","age","email","lastname"],"excludes":[]}}, requestedTotalSize=10000, pageSize=null, startFrom=0)])

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
calcite:
logical: |
LogicalSystemLimit(fetch=[10000], type=[QUERY_SIZE_LIMIT])
LogicalProject(account_number=[$0], firstname=[$1], address=[$2], balance=[$3], gender=[$4], city=[$5], employer=[$6], state=[$7], age=[$8], email=[$9], lastname=[$10], new=[SCALAR_MAX(1, 2, 3, $8, 'banana':VARCHAR)])
CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])
physical: |
EnumerableLimit(fetch=[10000])
EnumerableCalc(expr#0..16=[{inputs}], expr#17=[1], expr#18=[2], expr#19=[3], expr#20=['banana':VARCHAR], expr#21=[SCALAR_MAX($t17, $t18, $t19, $t8, $t20)], proj#0..10=[{exprs}], new=[$t21])
CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
calcite:
logical: |
LogicalSystemLimit(fetch=[10000], type=[QUERY_SIZE_LIMIT])
LogicalProject(account_number=[$0], firstname=[$1], address=[$2], balance=[$3], gender=[$4], city=[$5], employer=[$6], state=[$7], age=[$8], email=[$9], lastname=[$10], new=[SCALAR_MIN(1, 2, 3, $8, 'banana':VARCHAR)])
CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])
physical: |
EnumerableLimit(fetch=[10000])
EnumerableCalc(expr#0..16=[{inputs}], expr#17=[1], expr#18=[2], expr#19=[3], expr#20=['banana':VARCHAR], expr#21=[SCALAR_MIN($t17, $t18, $t19, $t8, $t20)], proj#0..10=[{exprs}], new=[$t21])
CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,9 @@ public void testAvgBySpanAndFields() {

String expectedSparkSql =
""
+ "SELECT AVG(`SAL`) `avg(SAL)`, `SPAN`(`EMPNO`, 500, NULL) `empno_span`, `DEPTNO`\n"
+ "SELECT AVG(`SAL`) `avg(SAL)`, SPAN(`EMPNO`, 500, NULL) `empno_span`, `DEPTNO`\n"
+ "FROM `scott`.`EMP`\n"
+ "GROUP BY `DEPTNO`, `SPAN`(`EMPNO`, 500, NULL)\n"
+ "GROUP BY `DEPTNO`, SPAN(`EMPNO`, 500, NULL)\n"
+ "ORDER BY `DEPTNO`, 2";
verifyPPLToSparkSQL(root, expectedSparkSql);
}
Expand All @@ -470,10 +470,10 @@ public void testAvgByTimeSpanAndFields() {
verifyLogical(root, expectedLogical);

String expectedSparkSql =
"SELECT AVG(`SAL`) `avg(SAL)`, `SPAN`(`HIREDATE`, 1, 'y') `hiredate_span`, `DEPTNO`\n"
"SELECT AVG(`SAL`) `avg(SAL)`, SPAN(`HIREDATE`, 1, 'y') `hiredate_span`, `DEPTNO`\n"
+ "FROM `scott`.`EMP`\n"
+ "WHERE `HIREDATE` IS NOT NULL\n"
+ "GROUP BY `DEPTNO`, `SPAN`(`HIREDATE`, 1, 'y')\n"
+ "GROUP BY `DEPTNO`, SPAN(`HIREDATE`, 1, 'y')\n"
+ "ORDER BY `DEPTNO`, 2";
verifyPPLToSparkSQL(root, expectedSparkSql);
}
Expand Down Expand Up @@ -596,9 +596,9 @@ public void testStddevSampByFieldWithAlias() {

String expectedSparkSql =
""
+ "SELECT STDDEV_SAMP(`SAL`) `samp`, `SPAN`(`EMPNO`, 100, NULL) `empno_span`\n"
+ "SELECT STDDEV_SAMP(`SAL`) `samp`, SPAN(`EMPNO`, 100, NULL) `empno_span`\n"
+ "FROM `scott`.`EMP`\n"
+ "GROUP BY `SPAN`(`EMPNO`, 100, NULL)";
+ "GROUP BY SPAN(`EMPNO`, 100, NULL)";
verifyPPLToSparkSQL(root, expectedSparkSql);
}

Expand Down Expand Up @@ -982,10 +982,10 @@ public void testSortAggregationMetrics2() {
verifyLogical(root, expectedLogical);

String expectedSparkSql =
"SELECT AVG(`SAL`) `avg`, `SPAN`(`HIREDATE`, 1, 'y') `hiredate_span`\n"
"SELECT AVG(`SAL`) `avg`, SPAN(`HIREDATE`, 1, 'y') `hiredate_span`\n"
+ "FROM `scott`.`EMP`\n"
+ "WHERE `HIREDATE` IS NOT NULL\n"
+ "GROUP BY `SPAN`(`HIREDATE`, 1, 'y')\n"
+ "GROUP BY SPAN(`HIREDATE`, 1, 'y')\n"
+ "ORDER BY 1";
verifyPPLToSparkSQL(root, expectedSparkSql);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void testMvjoinWithStringArray() {
verifyResult(root, expectedResult);

String expectedSparkSql =
"SELECT ARRAY_JOIN(`array`('a', 'b', 'c'), ',') `joined`\n"
"SELECT ARRAY_JOIN(ARRAY('a', 'b', 'c'), ',') `joined`\n"
+ "FROM `scott`.`EMP`\n"
+ "LIMIT 1";
verifyPPLToSparkSQL(root, expectedSparkSql);
Expand All @@ -59,7 +59,7 @@ public void testMvjoinWithDifferentDelimiter() {
verifyResult(root, expectedResult);

String expectedSparkSql =
"SELECT ARRAY_JOIN(`array`('apple', 'banana', 'cherry'), ' | ') `joined`\n"
"SELECT ARRAY_JOIN(ARRAY('apple', 'banana', 'cherry'), ' | ') `joined`\n"
+ "FROM `scott`.`EMP`\n"
+ "LIMIT 1";
verifyPPLToSparkSQL(root, expectedSparkSql);
Expand All @@ -82,7 +82,7 @@ public void testMvjoinWithEmptyArray() {
verifyResult(root, expectedResult);

String expectedSparkSql =
"SELECT ARRAY_JOIN(`array`(), ',') `joined`\n" + "FROM `scott`.`EMP`\n" + "LIMIT 1";
"SELECT ARRAY_JOIN(ARRAY(), ',') `joined`\n" + "FROM `scott`.`EMP`\n" + "LIMIT 1";
verifyPPLToSparkSQL(root, expectedSparkSql);
}

Expand All @@ -101,7 +101,7 @@ public void testMvjoinWithFieldReference() {
verifyLogical(root, expectedLogical);

String expectedSparkSql =
"SELECT ARRAY_JOIN(`array`(`ENAME`, `JOB`), '-') `joined`\n"
"SELECT ARRAY_JOIN(ARRAY(`ENAME`, `JOB`), '-') `joined`\n"
+ "FROM `scott`.`EMP`\n"
+ "LIMIT 1";
verifyPPLToSparkSQL(root, expectedSparkSql);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,11 +493,11 @@ public void testDecimalLiteral() {
verifyLogical(root, expectedLogical);

String expectedSparkSql =
"SELECT `DIVIDE`(22, 7.0) `r1`, `DIVIDE`(22, 7.0E0) `r2`, `DIVIDE`(22.0, 7) `r3`,"
+ " `DIVIDE`(2.20E1, 7) `r4`, 0.1 * 0.2 `r5`, 1E-1 * 2E-1 `r6`, 0.1 + 0.2 `r7`, 1E-1 +"
+ " 2E-1 `r8`, 0.06 - 0.01 `r9`, 6E-2 - 1E-2 `r10`, `DIVIDE`(0.1, 0.3) * 0.3 `r11`,"
+ " `DIVIDE`(1E-1, 3E-1) * 3E-1 `r12`, POWER(POWER(2.0, 5E-1), 2) `r13`,"
+ " POWER(POWER(2.0E0, 5E-1), 2) `r14`, `DIVIDE`(7.0, 0) `r15`, `DIVIDE`(7, 0.0)"
"SELECT DIVIDE(22, 7.0) `r1`, DIVIDE(22, 7.0E0) `r2`, DIVIDE(22.0, 7) `r3`,"
+ " DIVIDE(2.20E1, 7) `r4`, 0.1 * 0.2 `r5`, 1E-1 * 2E-1 `r6`, 0.1 + 0.2 `r7`, 1E-1 +"
+ " 2E-1 `r8`, 0.06 - 0.01 `r9`, 6E-2 - 1E-2 `r10`, DIVIDE(0.1, 0.3) * 0.3 `r11`,"
+ " DIVIDE(1E-1, 3E-1) * 3E-1 `r12`, POWER(POWER(2.0, 5E-1), 2) `r13`,"
+ " POWER(POWER(2.0E0, 5E-1), 2) `r14`, DIVIDE(7.0, 0) `r15`, DIVIDE(7, 0.0)"
+ " `r16`\n"
+ "FROM `scott`.`EMP`\n"
+ "LIMIT 1";
Expand Down
Loading
Loading