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