You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by pp...@apache.org on 2025/03/27 11:50:26 UTC

(ignite-3) branch main updated: IGNITE-24835 Sql. Forbid use of TIMESTAMP_TZ at parser level (#5490)

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

ppa pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new fd7c76abf7e IGNITE-24835 Sql. Forbid use of TIMESTAMP_TZ at parser level (#5490)
fd7c76abf7e is described below

commit fd7c76abf7e19c11063010cf44c08fc38f0ce8d8
Author: Pavel Pereslegin <xx...@gmail.com>
AuthorDate: Thu Mar 27 14:50:22 2025 +0300

    IGNITE-24835 Sql. Forbid use of TIMESTAMP_TZ at parser level (#5490)
---
 .../sql/group1/types/time/test_time.test           | 33 +++++++++++-----------
 .../sql/group1/types/timestamp/test_timestamp.test | 30 ++++++++++----------
 .../src/main/codegen/includes/parserImpls.ftl      | 16 +++++++++--
 .../internal/sql/engine/sql/SqlDdlParserTest.java  | 30 ++++++++++++++++----
 4 files changed, 70 insertions(+), 39 deletions(-)

diff --git a/modules/sql-engine/src/integrationTest/sql/group1/types/time/test_time.test b/modules/sql-engine/src/integrationTest/sql/group1/types/time/test_time.test
index 3e4cb2a6b17..97390a3336e 100644
--- a/modules/sql-engine/src/integrationTest/sql/group1/types/time/test_time.test
+++ b/modules/sql-engine/src/integrationTest/sql/group1/types/time/test_time.test
@@ -6,26 +6,25 @@ statement ok
 PRAGMA enable_verification
 
 statement ok
-CREATE TABLE times(i TIME(3))
+CREATE TABLE times(t1 TIME(3), t2 TIME(3) WITHOUT TIME ZONE)
 
 statement ok
-INSERT INTO times VALUES (time '00:01:20'), (time '20:08:10.998'), (time '20:08:10.33'), (time '20:08:10.001'), (NULL)
+INSERT INTO times VALUES (time '00:01:20', time '00:01:20'), (time '20:08:10.998', time '20:08:10.998'), (time '20:08:10.33', time '20:08:10.33'), (time '20:08:10.001', time '20:08:10.001'), (NULL, NULL)
 
-query T rowsort
-SELECT * FROM times
+query TT
+SELECT * FROM times ORDER by t1
 ----
-00:01:20
-20:08:10.001
-20:08:10.33
-20:08:10.998
-NULL
+00:01:20	00:01:20
+20:08:10.001	20:08:10.001
+20:08:10.33	20:08:10.33
+20:08:10.998	20:08:10.998
+NULL	NULL
 
-query T rowsort
-SELECT cast(i AS VARCHAR) FROM times
+query TT
+SELECT cast(t1 AS VARCHAR), cast(t2 AS VARCHAR) FROM times ORDER by t1
 ----
-00:01:20
-20:08:10.001
-20:08:10.33
-20:08:10.998
-NULL
-
+00:01:20	00:01:20
+20:08:10.001	20:08:10.001
+20:08:10.33	20:08:10.33
+20:08:10.998	20:08:10.998
+NULL	NULL
diff --git a/modules/sql-engine/src/integrationTest/sql/group1/types/timestamp/test_timestamp.test b/modules/sql-engine/src/integrationTest/sql/group1/types/timestamp/test_timestamp.test
index 326d32cb62c..1192c52c0eb 100644
--- a/modules/sql-engine/src/integrationTest/sql/group1/types/timestamp/test_timestamp.test
+++ b/modules/sql-engine/src/integrationTest/sql/group1/types/timestamp/test_timestamp.test
@@ -6,10 +6,10 @@ statement ok
 PRAGMA enable_verification
 
 statement ok
-CREATE TABLE IF NOT EXISTS timestamp_t (t TIMESTAMP);
+CREATE TABLE IF NOT EXISTS timestamp_t (t TIMESTAMP, t2 TIMESTAMP(1) WITHOUT TIME ZONE);
 
 statement ok
-INSERT INTO timestamp_t VALUES (timestamp '2008-01-01 00:00:01'), (NULL), (timestamp '2007-01-01 00:00:01'), (timestamp '2008-02-01 00:00:01'), (timestamp '2008-01-02 00:00:01'), (timestamp '2008-01-01 10:00:00'), (timestamp '2008-01-01 00:10:00'), (timestamp '2008-01-01 00:00:10')
+INSERT INTO timestamp_t VALUES (timestamp '2008-01-01 00:00:01', timestamp '2008-01-01 00:00:01'), (NULL, NULL), (timestamp '2007-01-01 00:00:01.999', timestamp '2007-01-01 00:00:01.999'), (timestamp '2008-02-01 00:00:01', timestamp '2008-02-01 00:00:01'), (timestamp '2008-01-02 00:00:01', timestamp '2008-01-02 00:00:01'), (timestamp '2008-01-01 10:00:00', timestamp '2008-01-01 10:00:00'), (timestamp '2008-01-01 00:10:00', timestamp '2008-01-01 00:10:00'), (timestamp '2008-01-01 00:00:10 [...]
 
 query T
 SELECT timestamp '2017-07-23 13:10:11';
@@ -43,22 +43,22 @@ SELECT timestamp 'AA2017-07-23 13:10:11';
 statement error: Illegal TIMESTAMP literal
 SELECT timestamp '2017-07-23A13:10:11';
 
-query T
-SELECT t FROM timestamp_t ORDER BY t;
-----
-2007-01-01 00:00:01
-2008-01-01 00:00:01
-2008-01-01 00:00:10
-2008-01-01 00:10:00
-2008-01-01 10:00:00
-2008-01-02 00:00:01
-2008-02-01 00:00:01
-NULL
+query TTT
+SELECT t, t2, t=t2 FROM timestamp_t ORDER BY t;
+----
+2007-01-01 00:00:01.999	2007-01-01 00:00:01.9	false
+2008-01-01 00:00:01	2008-01-01 00:00:01	true
+2008-01-01 00:00:10	2008-01-01 00:00:10	true
+2008-01-01 00:10:00	2008-01-01 00:10:00	true
+2008-01-01 10:00:00	2008-01-01 10:00:00	true
+2008-01-02 00:00:01	2008-01-02 00:00:01	true
+2008-02-01 00:00:01	2008-02-01 00:00:01	true
+NULL	NULL	NULL
 
 query T
 SELECT MIN(t) FROM timestamp_t;
 ----
-2007-01-01 00:00:01
+2007-01-01 00:00:01.999
 
 query T
 SELECT MAX(t) FROM timestamp_t;
@@ -125,7 +125,7 @@ SELECT t::DATE FROM timestamp_t WHERE EXTRACT(YEAR from t)=2007 ORDER BY 1
 query T
 SELECT t::TIME FROM timestamp_t WHERE EXTRACT(YEAR from t)=2007 ORDER BY 1
 ----
-00:00:01
+00:00:01.999
 
 query T
 SELECT (DATE '1992-01-01')::TIMESTAMP;
diff --git a/modules/sql-engine/src/main/codegen/includes/parserImpls.ftl b/modules/sql-engine/src/main/codegen/includes/parserImpls.ftl
index 05c20e56a2c..8dc21a8d21e 100644
--- a/modules/sql-engine/src/main/codegen/includes/parserImpls.ftl
+++ b/modules/sql-engine/src/main/codegen/includes/parserImpls.ftl
@@ -658,7 +658,7 @@ void AlterZoneOption(List<SqlNode> list) :
 /**
 * Parse datetime types: date, time, timestamp.
 *
-* TODO Method doesn't recognize 'TIME_WITH_LOCAL_TIME_ZONE' type and should be removed after IGNITE-21555.
+* TODO Method doesn't recognize TIME_WITH_LOCAL_TIME_ZONE, TIME_TZ and TIMESTAMP_TZ types and should be removed after IGNITE-21555.
 */
 SqlTypeNameSpec IgniteDateTimeTypeName() :
 {
@@ -675,6 +675,7 @@ SqlTypeNameSpec IgniteDateTimeTypeName() :
 |
     <TIME> { s = span(); }
     precision = PrecisionOpt()
+    (<WITHOUT> <TIME> <ZONE>)?
     {
         typeName = SqlTypeName.TIME;
         return new SqlBasicTypeNameSpec(typeName, precision, s.end(this));
@@ -682,12 +683,23 @@ SqlTypeNameSpec IgniteDateTimeTypeName() :
 |
     <TIMESTAMP> { s = span(); }
     precision = PrecisionOpt()
-    typeName = TimeZoneOpt(false)
+    typeName = TimestampZoneOpt()
     {
         return new SqlBasicTypeNameSpec(typeName, precision, s.end(this));
     }
 }
 
+SqlTypeName TimestampZoneOpt() :
+{
+}
+{
+    <WITHOUT> <TIME> <ZONE> { return SqlTypeName.TIMESTAMP; }
+|
+    <WITH> <LOCAL> <TIME> <ZONE> { return SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE; }
+|
+    { return SqlTypeName.TIMESTAMP; }
+}
+
 SqlNode SqlStartTransaction() :
 {
     final Span s;
diff --git a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/sql/SqlDdlParserTest.java b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/sql/SqlDdlParserTest.java
index 56bc303565e..53aad8684a9 100644
--- a/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/sql/SqlDdlParserTest.java
+++ b/modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/sql/SqlDdlParserTest.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.internal.sql.engine.sql;
 
 import static java.util.Collections.singleton;
+import static org.apache.ignite.internal.lang.IgniteStringFormatter.format;
 import static org.apache.ignite.internal.sql.engine.util.SqlTestUtils.assertThrowsSqlException;
 import static org.hamcrest.CoreMatchers.hasItem;
 import static org.hamcrest.CoreMatchers.instanceOf;
@@ -43,12 +44,14 @@ import org.apache.calcite.sql.SqlNode;
 import org.apache.calcite.sql.SqlNumericLiteral;
 import org.apache.calcite.sql.SqlUnknownLiteral;
 import org.apache.calcite.sql.ddl.SqlColumnDeclaration;
+import org.apache.calcite.sql.type.SqlTypeName;
 import org.apache.ignite.lang.ErrorGroups.Sql;
 import org.hamcrest.CustomMatcher;
 import org.hamcrest.Matcher;
 import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
 import org.junit.jupiter.params.provider.ValueSource;
 
 /**
@@ -767,15 +770,32 @@ public class SqlDdlParserTest extends AbstractParserTest {
     }
 
     /**
-     * Ensures that the user cannot use the TIME_WITH_LOCAL_TIME_ZONE and TIMESTAMP_WITH_LOCAL_TIME_ZONE types for table columns.
+     * Ensures that the parser throws the expected exception when attempting to use the following unsupported types for table columns.
+     *
+     * <ol>
+     *     <li>{@link SqlTypeName#TIME_TZ TIME WITH TIME ZONE}</li>
+     *     <li>{@link SqlTypeName#TIME_WITH_LOCAL_TIME_ZONE TIME WITH LOCAL TIME ZONE}</li>
+     *     <li>{@link SqlTypeName#TIMESTAMP_TZ TIMESTAMP WITH TIME ZONE}</li>
+     * </ol>
      */
     // TODO: Remove after https://issues.apache.org/jira/browse/IGNITE-21555 is implemented.
-    @Test
-    public void timeWithLocalTimeZoneIsNotSupported() {
+    @ParameterizedTest(name = "type={0}")
+    @CsvSource({
+            "TIME WITH TIME ZONE, Encountered \"WITH\"",
+            "TIME WITH LOCAL TIME ZONE, Encountered \"WITH\"",
+            "TIMESTAMP WITH TIME ZONE, Encountered \"TIME\""
+    })
+    public void unsupportedTimeZoneAwareTableColumnTypes(String typeName, String expectedError) {
+        assertThrowsSqlException(
+                Sql.STMT_PARSE_ERR,
+                expectedError,
+                () -> parse(format("CREATE TABLE test (ts {})", typeName))
+        );
+
         assertThrowsSqlException(
                 Sql.STMT_PARSE_ERR,
-                "Encountered \"WITH\"",
-                () -> parse("CREATE TABLE test (ts TIME WITH LOCAL TIME ZONE)")
+                expectedError,
+                () -> parse(format("ALTER TABLE test ADD COLUMN ts {}", typeName))
         );
     }