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

jiajunxie 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 d4046d0274 [CALCITE-5931] Allow round decimals like 1.00 in window 
ranges
d4046d0274 is described below

commit d4046d027450bb792481fae46af76719d562c904
Author: Claude Brisson <[email protected]>
AuthorDate: Tue Aug 15 15:50:32 2023 +0200

    [CALCITE-5931] Allow round decimals like 1.00 in window ranges
    
    Co-authored-by: xiejiajun <[email protected]>
---
 .../main/java/org/apache/calcite/sql/SqlWindow.java |  4 +++-
 .../org/apache/calcite/test/SqlValidatorTest.java   |  3 +++
 core/src/test/resources/sql/winagg.iq               | 21 +++++++++++++++++++++
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/calcite/sql/SqlWindow.java 
b/core/src/main/java/org/apache/calcite/sql/SqlWindow.java
index 198b9961c3..28cca4fb0b 100644
--- a/core/src/main/java/org/apache/calcite/sql/SqlWindow.java
+++ b/core/src/main/java/org/apache/calcite/sql/SqlWindow.java
@@ -39,6 +39,7 @@ import 
org.checkerframework.checker.nullness.qual.EnsuresNonNullIf;
 import org.checkerframework.checker.nullness.qual.Nullable;
 import org.checkerframework.dataflow.qual.Pure;
 
+import java.math.BigDecimal;
 import java.util.List;
 
 import static org.apache.calcite.linq4j.Nullness.castNonNull;
@@ -691,7 +692,8 @@ public class SqlWindow extends SqlCall {
           final SqlNumericLiteral boundLiteral =
               (SqlNumericLiteral) boundVal;
           if (!boundLiteral.isExact()
-              || (boundLiteral.getScale() != null && boundLiteral.getScale() 
!= 0)
+              || (boundLiteral.getScale() != null
+                && 
boundLiteral.getValueAs(BigDecimal.class).stripTrailingZeros().scale() > 0)
               || (0 > boundLiteral.longValue(true))) {
             // true == throw if not exact (we just tested that - right?)
             throw validator.newValidationError(boundVal,
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 1b2149e37f..150dbdf785 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java
@@ -3356,6 +3356,9 @@ public class SqlValidatorTest extends 
SqlValidatorTestCase {
     win("window w as (rows ^2.5^ preceding)")
         .fails("ROWS value must be a non-negative integral constant");
 
+    // CALCITE-5931 - Allow integers like 1.00 in window frame
+    win("window w as (rows 2.00 preceding)").ok();
+
     // -----------------------------------
     // --   negative testings           --
     // -----------------------------------
diff --git a/core/src/test/resources/sql/winagg.iq 
b/core/src/test/resources/sql/winagg.iq
index e6228a3966..7304a00382 100644
--- a/core/src/test/resources/sql/winagg.iq
+++ b/core/src/test/resources/sql/winagg.iq
@@ -98,6 +98,27 @@ order by 1;
 
 !ok
 
+# [CALCITE-5931] Allow integers like 1.00 in window frame
+select empno,
+  stddev(comm) over (order by empno rows 2 preceding) as stdev_2int,
+  stddev(comm) over (order by empno rows 2.00 preceding) as stdev_2double
+from emp
+where deptno = 30
+order by 1;
++-------+-------------------------------------------------+-------------------------------------------------+
+| EMPNO | STDEV_2INT                                      | STDEV_2DOUBLE      
                             |
++-------+-------------------------------------------------+-------------------------------------------------+
+|  7499 |                                                 |                    
                             |
+|  7521 |  141.421356237309510106570087373256683349609375 |  
141.421356237309510106570087373256683349609375 |
+|  7654 | 585.9465277082316561063635163009166717529296875 | 
585.9465277082316561063635163009166717529296875 |
+|  7698 | 636.3961030678927954795653931796550750732421875 | 
636.3961030678927954795653931796550750732421875 |
+|  7844 |  989.949493661166570745990611612796783447265625 |  
989.949493661166570745990611612796783447265625 |
+|  7900 |                                                 |                    
                             |
++-------+-------------------------------------------------+-------------------------------------------------+
+(6 rows)
+
+!ok
+
 !use post
 # [CALCITE-1540] Support multiple columns in PARTITION BY clause of window 
function
 select gender,deptno,

Reply via email to