|
278 | 278 | import org.apache.logging.log4j.LogManager; |
279 | 279 | import org.apache.logging.log4j.Logger; |
280 | 280 | import org.opensearch.sql.calcite.CalcitePlanContext; |
| 281 | +import org.opensearch.sql.calcite.utils.OpenSearchTypeFactory; |
281 | 282 | import org.opensearch.sql.calcite.utils.PPLOperandTypes; |
282 | 283 | import org.opensearch.sql.calcite.utils.PlanUtils; |
283 | 284 | import org.opensearch.sql.calcite.utils.UserDefinedFunctionUtils; |
@@ -721,9 +722,6 @@ void populate() { |
721 | 722 | registerOperator(AND, SqlStdOperatorTable.AND); |
722 | 723 | registerOperator(OR, SqlStdOperatorTable.OR); |
723 | 724 | registerOperator(NOT, SqlStdOperatorTable.NOT); |
724 | | - |
725 | | - // Register ADDFUNCTION for numeric addition only |
726 | | - registerOperator(ADDFUNCTION, SqlStdOperatorTable.PLUS); |
727 | 725 | registerOperator(SUBTRACTFUNCTION, SqlStdOperatorTable.MINUS, OperandTypes.NUMERIC_NUMERIC); |
728 | 726 | registerOperator(SUBTRACT, SqlStdOperatorTable.MINUS, OperandTypes.NUMERIC_NUMERIC); |
729 | 727 | // Add DATETIME-DATETIME variant for timestamp binning support |
@@ -1057,19 +1055,18 @@ void populate() { |
1057 | 1055 | registerOperator(JSON_EXTRACT_ALL, PPLBuiltinOperators.JSON_EXTRACT_ALL); // internal |
1058 | 1056 |
|
1059 | 1057 | // Register operators with a different type checker |
1060 | | - |
1061 | | - // Register ADD (+ symbol) for string concatenation |
1062 | | - // Replaced type checker since CONCAT also supports array concatenation |
1063 | | - // registerOperator( |
1064 | | - // ADD, |
1065 | | - // SqlStdOperatorTable.CONCAT, |
1066 | | - // OperandTypes.family(SqlTypeFamily.CHARACTER, SqlTypeFamily.CHARACTER)); |
1067 | | - // Register ADD (+ symbol) for numeric addition |
1068 | | - // Replace type checker since PLUS also supports binary addition |
1069 | | - registerOperator( |
1070 | | - ADD, |
1071 | | - SqlStdOperatorTable.PLUS, |
1072 | | - OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC)); |
| 1058 | + // Register ADD (+ symbol) for string concatenation and numeric addition |
| 1059 | + // Not creating PPL builtin operator as it will cause confusion during function resolution |
| 1060 | + FunctionImp add = |
| 1061 | + (builder, args) -> { |
| 1062 | + SqlOperator op = |
| 1063 | + (Stream.of(args).map(RexNode::getType).anyMatch(OpenSearchTypeFactory::isCharacter)) |
| 1064 | + ? SqlStdOperatorTable.CONCAT |
| 1065 | + : SqlStdOperatorTable.PLUS; |
| 1066 | + return builder.makeCall(op, args); |
| 1067 | + }; |
| 1068 | + register(ADD, add, SqlStdOperatorTable.PLUS.getOperandTypeChecker()); |
| 1069 | + register(ADDFUNCTION, add, SqlStdOperatorTable.PLUS.getOperandTypeChecker()); |
1073 | 1070 | // Replace with a custom CompositeOperandTypeChecker to check both operands as |
1074 | 1071 | // SqlStdOperatorTable.ITEM.getOperandTypeChecker() checks only the first |
1075 | 1072 | // operand instead |
|
0 commit comments