Skip to content

Commit

Permalink
show caican how to return null values
Browse files Browse the repository at this point in the history
  • Loading branch information
tanclary committed Feb 23, 2024
1 parent 0e04e4f commit c573824
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2794,9 +2794,9 @@ public static double log(BigDecimal d0, BigDecimal d1) {
}

/** SQL {@code LOG2(number)} function applied to
* BigDecimal and double values. */
* BigDecimal values. */
public static @Nullable Double log2(BigDecimal d0) {
return (d0.doubleValue() < 0.0 || d0.doubleValue() == 0.0) ? null : log(d0, 2);
return log2(d0.doubleValue());
}

// MOD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2157,7 +2157,7 @@ private static RelDataType deriveTypeMapFromEntries(SqlOperatorBinding opBinding
@LibraryOperator(libraries = {MYSQL, SPARK})
public static final SqlFunction LOG2 =
SqlBasicFunction.create("LOG2",
ReturnTypes.DOUBLE_NULLABLE,
ReturnTypes.DOUBLE_FORCE_NULLABLE,
OperandTypes.NUMERIC,
SqlFunctionCategory.NUMERIC);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,13 @@ public static SqlCall stripSeparator(SqlCall call) {
public static final SqlReturnTypeInference DOUBLE_NULLABLE =
DOUBLE.andThen(SqlTypeTransforms.TO_NULLABLE);

/**
* Type-inference strategy whereby the result type of a call is a nullable
* Double.
*/
public static final SqlReturnTypeInference DOUBLE_FORCE_NULLABLE =
DOUBLE.andThen(SqlTypeTransforms.FORCE_NULLABLE);

/**
* Type-inference strategy whereby the result type of a call is a Char.
*/
Expand Down

0 comments on commit c573824

Please sign in to comment.