From 0c02bf75d7ec9d33dacd08aa7e0890d0ae07d922 Mon Sep 17 00:00:00 2001 From: dnini Date: Fri, 22 Nov 2024 12:30:53 +0200 Subject: [PATCH] [CALCITE-6702] Strong Policy for the POWER Function is wrong --- .../src/main/java/org/apache/calcite/plan/Strong.java | 1 + .../java/org/apache/calcite/sql/SqlBasicFunction.java | 11 +++++++++++ .../src/main/java/org/apache/calcite/sql/SqlKind.java | 3 +++ .../apache/calcite/sql/fun/SqlStdOperatorTable.java | 2 +- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/apache/calcite/plan/Strong.java b/core/src/main/java/org/apache/calcite/plan/Strong.java index 3c8be238f087..272187e28590 100644 --- a/core/src/main/java/org/apache/calcite/plan/Strong.java +++ b/core/src/main/java/org/apache/calcite/plan/Strong.java @@ -336,6 +336,7 @@ private static Map 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 diff --git a/core/src/main/java/org/apache/calcite/sql/SqlBasicFunction.java b/core/src/main/java/org/apache/calcite/sql/SqlBasicFunction.java index 980df24d4e8b..1b40ef4eca6a 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlBasicFunction.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlBasicFunction.java @@ -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}. */ diff --git a/core/src/main/java/org/apache/calcite/sql/SqlKind.java b/core/src/main/java/org/apache/calcite/sql/SqlKind.java index 03a0178f0564..aa91babbd56a 100644 --- a/core/src/main/java/org/apache/calcite/sql/SqlKind.java +++ b/core/src/main/java/org/apache/calcite/sql/SqlKind.java @@ -319,6 +319,9 @@ public enum SqlKind { */ PATTERN_CONCAT, + /** Exponentiation. **/ + POWER, + // comparison operators /** {@code IN} operator. */ diff --git a/core/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java b/core/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java index 0258f75d0bf3..33abac720b62 100644 --- a/core/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java +++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java @@ -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);