Skip to content

Commit bfc076d

Browse files
committed
[SQL] Align implementation of TIME and TIMESTAMP default precision with documentation
Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
1 parent 9bc368e commit bfc076d

File tree

6 files changed

+59
-5
lines changed

6 files changed

+59
-5
lines changed

docs.feldera.com/docs/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import TabItem from '@theme/TabItem';
1515

1616
## Unreleased
1717

18+
TIMESTAMP is now the same as TIMESTAMP(3); TIME is now the same as
19+
TIME(3) (the default precision has been changed from 0 to 3; the
20+
documentation always claimed that the precision is 3).
21+
1822
## 0.129.0
1923

2024
Values that are late in the NOW stream are no longer logged to the

python/tests/runtime_aggtest/illarg_tests/test_date_time_fn.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,8 +473,8 @@ def __init__(self):
473473
"doy": 580,
474474
"dow": 580,
475475
"hr": 13926,
476-
"min": 835560,
477-
"sec": 50133659,
476+
"min": 835561,
477+
"sec": 50133660,
478478
}
479479
]
480480
self.sql = """CREATE MATERIALIZED VIEW tsdiff_ts_legal AS SELECT

sql-to-dbsp-compiler/SQL-compiler/src/main/java/org/dbsp/sqlCompiler/compiler/frontend/calciteCompiler/SqlToRelCompiler.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,15 @@ public int getMaxPrecision(SqlTypeName typeName) {
350350
return super.getMaxPrecision(typeName);
351351
}
352352

353+
@Override
354+
public int getDefaultPrecision(SqlTypeName typeName) {
355+
if (typeName == SqlTypeName.TIMESTAMP)
356+
return 3;
357+
if (typeName == SqlTypeName.TIME)
358+
return 3;
359+
return super.getDefaultPrecision(typeName);
360+
}
361+
353362
@Override
354363
public boolean shouldConvertRaggedUnionTypesToVarying() { return true; }
355364
};

sql-to-dbsp-compiler/SQL-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql/MetadataTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,7 @@ CREATE TABLE T (
11831183
"case_sensitive" : false,
11841184
"columntype" : {
11851185
"nullable" : true,
1186-
"precision" : 0,
1186+
"precision" : 3,
11871187
"type" : "TIMESTAMP"
11881188
},
11891189
"lateness" : "INTERVAL '5 10:10' DAY TO MINUTE",

sql-to-dbsp-compiler/SQL-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql/simple/Regression1Tests.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,47 @@ NOT EXISTS (
244244
}
245245
}
246246

247+
@Test
248+
public void issue4562() {
249+
this.qs("""
250+
SELECT TIMESTAMPADD(MINUTE, 2, '2020-06-21 14:23:44.123'::TIMESTAMP);
251+
r
252+
---
253+
2020-06-21 14:25:44.123
254+
(1 row)""");
255+
}
256+
257+
@Test
258+
public void issue4650() {
259+
var ccs = this.getCCS("""
260+
CREATE TABLE t(tmestmp TIMESTAMP);
261+
262+
CREATE MATERIALIZED VIEW v AS SELECT
263+
TIMESTAMPDIFF(MINUTE, tmestmp, TIMESTAMP '2022-01-22 20:24:44.332') AS min,
264+
TIMESTAMPDIFF(SECOND, tmestmp, TIMESTAMP '2022-01-22 20:24:44.332') AS sec,
265+
TIMESTAMPDIFF(MINUTE, TIMESTAMP '2020-06-21 14:23:44.123', TIMESTAMP '2022-01-22 20:24:44.332') AS min1,
266+
TIMESTAMPDIFF(SECOND, TIMESTAMP '2020-06-21 14:23:44.123', TIMESTAMP '2022-01-22 20:24:44.332') AS sec1
267+
FROM t;""");
268+
ccs.step("INSERT INTO T VALUES(TIMESTAMP '2020-06-21 14:23:44.123');", """
269+
min | sec | min1 | sec1 | weight
270+
--------------------------------------------
271+
835561 | 50133660 | 835561 | 50133660 | 1""");
272+
273+
ccs = this.getCCS("""
274+
CREATE TABLE t(tmestmp TIMESTAMP);
275+
276+
CREATE MATERIALIZED VIEW v AS SELECT
277+
TIMESTAMPDIFF(MINUTE, tmestmp, '2022-01-22 20:24:44.332'::TIMESTAMP) AS min,
278+
TIMESTAMPDIFF(SECOND, tmestmp, '2022-01-22 20:24:44.332'::TIMESTAMP) AS sec,
279+
TIMESTAMPDIFF(MINUTE, '2020-06-21 14:23:44.123'::TIMESTAMP, '2022-01-22 20:24:44.332'::TIMESTAMP) AS min1,
280+
TIMESTAMPDIFF(SECOND, '2020-06-21 14:23:44.123'::TIMESTAMP, '2022-01-22 20:24:44.332'::TIMESTAMP) AS sec1
281+
FROM t;""");
282+
ccs.step("INSERT INTO T VALUES(TIMESTAMP '2020-06-21 14:23:44.123');", """
283+
min | sec | min1 | sec1 | weight
284+
--------------------------------------------
285+
835561 | 50133660 | 835561 | 50133660 | 1""");
286+
}
287+
247288
@Test
248289
public void issue4010() {
249290
this.getCCS("""
@@ -498,7 +539,7 @@ CREATE VIEW V AS SELECT CAST(x AS TIMESTAMP), CAST(10.20 AS TIMESTAMP),
498539
ccs.step("INSERT INTO T VALUES(10.20, 10)", """
499540
x | decimal | int | y | weight
500541
-----------------------------------------------------------------------------------------------
501-
1970-01-01 00:00:00 | 1970-01-01 00:00:00 | 1970-01-01 00:00:00 | 1970-01-01 00:00:00 |1""");
542+
1970-01-01 00:00:00 | 1970-01-01 00:00:00 | 1970-01-01 00:00:00.010 | 1970-01-01 00:00:00 |1""");
502543
}
503544

504545
@Test

sql-to-dbsp-compiler/SQL-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql/simple/TrigonometryTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ public void invalidInputs() {
11131113
);
11141114

11151115
this.queryFailingInCompilation("SELECT sin(CAST('15:06:51.06731' AS TIME))",
1116-
"Cannot apply 'SIN' to arguments of type 'SIN(<TIME(0)>)'. " +
1116+
"Cannot apply 'SIN' to arguments of type 'SIN(<TIME(3)>)'. " +
11171117
"Supported form(s): 'SIN(<NUMERIC>)'"
11181118
);
11191119
}

0 commit comments

Comments
 (0)