Skip to content

Commit

Permalink
[CALCITE-6282] Avatica ignores time precision when returning TIME res…
Browse files Browse the repository at this point in the history
…ults

Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
  • Loading branch information
mihaibudiu committed Mar 29, 2024
1 parent d5b6b5c commit 0d21496
Show file tree
Hide file tree
Showing 5 changed files with 204 additions and 196 deletions.
14 changes: 8 additions & 6 deletions core/src/main/java/org/apache/calcite/util/Bug.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,6 @@ public abstract class Bug {
*/
public static final boolean FRG254_FIXED = false;

/**
* Whether <a href="http://issues.eigenbase.org/browse/FRG-282">issue
* FRG-282: Support precision in TIME and TIMESTAMP data types</a> is fixed.
*/
public static final boolean FRG282_FIXED = false;

/**
* Whether <a href="http://issues.eigenbase.org/browse/FRG-296">issue
* FRG-296: SUBSTRING(string FROM regexp FOR regexp)</a> is fixed.
Expand Down Expand Up @@ -211,6 +205,14 @@ public abstract class Bug {
*/
public static final boolean TODO_FIXED = false;

/** Whether
* <a href="https://issues.apache.org/jira/browse/CALCITE-6282">[CALCITE-6282]
* Avatica ignores time precision when returning TIME results</a> is fixed.
* This should be removed once the bug is fixed in Avatica, and
* Calcite switches to the most recent version of Avatica.
* This is expected to be fixed in Avatica 1.25.0. */
public static final boolean CALCITE_6282_FIXED = false;

/**
* Use this method to flag temporary code.
*
Expand Down
25 changes: 15 additions & 10 deletions core/src/test/resources/sql/misc.iq
Original file line number Diff line number Diff line change
Expand Up @@ -2136,6 +2136,7 @@ EnumerableAggregate(group=[{}], C=[COUNT()])
EnumerableValues(tuples=[[]])
!plan

!if (fixed.calcite6828) {
# [CALCITE-1659] Simplifying CAST('YYYY-MM-DD hh:mm:ss.SSS' as TIMESTAMP)
# should round the sub-second fraction
select TIMESTAMP '2016-02-26 19:06:00.123456789',
Expand All @@ -2146,33 +2147,37 @@ select TIMESTAMP '2016-02-26 19:06:00.123456789',
CAST('2016-02-26 19:06:00.123' as TIMESTAMP(3)),
CAST('2016-02-26 19:06:00.123' as TIMESTAMP(6)),
CAST('2016-02-26 19:06:00.123' as TIMESTAMP(9));
+---------------------+---------------------+---------------------+---------------------+---------------------+---------------------+---------------------+---------------------+
| EXPR$0 | EXPR$1 | EXPR$2 | EXPR$3 | EXPR$4 | EXPR$5 | EXPR$6 | EXPR$7 |
+---------------------+---------------------+---------------------+---------------------+---------------------+---------------------+---------------------+---------------------+
| 2016-02-26 19:06:00 | 2016-02-26 19:06:00 | 2016-02-26 19:06:00 | 2016-02-26 19:06:00 | 2016-02-26 19:06:00 | 2016-02-26 19:06:00 | 2016-02-26 19:06:00 | 2016-02-26 19:06:00 |
+---------------------+---------------------+---------------------+---------------------+---------------------+---------------------+---------------------+---------------------+
+-------------------------+---------------------+---------------------+-----------------------+------------------------+-------------------------+-------------------------+-------------------------+
| EXPR$0 | EXPR$1 | EXPR$2 | EXPR$3 | EXPR$4 | EXPR$5 | EXPR$6 | EXPR$7 |
+-------------------------+---------------------+---------------------+-----------------------+------------------------+-------------------------+-------------------------+-------------------------+
| 2016-02-26 19:06:00.123 | 2016-02-26 19:06:00 | 2016-02-26 19:06:00 | 2016-02-26 19:06:00.1 | 2016-02-26 19:06:00.12 | 2016-02-26 19:06:00.123 | 2016-02-26 19:06:00.123 | 2016-02-26 19:06:00.123 |
+-------------------------+---------------------+---------------------+-----------------------+------------------------+-------------------------+-------------------------+-------------------------+
(1 row)

!ok
EnumerableValues(tuples=[[{ 2016-02-26 19:06:00.123, 2016-02-26 19:06:00, 2016-02-26 19:06:00, 2016-02-26 19:06:00.1, 2016-02-26 19:06:00.12, 2016-02-26 19:06:00.123, 2016-02-26 19:06:00.123, 2016-02-26 19:06:00.123 }]])
!plan

!}

!if (fixed.calcite6828) {
# [CALCITE-1664] CAST('<string>' as TIMESTAMP) adds part of sub-second fraction to the value
select
TIMESTAMP '2016-02-26 19:06:00.12345678',
CAST('2016-02-26 19:06:00.12345678' as TIMESTAMP),
TIMESTAMPDIFF(SECOND,
TIMESTAMP '2016-02-26 19:06:00.123456789',
CAST('2016-02-26 19:06:00.123456789' as TIMESTAMP));
+---------------------+---------------------+--------+
| EXPR$0 | EXPR$1 | EXPR$2 |
+---------------------+---------------------+--------+
| 2016-02-26 19:06:00 | 2016-02-26 19:06:00 | 0 |
+---------------------+---------------------+--------+
+-------------------------+---------------------+--------+
| EXPR$0 | EXPR$1 | EXPR$2 |
+-------------------------+---------------------+--------+
| 2016-02-26 19:06:00.123 | 2016-02-26 19:06:00 | 0 |
+-------------------------+---------------------+--------+
(1 row)

!ok

!}
# TIMESTAMPDIFF with 'flag' literal as time unit argument
SELECT TIMESTAMPDIFF(quarter, TIMESTAMP '2008-12-25', TIMESTAMP '2008-09-25');
+--------+
Expand Down
16 changes: 9 additions & 7 deletions core/src/test/resources/sql/operator.iq
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ order by 1,2;

!ok

!if (fixed.calcite6828) {
# FLOOR and CEIL of TIME
select v,
case when b then 'ceil' else 'floor' end as op,
Expand All @@ -235,16 +236,17 @@ select v,
from (values (time '12:34:56.7')) as t(v),
(values false, true) as u(b)
order by 1,2;
+----------+-------+----------+----------+----------+----------+----------+----------+----------+----------+
| V | OP | Y | Q | M | W | D | H | MI | S |
+----------+-------+----------+----------+----------+----------+----------+----------+----------+----------+
| 12:34:56 | ceil | 12:34:57 | 12:34:56 | 12:34:56 | 12:34:56 | 12:34:56 | 13:00:00 | 12:35:00 | 12:34:57 |
| 12:34:56 | floor | 12:34:56 | 12:34:56 | 12:34:56 | 12:34:56 | 12:34:56 | 12:00:00 | 12:34:00 | 12:34:56 |
+----------+-------+----------+----------+----------+----------+----------+----------+----------+----------+
+------------+-------+------------+------------+------------+------------+------------+------------+------------+------------+
| V | OP | Y | Q | M | W | D | H | MI | S |
+------------+-------+------------+------------+------------+------------+------------+------------+------------+------------+
| 12:34:56.7 | ceil | 12:34:57.0 | 12:34:56.7 | 12:34:56.7 | 12:34:56.7 | 12:34:56.7 | 13:00:00.0 | 12:35:00.0 | 12:34:57.0 |
| 12:34:56.7 | floor | 12:34:56.6 | 12:34:56.6 | 12:34:56.6 | 12:34:56.6 | 12:34:56.7 | 12:00:00.0 | 12:34:00.0 | 12:34:56.0 |
+------------+-------+------------+------------+------------+------------+------------+------------+------------+------------+
(2 rows)

!ok

!}

select "T"."X"[1] as x1 from (VALUES (ROW(ROW(3, 7), ROW(4, 8)))) as T(x, y);

X1 INTEGER(10) NOT NULL
Expand Down
Loading

0 comments on commit 0d21496

Please sign in to comment.