Skip to content

Commit 155eb2c

Browse files
authored
Add scalar min/max to BuiltinFunctionName (#4967) (#4971)
(cherry picked from commit 7dfabce) Signed-off-by: Lantao Jin <ltjin@amazon.com>
1 parent 5d6f021 commit 155eb2c

4 files changed

Lines changed: 14 additions & 7 deletions

File tree

core/src/main/java/org/opensearch/sql/calcite/CalciteRelNodeVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2920,7 +2920,7 @@ private RelNode rankByColumnSplit(
29202920
*/
29212921
private AggCall buildAggCall(RelBuilder relBuilder, String aggFunctionName, RexNode node) {
29222922
BuiltinFunctionName aggFunction =
2923-
BuiltinFunctionName.of(aggFunctionName)
2923+
BuiltinFunctionName.ofAggregation(aggFunctionName)
29242924
.orElseThrow(
29252925
() ->
29262926
new IllegalArgumentException(

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public enum BuiltinFunctionName {
5858
SIN(FunctionName.of("sin")),
5959
TAN(FunctionName.of("tan")),
6060
SPAN(FunctionName.of("span")),
61+
SCALAR_MAX(FunctionName.of("scalar_max")),
62+
SCALAR_MIN(FunctionName.of("scalar_min")),
6163

6264
/** Binning Functions. */
6365
SPAN_BUCKET(FunctionName.of("span_bucket")),

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@
185185
import static org.opensearch.sql.expression.function.BuiltinFunctionName.RINT;
186186
import static org.opensearch.sql.expression.function.BuiltinFunctionName.ROUND;
187187
import static org.opensearch.sql.expression.function.BuiltinFunctionName.RTRIM;
188+
import static org.opensearch.sql.expression.function.BuiltinFunctionName.SCALAR_MAX;
189+
import static org.opensearch.sql.expression.function.BuiltinFunctionName.SCALAR_MIN;
188190
import static org.opensearch.sql.expression.function.BuiltinFunctionName.SECOND;
189191
import static org.opensearch.sql.expression.function.BuiltinFunctionName.SECOND_OF_MINUTE;
190192
import static org.opensearch.sql.expression.function.BuiltinFunctionName.SEC_TO_TIME;
@@ -876,9 +878,9 @@ void populate() {
876878
registerOperator(INTERNAL_REGEXP_REPLACE_5, SqlLibraryOperators.REGEXP_REPLACE_5);
877879
registerOperator(INTERNAL_TRANSLATE3, SqlLibraryOperators.TRANSLATE3);
878880

879-
// Register eval functions for PPL max() and min() calls
880-
registerOperator(MAX, PPLBuiltinOperators.SCALAR_MAX);
881-
registerOperator(MIN, PPLBuiltinOperators.SCALAR_MIN);
881+
// Register eval functions for PPL scalar max() and min() calls
882+
registerOperator(SCALAR_MAX, PPLBuiltinOperators.SCALAR_MAX);
883+
registerOperator(SCALAR_MIN, PPLBuiltinOperators.SCALAR_MIN);
882884

883885
// Register PPL UDF operator
884886
registerOperator(COSH, PPLBuiltinOperators.COSH);

ppl/src/main/java/org/opensearch/sql/ppl/parser/AstExpressionBuilder.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,15 @@ public class AstExpressionBuilder extends OpenSearchPPLParserBaseVisitor<Unresol
8282

8383
private static final int DEFAULT_TAKE_FUNCTION_SIZE_VALUE = 10;
8484

85-
/** The function name mapping between fronted and core engine. */
86-
private static Map<String, String> FUNCTION_NAME_MAPPING =
85+
/** The eval function name mapping between fronted and core engine. */
86+
private static final Map<String, String> EVAL_FUNCTION_NAME_MAPPING =
8787
new ImmutableMap.Builder<String, String>()
8888
.put("isnull", IS_NULL.getName().getFunctionName())
8989
.put("isnotnull", IS_NOT_NULL.getName().getFunctionName())
9090
.put("regex_match", REGEXP_MATCH.getName().getFunctionName()) // compatible with old one
9191
.put("regexp_replace", REPLACE.getName().getFunctionName())
92+
.put("max", SCALAR_MAX.getName().getFunctionName()) // this is scalar max
93+
.put("min", SCALAR_MIN.getName().getFunctionName()) // this is scalar min
9294
.build();
9395

9496
private final AstBuilder astBuilder;
@@ -439,7 +441,8 @@ public UnresolvedExpression visitCaseFunctionCall(
439441
public UnresolvedExpression visitEvalFunctionCall(EvalFunctionCallContext ctx) {
440442
final String functionName = ctx.evalFunctionName().getText();
441443
final String mappedName =
442-
FUNCTION_NAME_MAPPING.getOrDefault(functionName.toLowerCase(Locale.ROOT), functionName);
444+
EVAL_FUNCTION_NAME_MAPPING.getOrDefault(
445+
functionName.toLowerCase(Locale.ROOT), functionName);
443446

444447
// Rewrite sum and avg functions to arithmetic expressions
445448
if (SUM.getName().getFunctionName().equalsIgnoreCase(mappedName)

0 commit comments

Comments
 (0)