Skip to content

Commit

Permalink
[CALCITE-5931] Allow round decimals like 1.00 in window ranges
Browse files Browse the repository at this point in the history
Co-authored-by: xiejiajun <[email protected]>
  • Loading branch information
arkanovicz and JiajunBernoulli committed Sep 10, 2023
1 parent 7176860 commit d4046d0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/src/main/java/org/apache/calcite/sql/SqlWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
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;
Expand Down Expand Up @@ -691,7 +692,8 @@ private static void validateFrameBoundary(
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3356,6 +3356,9 @@ void testWinPartClause() {
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 --
// -----------------------------------
Expand Down
21 changes: 21 additions & 0 deletions core/src/test/resources/sql/winagg.iq
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d4046d0

Please sign in to comment.