Skip to content

Commit 6286e90

Browse files
committed
Remove EnhancedCoalesceFunction in favor of built-in Coalesce function (1913/2054)
- numbers are allowed to be coerced to strings Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent 23e611a commit 6286e90

4 files changed

Lines changed: 31 additions & 115 deletions

File tree

core/src/main/java/org/opensearch/sql/calcite/validate/PplTypeCoercionRule.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,31 @@
1717
import org.apache.calcite.sql.type.SqlTypeCoercionRule;
1818
import org.apache.calcite.sql.type.SqlTypeName;
1919

20+
/**
21+
* Provides PPL-specific type coercion rules that extend Calcite's default type coercion behavior.
22+
*
23+
* <p>This class defines additional type mapping rules for PPL, particularly for handling custom
24+
* types like IP addresses and number-to-string coercion. These additional rules are merged with
25+
* Calcite's built-in type coercion rules.
26+
*
27+
* <p>The additional mappings defined include:
28+
*
29+
* <ul>
30+
* <li>IP can be coerced to/from string types
31+
* <li>VARCHAR can be coerced from numeric types
32+
* </ul>
33+
*
34+
* <p>Three variants of type coercion rules are provided:
35+
*
36+
* <ul>
37+
* <li>{@link #instance()} - Standard type coercion rules
38+
* <li>{@link #lenientInstance()} - More permissive type coercion rules
39+
* <li>{@link #assignmentInstance()} - Rules for type assignment validation
40+
* </ul>
41+
*
42+
* @see SqlTypeCoercionRule
43+
* @see PplTypeCoercion
44+
*/
2045
public class PplTypeCoercionRule {
2146
/**
2247
* PPL-specific additional type mapping rules
@@ -25,14 +50,18 @@ public class PplTypeCoercionRule {
2550
* <li>IP -> IP
2651
* <li>CHARACTER -> IP
2752
* <li>IP -> CHARACTER
53+
* <li>NUMBER -> VARCHAR
2854
* </ul>
2955
*/
3056
private static final Map<SqlTypeName, ImmutableSet<@NonNull SqlTypeName>> additionalMapping =
3157
Map.of(
3258
SqlTypeName.OTHER,
3359
ImmutableSet.of(SqlTypeName.OTHER, SqlTypeName.VARCHAR, SqlTypeName.CHAR),
3460
SqlTypeName.VARCHAR,
35-
ImmutableSet.of(SqlTypeName.OTHER),
61+
ImmutableSet.<SqlTypeName>builder()
62+
.add(SqlTypeName.OTHER)
63+
.addAll(SqlTypeName.NUMERIC_TYPES)
64+
.build(),
3665
SqlTypeName.CHAR,
3766
ImmutableSet.of(SqlTypeName.OTHER));
3867

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
import org.opensearch.sql.expression.function.udf.ToNumberFunction;
8181
import org.opensearch.sql.expression.function.udf.ToStringFunction;
8282
import org.opensearch.sql.expression.function.udf.condition.EarliestFunction;
83-
import org.opensearch.sql.expression.function.udf.condition.EnhancedCoalesceFunction;
8483
import org.opensearch.sql.expression.function.udf.condition.LatestFunction;
8584
import org.opensearch.sql.expression.function.udf.datetime.AddSubDateFunction;
8685
import org.opensearch.sql.expression.function.udf.datetime.CurrentFunction;
@@ -488,9 +487,6 @@ public class PPLBuiltinOperators extends ReflectiveSqlOperatorTable {
488487
PPLReturnTypes.STRING_ARRAY,
489488
PPLOperandTypes.ANY_SCALAR_OPTIONAL_INTEGER);
490489

491-
public static final SqlFunction ENHANCED_COALESCE =
492-
new EnhancedCoalesceFunction().toUDF("COALESCE");
493-
494490
public static final SqlFunction ATAN =
495491
new SqlFunction(
496492
"ATAN",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ void populate() {
829829
registerOperator(IFNULL, SqlStdOperatorTable.COALESCE);
830830
registerOperator(EARLIEST, PPLBuiltinOperators.EARLIEST);
831831
registerOperator(LATEST, PPLBuiltinOperators.LATEST);
832-
registerOperator(COALESCE, PPLBuiltinOperators.ENHANCED_COALESCE);
832+
registerOperator(COALESCE, SqlStdOperatorTable.COALESCE);
833833

834834
// Register library operator
835835
registerOperator(REGEXP, PPLBuiltinOperators.REGEXP);

core/src/main/java/org/opensearch/sql/expression/function/udf/condition/EnhancedCoalesceFunction.java

Lines changed: 0 additions & 109 deletions
This file was deleted.

0 commit comments

Comments
 (0)