This is an automated email from the ASF dual-hosted git repository.
alexpl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new 6648f8dadd2 IGNITE-23278 SQL Calcite: Fix incorrect error with
TIMESTAMP WITH TIME ZONE type - Fixes #11566.
6648f8dadd2 is described below
commit 6648f8dadd2aa17dccb6979856925a6b5da6aaea
Author: Vladimir Steshin <[email protected]>
AuthorDate: Fri Oct 4 10:26:42 2024 +0300
IGNITE-23278 SQL Calcite: Fix incorrect error with TIMESTAMP WITH TIME ZONE
type - Fixes #11566.
Signed-off-by: Aleksey Plekhanov <[email protected]>
---
.../query/calcite/type/IgniteTypeFactory.java | 41 ++++++++++++++++++++++
.../query/calcite/integration/DataTypesTest.java | 23 ++++++++++++
2 files changed, 64 insertions(+)
diff --git
a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/type/IgniteTypeFactory.java
b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/type/IgniteTypeFactory.java
index 00de072af21..ab5f6f2a30c 100644
---
a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/type/IgniteTypeFactory.java
+++
b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/type/IgniteTypeFactory.java
@@ -27,6 +27,7 @@ import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Period;
+import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -42,12 +43,23 @@ import org.apache.calcite.sql.parser.SqlParserPos;
import org.apache.calcite.sql.type.BasicSqlType;
import org.apache.calcite.sql.type.IntervalSqlType;
import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.ignite.IgniteException;
import org.apache.ignite.internal.util.typedef.F;
/**
* Ignite type factory.
*/
public class IgniteTypeFactory extends JavaTypeFactoryImpl {
+ /** */
+ private static final EnumMap<SqlTypeName, String> UNSUPPORTED_TYPES = new
EnumMap<>(SqlTypeName.class);
+
+ static {
+ UNSUPPORTED_TYPES.put(SqlTypeName.TIME_TZ, "TIME WITH TIME ZONE");
+ UNSUPPORTED_TYPES.put(SqlTypeName.TIMESTAMP_TZ, "TIMESTAMP WITH TIME
ZONE");
+ UNSUPPORTED_TYPES.put(SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE,
"TIMESTAMP WITH LOCAL TIME ZONE");
+ UNSUPPORTED_TYPES.put(SqlTypeName.TIME_WITH_LOCAL_TIME_ZONE, "TIME
WITH LOCAL TIME ZONE");
+ }
+
/** Interval qualifier to create year-month interval types. */
private static final SqlIntervalQualifier INTERVAL_QUALIFIER_YEAR_MONTH =
new SqlIntervalQualifier(TimeUnit.YEAR,
TimeUnit.MONTH, SqlParserPos.ZERO);
@@ -345,6 +357,35 @@ public class IgniteTypeFactory extends JavaTypeFactoryImpl
{
return true;
}
+ /** {@inheritDoc} */
+ @Override public RelDataType createSqlType(SqlTypeName typeName) {
+ checkUnsupportedType(typeName);
+
+ return super.createSqlType(typeName);
+ }
+
+ /** {@inheritDoc} */
+ @Override public RelDataType createSqlType(SqlTypeName typeName, int
precision) {
+ checkUnsupportedType(typeName);
+
+ return super.createSqlType(typeName, precision);
+ }
+
+ /** {@inheritDoc} */
+ @Override public RelDataType createSqlType(SqlTypeName typeName, int
precision, int scale) {
+ checkUnsupportedType(typeName);
+
+ return super.createSqlType(typeName, precision, scale);
+ }
+
+ /** */
+ private static void checkUnsupportedType(SqlTypeName typeName) {
+ String unsupportedTypeName = UNSUPPORTED_TYPES.get(typeName);
+
+ if (unsupportedTypeName != null)
+ throw new IgniteException("Type '" + unsupportedTypeName + "' is
not supported.");
+ }
+
/** {@inheritDoc} */
@Override public RelDataType createUnknownType() {
// TODO workaround for
https://issues.apache.org/jira/browse/CALCITE-5297
diff --git
a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/DataTypesTest.java
b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/DataTypesTest.java
index c350fc2d80f..7a35de837ca 100644
---
a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/DataTypesTest.java
+++
b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/DataTypesTest.java
@@ -29,6 +29,7 @@ import org.apache.calcite.sql.type.SqlTypeName;
import org.apache.calcite.tools.FrameworkConfig;
import org.apache.calcite.tools.Frameworks;
import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteException;
import org.apache.ignite.cache.QueryEntity;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.internal.processors.query.IgniteSQLException;
@@ -351,6 +352,28 @@ public class DataTypesTest extends
AbstractBasicIntegrationTest {
}
}
+ /** */
+ @Test
+ public void testUnsupportedTypes() {
+ assertThrows("CREATE TABLE test (val TIME WITH TIME ZONE)",
IgniteException.class,
+ "'TIME WITH TIME ZONE' is not supported.");
+ assertThrows("CREATE TABLE test (val TIMESTAMP WITH TIME ZONE)",
IgniteException.class,
+ "'TIMESTAMP WITH TIME ZONE' is not supported.");
+ assertThrows("CREATE TABLE test (val TIME WITH LOCAL TIME ZONE)",
IgniteException.class,
+ "'TIME WITH LOCAL TIME ZONE' is not supported.");
+ assertThrows("CREATE TABLE test (val TIMESTAMP WITH LOCAL TIME ZONE)",
IgniteException.class,
+ "'TIMESTAMP WITH LOCAL TIME ZONE' is not supported.");
+
+ assertThrows("SELECT CAST (1 as TIME WITH TIME ZONE)",
IgniteException.class,
+ "'TIME WITH TIME ZONE' is not supported.");
+ assertThrows("SELECT CAST (1 as TIMESTAMP WITH TIME ZONE)",
IgniteException.class,
+ "'TIMESTAMP WITH TIME ZONE' is not supported.");
+ assertThrows("SELECT CAST (1 as TIME WITH LOCAL TIME ZONE)",
IgniteException.class,
+ "'TIME WITH LOCAL TIME ZONE' is not supported.");
+ assertThrows("SELECT CAST (1 as TIMESTAMP WITH LOCAL TIME ZONE)",
IgniteException.class,
+ "'TIMESTAMP WITH LOCAL TIME ZONE' is not supported.");
+ }
+
/** Cache API - SQL API cross check. */
@Test
public void testBinaryCache() {