Skip to content

Commit 3662ec4

Browse files
Fix function identify problem in converting to sql dialect (#4793) (#4807)
(cherry picked from commit 3a91e5c) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 15845d9 commit 3662ec4

32 files changed

+196
-177
lines changed

core/src/main/java/org/opensearch/sql/expression/function/PPLBuiltinOperators.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@
9898
import org.opensearch.sql.expression.function.udf.math.ConvFunction;
9999
import org.opensearch.sql.expression.function.udf.math.DivideFunction;
100100
import org.opensearch.sql.expression.function.udf.math.EulerFunction;
101-
import org.opensearch.sql.expression.function.udf.math.MaxFunction;
102-
import org.opensearch.sql.expression.function.udf.math.MinFunction;
103101
import org.opensearch.sql.expression.function.udf.math.ModFunction;
104102
import org.opensearch.sql.expression.function.udf.math.NumberToStringFunction;
103+
import org.opensearch.sql.expression.function.udf.math.ScalarMaxFunction;
104+
import org.opensearch.sql.expression.function.udf.math.ScalarMinFunction;
105105

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

137137
public static final SqlOperator COSH =
138138
adaptMathFunctionToUDF(

core/src/main/java/org/opensearch/sql/expression/function/PPLFuncImpTable.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -859,8 +859,8 @@ void populate() {
859859
registerOperator(INTERNAL_TRANSLATE3, SqlLibraryOperators.TRANSLATE3);
860860

861861
// Register eval functions for PPL max() and min() calls
862-
registerOperator(MAX, PPLBuiltinOperators.MAX);
863-
registerOperator(MIN, PPLBuiltinOperators.MIN);
862+
registerOperator(MAX, PPLBuiltinOperators.SCALAR_MAX);
863+
registerOperator(MIN, PPLBuiltinOperators.SCALAR_MIN);
864864

865865
// Register PPL UDF operator
866866
registerOperator(COSH, PPLBuiltinOperators.COSH);

core/src/main/java/org/opensearch/sql/expression/function/UserDefinedFunctionBuilder.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ default SqlUserDefinedFunction toUDF(String functionName, boolean isDeterministi
5959
public boolean isDeterministic() {
6060
return isDeterministic;
6161
}
62+
63+
@Override
64+
public SqlIdentifier getSqlIdentifier() {
65+
// to avoid convert to sql dialog as identifier, use keyword instead
66+
// check the code SqlUtil.unparseFunctionSyntax()
67+
return null;
68+
}
6269
};
6370
}
6471
}

core/src/main/java/org/opensearch/sql/expression/function/udf/math/MaxFunction.java renamed to core/src/main/java/org/opensearch/sql/expression/function/udf/math/ScalarMaxFunction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
* MAX(value1, value2, ...) returns the maximum value from the arguments. For mixed types, strings
2525
* have higher precedence than numbers.
2626
*/
27-
public class MaxFunction extends ImplementorUDF {
27+
public class ScalarMaxFunction extends ImplementorUDF {
2828

29-
public MaxFunction() {
29+
public ScalarMaxFunction() {
3030
super(new MaxImplementor(), NullPolicy.ALL);
3131
}
3232

core/src/main/java/org/opensearch/sql/expression/function/udf/math/MinFunction.java renamed to core/src/main/java/org/opensearch/sql/expression/function/udf/math/ScalarMinFunction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
* MIN(value1, value2, ...) returns the minimum value from the arguments. For mixed types, numbers
2525
* have higher precedence than strings.
2626
*/
27-
public class MinFunction extends ImplementorUDF {
27+
public class ScalarMinFunction extends ImplementorUDF {
2828

29-
public MinFunction() {
29+
public ScalarMinFunction() {
3030
super(new MinImplementor(), NullPolicy.ALL);
3131
}
3232

integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteExplainIT.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,19 +1300,19 @@ public void testExplainSortOnMeasureMultiBucketsNotMultiTermsNotPushDown() throw
13001300

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

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

integ-test/src/test/resources/expectedOutput/calcite/explain_eval_max.json

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
calcite:
2+
logical: |
3+
LogicalSystemLimit(fetch=[10000], type=[QUERY_SIZE_LIMIT])
4+
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)])
5+
CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])
6+
physical: |
7+
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])
8+
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)])

integ-test/src/test/resources/expectedOutput/calcite/explain_eval_min.json

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
calcite:
2+
logical: |
3+
LogicalSystemLimit(fetch=[10000], type=[QUERY_SIZE_LIMIT])
4+
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)])
5+
CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])
6+
physical: |
7+
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])
8+
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)])

0 commit comments

Comments
 (0)