Skip to content

Commit

Permalink
IGNITE-23278 SQL Calcite: Fix incorrect error with TIMESTAMP WITH TIM…
Browse files Browse the repository at this point in the history
…E ZONE type - Fixes #11566.

Signed-off-by: Aleksey Plekhanov <plehanov.alex@gmail.com>
  • Loading branch information
Vladsz83 authored and alex-plekhanov committed Oct 4, 2024
1 parent 2eebf5f commit 6648f8d
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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;
Expand All @@ -42,12 +43,23 @@
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);
Expand Down Expand Up @@ -345,6 +357,35 @@ private boolean allEquals(List<RelDataType> types) {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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;
Expand Down Expand Up @@ -351,6 +352,28 @@ public void testBinarySql() {
}
}

/** */
@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() {
Expand Down

0 comments on commit 6648f8d

Please sign in to comment.