Skip to content

Commit

Permalink
KE-11534 keep ifnull operator rather than convert to case when
Browse files Browse the repository at this point in the history
  • Loading branch information
pfzhan committed Mar 26, 2024
1 parent 31a6a2f commit 9e2671f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private StandardConvertletTable() {
SqlStdOperatorTable.IS_NOT_NULL);
addAlias(SqlLibraryOperators.NULL_SAFE_EQUAL, SqlStdOperatorTable.IS_NOT_DISTINCT_FROM);
addAlias(SqlStdOperatorTable.PERCENT_REMAINDER, SqlStdOperatorTable.MOD);
addAlias(SqlLibraryOperators.IFNULL, SqlLibraryOperators.NVL);
// addAlias(SqlLibraryOperators.IFNULL, SqlLibraryOperators.NVL); // kylin IFNULL ≠ NVL for cc

// Register convertlets for specific objects.
registerOp(SqlStdOperatorTable.CAST, this::convertCast);
Expand Down Expand Up @@ -166,6 +166,7 @@ private StandardConvertletTable() {
registerOp(SqlLibraryOperators.DECODE,
StandardConvertletTable::convertDecode);
registerOp(SqlLibraryOperators.IF, StandardConvertletTable::convertIf);
registerOp(SqlLibraryOperators.IFNULL, StandardConvertletTable::convertIfNull);

// Expand "x NOT LIKE y" into "NOT (x LIKE y)"
registerOp(SqlStdOperatorTable.NOT_LIKE,
Expand Down Expand Up @@ -326,6 +327,20 @@ private static RexNode convertNvl(SqlRexContext cx, SqlCall call) {
));
}

/** Converts a call to the IfNull function. */
private static RexNode convertIfNull(SqlRexContext cx, SqlCall call) {
final RexBuilder rexBuilder = cx.getRexBuilder();
final RexNode operand0 =
cx.convertExpression(call.getOperandList().get(0));
final RexNode operand1 =
cx.convertExpression(call.getOperandList().get(1));
final RelDataType type =
cx.getValidator().getValidatedNodeType(call);
// Preserve Operand Nullability
return rexBuilder.makeCall(type, SqlLibraryOperators.IFNULL,
ImmutableList.of(operand0, operand1));
}

/** Converts a call to the DECODE function. */
private static RexNode convertDecode(SqlRexContext cx, SqlCall call) {
final RexBuilder rexBuilder = cx.getRexBuilder();
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ systemProp.org.gradle.internal.publish.checksums.insecure=true
# This is version for Calcite itself
# Note: it should not include "-SNAPSHOT" as it is automatically added by build.gradle.kts
# Release version can be generated by using -Prelease or -Prc=<int> arguments
calcite.version=1.30.0-kylin-4.x-r04
calcite.version=1.30.0-kylin-4.x-r05
# This is a version to be used from Maven repository. It can be overridden by localAvatica below
calcite.avatica.version=1.20.0

Expand Down

0 comments on commit 9e2671f

Please sign in to comment.