This is an automated email from the ASF dual-hosted git repository.
xiong pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/main by this push:
new 0a96bee854 [CALCITE-6713] NVL2's return data type should be nullable
if and only if at least one of the second and third parameters are nullable
0a96bee854 is described below
commit 0a96bee8549020cb11d8c320f6c9c0e0581cbafb
Author: Xiong Duan <[email protected]>
AuthorDate: Sun Dec 1 09:46:14 2024 +0800
[CALCITE-6713] NVL2's return data type should be nullable if and only if at
least one of the second and third parameters are nullable
---
.../main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java | 3 +--
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java | 6 +++---
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git
a/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
b/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
index e8f044f3ac..b4f0a17d31 100644
--- a/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
+++ b/core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
@@ -303,8 +303,7 @@ public abstract class SqlLibraryOperators {
@LibraryOperator(libraries = {ORACLE, REDSHIFT, SPARK})
public static final SqlBasicFunction NVL2 =
SqlBasicFunction.create(SqlKind.NVL2,
- ReturnTypes.NVL2_RESTRICTIVE
- .andThen(SqlTypeTransforms.TO_NULLABLE_ALL),
+ ReturnTypes.NVL2_RESTRICTIVE,
OperandTypes.SECOND_THIRD_SAME);
/** The "IFNULL(value, value)" function. */
diff --git a/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
b/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
index aacc5f8955..9c0cd589c1 100644
--- a/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
+++ b/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
@@ -11692,9 +11692,9 @@ public class SqlOperatorTest {
f12.checkScalar("NVL2(NULL, 3.0, 2.111)", "2.111", "DECIMAL(4, 3) NOT
NULL");
f12.checkScalar("NVL2(3.111, 3.1415926, 2.111)", "3.1415926",
"DECIMAL(8, 7) NOT NULL");
- f12.checkNull("nvl2('ab', CAST(NULL AS VARCHAR(6)), 'def')");
- f12.checkNull("nvl2(NULL, 'abc', NULL)");
- f12.checkNull("nvl2(NULL, NULL, NULL)");
+ f12.checkNullValueWithNullableType("nvl2('ab', CAST(NULL AS VARCHAR(6)),
'def')");
+ f12.checkNullValueWithNullableType("nvl2(NULL, 'abc', NULL)");
+ f12.checkNullValueWithNullableType("nvl2(NULL, NULL, NULL)");
f12.checkFails("^NVL2(2.0, 2.0, true)^", "Parameters must be of the same
type", false);
f12.checkFails("^NVL2(NULL, 2.0, true)^", "Parameters must be of the
same type", false);