Skip to content

Commit

Permalink
[CALCITE-6702]: Strong Policy for the POWER Function is wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
ninidhiaeddine committed Nov 22, 2024
1 parent b635174 commit b8e4875
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions core/src/main/java/org/apache/calcite/plan/Strong.java
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ private static Map<SqlKind, Policy> createPolicyMap() {
map.put(SqlKind.TIMESTAMP_ADD, Policy.ANY);
map.put(SqlKind.TIMESTAMP_DIFF, Policy.ANY);
map.put(SqlKind.ITEM, Policy.ANY);
map.put(SqlKind.POWER, Policy.ANY);

// Assume that any other expressions cannot be simplified.
for (SqlKind k
Expand Down
11 changes: 11 additions & 0 deletions core/src/main/java/org/apache/calcite/sql/SqlBasicFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ public static SqlBasicFunction create(SqlKind kind,
SqlFunctionCategory.SYSTEM, call -> SqlMonotonicity.NOT_MONOTONIC, false);
}

/** Creates a {@code SqlBasicFunction} whose name is the same as its kind */
public static SqlBasicFunction create(SqlKind kind,
SqlReturnTypeInference returnTypeInference,
SqlOperandTypeChecker operandTypeChecker,
SqlFunctionCategory category) {
return new SqlBasicFunction(kind.name(), kind,
SqlSyntax.FUNCTION, true, returnTypeInference, null,
OperandHandlers.DEFAULT, operandTypeChecker, 0,
category, call -> SqlMonotonicity.NOT_MONOTONIC, false);
}

/** Creates a {@code SqlBasicFunction}
* with kind {@link SqlKind#OTHER_FUNCTION}
* and category {@link SqlFunctionCategory#NUMERIC}. */
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/org/apache/calcite/sql/SqlKind.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ public enum SqlKind {
*/
PATTERN_CONCAT,

/** Exponentiation **/
POWER,

// comparison operators

/** {@code IN} operator. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1700,7 +1700,7 @@ public class SqlStdOperatorTable extends ReflectiveSqlOperatorTable {
* second operand is negative.
*/
public static final SqlBasicFunction POWER =
SqlBasicFunction.create("POWER",
SqlBasicFunction.create(SqlKind.POWER,
ReturnTypes.DOUBLE_NULLABLE,
OperandTypes.NUMERIC_NUMERIC,
SqlFunctionCategory.NUMERIC);
Expand Down

0 comments on commit b8e4875

Please sign in to comment.