You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by li...@apache.org on 2022/12/03 12:11:00 UTC

[calcite] branch main updated: [CALCITE-5410] Assertion error on PERCENT_REMAINDER operator with DECIMAL type

This is an automated email from the ASF dual-hosted git repository.

libenchao 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 33ca193095 [CALCITE-5410] Assertion error on PERCENT_REMAINDER operator with DECIMAL type
33ca193095 is described below

commit 33ca193095fcd0db46b88a270bca8d8cd569b31a
Author: Aleksey Plekhanov <pl...@gmail.com>
AuthorDate: Thu Dec 1 11:00:19 2022 +0300

    [CALCITE-5410] Assertion error on PERCENT_REMAINDER operator with DECIMAL type
---
 babel/src/test/resources/sql/select.iq                      | 13 +++++++++++++
 .../org/apache/calcite/sql/fun/SqlStdOperatorTable.java     |  2 +-
 .../test/java/org/apache/calcite/test/SqlValidatorTest.java |  6 ++++++
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/babel/src/test/resources/sql/select.iq b/babel/src/test/resources/sql/select.iq
index 07399eb7da..1b6f40bdce 100755
--- a/babel/src/test/resources/sql/select.iq
+++ b/babel/src/test/resources/sql/select.iq
@@ -60,4 +60,17 @@ select(...)
 !explain-validated-on mysql8+ oracle
 !}
 
+# [CALCITE-5410] Assertion error on PERCENT_REMAINDER operator with DECIMAL type
+
+select 1.0 % 2;
+
++--------+
+| EXPR$0 |
++--------+
+|    1.0 |
++--------+
+(1 row)
+
+!ok
+
 # End select.iq
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 7c602aa7b1..e51e72b4bf 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
@@ -301,7 +301,7 @@ public class SqlStdOperatorTable extends ReflectiveSqlOperatorTable {
           SqlKind.MOD,
           60,
           true,
-          ReturnTypes.ARG1_NULLABLE,
+          ReturnTypes.NULLABLE_MOD,
           null,
           OperandTypes.EXACT_NUMERIC_EXACT_NUMERIC);
 
diff --git a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
index 5709ccc0de..de742d4fd1 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
@@ -501,6 +501,12 @@ public class SqlValidatorTest extends SqlValidatorTestCase {
 
     expr("mod(5.1, 3)").ok();
     expr("mod(2,5.1)").ok();
+    expr("5.1 % 3")
+        .withConformance(SqlConformanceEnum.LENIENT)
+        .columnType("DECIMAL(2, 1) NOT NULL");
+    expr("2 % 5.1")
+        .withConformance(SqlConformanceEnum.LENIENT)
+        .columnType("DECIMAL(2, 1) NOT NULL");
     expr("exp(3.67)").ok();
   }