From 21c7328d5e1c820e7c17b5c073a9dabfac1445ee Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Wed, 25 Jan 2023 17:50:14 +0100 Subject: [PATCH 1/4] Add temporal type constants and canonicalize Similar to `TimeType` in 3d0af3bb55b6de2fd493fa57307a5323f0fb9741. --- .../trino/spi/type/TimeWithTimeZoneType.java | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/core/trino-spi/src/main/java/io/trino/spi/type/TimeWithTimeZoneType.java b/core/trino-spi/src/main/java/io/trino/spi/type/TimeWithTimeZoneType.java index 0b27040581e..e3d0fbc706c 100644 --- a/core/trino-spi/src/main/java/io/trino/spi/type/TimeWithTimeZoneType.java +++ b/core/trino-spi/src/main/java/io/trino/spi/type/TimeWithTimeZoneType.java @@ -28,30 +28,35 @@ public abstract sealed class TimeWithTimeZoneType public static final int DEFAULT_PRECISION = 3; // TODO: should be 6 per SQL spec + private static final TimeWithTimeZoneType[] TYPES = new TimeWithTimeZoneType[MAX_PRECISION + 1]; + + static { + for (int precision = 0; precision <= MAX_PRECISION; precision++) { + TYPES[precision] = (precision <= MAX_SHORT_PRECISION) ? new ShortTimeWithTimeZoneType(precision) : new LongTimeWithTimeZoneType(precision); + } + } + + public static final TimeWithTimeZoneType TIME_TZ_SECONDS = createTimeWithTimeZoneType(0); + public static final TimeWithTimeZoneType TIME_TZ_MILLIS = createTimeWithTimeZoneType(3); + public static final TimeWithTimeZoneType TIME_TZ_MICROS = createTimeWithTimeZoneType(6); + public static final TimeWithTimeZoneType TIME_TZ_NANOS = createTimeWithTimeZoneType(9); + public static final TimeWithTimeZoneType TIME_TZ_PICOS = createTimeWithTimeZoneType(12); + /** * @deprecated Use {@link #createTimeWithTimeZoneType} instead. */ @Deprecated - public static final TimeWithTimeZoneType TIME_WITH_TIME_ZONE = new ShortTimeWithTimeZoneType(DEFAULT_PRECISION); + // Use singleton for backwards compatibility with code checking `type == TIME_WITH_TIME_ZONE` + public static final TimeWithTimeZoneType TIME_WITH_TIME_ZONE = TIME_TZ_MILLIS; private final int precision; public static TimeWithTimeZoneType createTimeWithTimeZoneType(int precision) { - if (precision == DEFAULT_PRECISION) { - // Use singleton for backwards compatibility with code checking `type == TIME_WITH_TIME_ZONE` - return TIME_WITH_TIME_ZONE; - } - if (precision < 0 || precision > MAX_PRECISION) { throw new TrinoException(NUMERIC_VALUE_OUT_OF_RANGE, format("TIME WITH TIME ZONE precision must be in range [0, %s]: %s", MAX_PRECISION, precision)); } - - if (precision <= MAX_SHORT_PRECISION) { - return new ShortTimeWithTimeZoneType(precision); - } - - return new LongTimeWithTimeZoneType(precision); + return TYPES[precision]; } protected TimeWithTimeZoneType(int precision, Class javaType) From 0ded89a0a1e1a9d8a11611c19a3194c0e86db0a2 Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Wed, 25 Jan 2023 17:59:41 +0100 Subject: [PATCH 2/4] Remove dangerous fallback handling of uknown type in Redis --- .../plugin/redis/decoder/hash/ISO8601HashRedisFieldDecoder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/trino-redis/src/main/java/io/trino/plugin/redis/decoder/hash/ISO8601HashRedisFieldDecoder.java b/plugin/trino-redis/src/main/java/io/trino/plugin/redis/decoder/hash/ISO8601HashRedisFieldDecoder.java index d7b089e7fc7..3ba8d60211a 100644 --- a/plugin/trino-redis/src/main/java/io/trino/plugin/redis/decoder/hash/ISO8601HashRedisFieldDecoder.java +++ b/plugin/trino-redis/src/main/java/io/trino/plugin/redis/decoder/hash/ISO8601HashRedisFieldDecoder.java @@ -76,7 +76,7 @@ public long getLong() return packDateTimeWithZone(millis, getTimeZoneKey(dateTime.getZone().getID())); } - return millis; + throw new IllegalStateException("Unsupported type: " + type); } } } From 6594ce451c8b89445657b0e851e119b83bf82fa2 Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Wed, 25 Jan 2023 17:56:42 +0100 Subject: [PATCH 3/4] Remove unnecessary code block The unsupported types are handled at the end of the `toWriteMapping` method. --- .../main/java/io/trino/plugin/phoenix5/PhoenixClient.java | 6 ------ .../main/java/io/trino/plugin/redshift/RedshiftClient.java | 2 ++ 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/plugin/trino-phoenix5/src/main/java/io/trino/plugin/phoenix5/PhoenixClient.java b/plugin/trino-phoenix5/src/main/java/io/trino/plugin/phoenix5/PhoenixClient.java index e448b6ca5a3..b772a8b4737 100644 --- a/plugin/trino-phoenix5/src/main/java/io/trino/plugin/phoenix5/PhoenixClient.java +++ b/plugin/trino-phoenix5/src/main/java/io/trino/plugin/phoenix5/PhoenixClient.java @@ -174,8 +174,6 @@ import static io.trino.spi.type.RealType.REAL; import static io.trino.spi.type.SmallintType.SMALLINT; import static io.trino.spi.type.TimeType.TIME_MILLIS; -import static io.trino.spi.type.TimeWithTimeZoneType.TIME_WITH_TIME_ZONE; -import static io.trino.spi.type.TimestampWithTimeZoneType.TIMESTAMP_TZ_MILLIS; import static io.trino.spi.type.TinyintType.TINYINT; import static io.trino.spi.type.VarcharType.createUnboundedVarcharType; import static java.lang.Math.max; @@ -548,10 +546,6 @@ public WriteMapping toWriteMapping(ConnectorSession session, Type type) if (TIME_MILLIS.equals(type)) { return WriteMapping.longMapping("time", timeWriteFunctionUsingSqlTime()); } - // Phoenix doesn't support _WITH_TIME_ZONE - if (TIME_WITH_TIME_ZONE.equals(type) || TIMESTAMP_TZ_MILLIS.equals(type)) { - throw new TrinoException(NOT_SUPPORTED, "Unsupported column type: " + type.getDisplayName()); - } if (type instanceof ArrayType arrayType) { Type elementType = arrayType.getElementType(); String elementDataType = toWriteMapping(session, elementType).getDataType().toUpperCase(ENGLISH); diff --git a/plugin/trino-redshift/src/main/java/io/trino/plugin/redshift/RedshiftClient.java b/plugin/trino-redshift/src/main/java/io/trino/plugin/redshift/RedshiftClient.java index 86abef905cf..61975c21a47 100644 --- a/plugin/trino-redshift/src/main/java/io/trino/plugin/redshift/RedshiftClient.java +++ b/plugin/trino-redshift/src/main/java/io/trino/plugin/redshift/RedshiftClient.java @@ -679,6 +679,8 @@ public WriteMapping toWriteMapping(ConnectorSession session, Type type) } // Fall back to legacy behavior + // TODO we should not fall back to legacy behavior, the mappings should be explicit (the legacyToWriteMapping + // is just a copy of some generic default mappings that used to exist) return legacyToWriteMapping(type); } From 1aaa2112988ccc90b8b4a526f9c667a5d9a86d99 Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Wed, 25 Jan 2023 17:54:43 +0100 Subject: [PATCH 4/4] Update usages of deprecated constant This isn't dissimilar to how we use constants in other temporal types. --- .../trino/jdbc/TestTrinoDatabaseMetaData.java | 2 +- .../sql/analyzer/ExpressionAnalyzer.java | 4 +-- .../trino/type/TestTimeWithTimeZoneType.java | 28 +++++++++---------- .../java/io/trino/type/TestTypeCoercion.java | 6 ++-- .../type/TimeWithTimeZoneParametricType.java | 2 +- .../AbstractDateTimeJsonValueProvider.java | 6 ++-- .../json/CustomDateTimeJsonFieldDecoder.java | 4 +-- .../decoder/json/ISO8601JsonFieldDecoder.java | 6 ++-- ...illisecondsSinceEpochJsonFieldDecoder.java | 4 +-- .../SecondsSinceEpochJsonFieldDecoder.java | 4 +-- .../TestCustomDateTimeJsonFieldDecoder.java | 12 ++++---- .../json/TestISO8601JsonFieldDecoder.java | 20 ++++++------- .../trino/decoder/json/TestJsonDecoder.java | 8 +++--- ...illisecondsSinceEpochJsonFieldDecoder.java | 14 +++++----- ...TestSecondsSinceEpochJsonFieldDecoder.java | 14 +++++----- .../kafka/encoder/json/JsonRowEncoder.java | 4 +-- .../json/format/CustomDateTimeFormatter.java | 4 +-- .../json/format/ISO8601DateTimeFormatter.java | 4 +-- .../plugin/kafka/TestKafkaConnectorTest.java | 6 ++-- .../kafka/encoder/json/TestJsonEncoder.java | 6 ++-- .../hash/ISO8601HashRedisFieldDecoder.java | 4 +-- .../trino/plugin/redis/util/RedisLoader.java | 4 +-- .../java/io/trino/testing/H2QueryRunner.java | 4 +-- 23 files changed, 85 insertions(+), 85 deletions(-) diff --git a/client/trino-jdbc/src/test/java/io/trino/jdbc/TestTrinoDatabaseMetaData.java b/client/trino-jdbc/src/test/java/io/trino/jdbc/TestTrinoDatabaseMetaData.java index 5677816e5ea..509e939a048 100644 --- a/client/trino-jdbc/src/test/java/io/trino/jdbc/TestTrinoDatabaseMetaData.java +++ b/client/trino-jdbc/src/test/java/io/trino/jdbc/TestTrinoDatabaseMetaData.java @@ -813,7 +813,7 @@ public void testGetColumns() assertColumnSpec(rs, Types.TIME, 15L, null, 6L, null, createTimeType(6)); assertColumnSpec(rs, Types.TIME, 18L, null, 9L, null, createTimeType(9)); assertColumnSpec(rs, Types.TIME, 21L, null, 12L, null, createTimeType(12)); - assertColumnSpec(rs, Types.TIME_WITH_TIMEZONE, 18L, null, 3L, null, TimeWithTimeZoneType.TIME_WITH_TIME_ZONE); + assertColumnSpec(rs, Types.TIME_WITH_TIMEZONE, 18L, null, 3L, null, TimeWithTimeZoneType.TIME_TZ_MILLIS); assertColumnSpec(rs, Types.TIME_WITH_TIMEZONE, 14L, null, 0L, null, createTimeWithTimeZoneType(0)); assertColumnSpec(rs, Types.TIME_WITH_TIMEZONE, 18L, null, 3L, null, createTimeWithTimeZoneType(3)); assertColumnSpec(rs, Types.TIME_WITH_TIMEZONE, 21L, null, 6L, null, createTimeWithTimeZoneType(6)); diff --git a/core/trino-main/src/main/java/io/trino/sql/analyzer/ExpressionAnalyzer.java b/core/trino-main/src/main/java/io/trino/sql/analyzer/ExpressionAnalyzer.java index 4a4924604e4..28bdf9a97af 100644 --- a/core/trino-main/src/main/java/io/trino/sql/analyzer/ExpressionAnalyzer.java +++ b/core/trino-main/src/main/java/io/trino/sql/analyzer/ExpressionAnalyzer.java @@ -226,7 +226,7 @@ import static io.trino.spi.type.SmallintType.SMALLINT; import static io.trino.spi.type.TimeType.TIME_MILLIS; import static io.trino.spi.type.TimeType.createTimeType; -import static io.trino.spi.type.TimeWithTimeZoneType.TIME_WITH_TIME_ZONE; +import static io.trino.spi.type.TimeWithTimeZoneType.TIME_TZ_MILLIS; import static io.trino.spi.type.TimeWithTimeZoneType.createTimeWithTimeZoneType; import static io.trino.spi.type.TimestampType.TIMESTAMP_MILLIS; import static io.trino.spi.type.TimestampType.createTimestampType; @@ -627,7 +627,7 @@ protected Type visitCurrentTime(CurrentTime node, StackableAstVisitorContext { if (node.getPrecision() != null) { diff --git a/core/trino-main/src/test/java/io/trino/type/TestTimeWithTimeZoneType.java b/core/trino-main/src/test/java/io/trino/type/TestTimeWithTimeZoneType.java index 042388c74b0..33566ff6906 100644 --- a/core/trino-main/src/test/java/io/trino/type/TestTimeWithTimeZoneType.java +++ b/core/trino-main/src/test/java/io/trino/type/TestTimeWithTimeZoneType.java @@ -20,30 +20,30 @@ import static io.trino.spi.type.DateTimeEncoding.packTimeWithTimeZone; import static io.trino.spi.type.DateTimeEncoding.unpackOffsetMinutes; import static io.trino.spi.type.DateTimeEncoding.unpackTimeNanos; -import static io.trino.spi.type.TimeWithTimeZoneType.TIME_WITH_TIME_ZONE; +import static io.trino.spi.type.TimeWithTimeZoneType.TIME_TZ_MILLIS; public class TestTimeWithTimeZoneType extends AbstractTestType { public TestTimeWithTimeZoneType() { - super(TIME_WITH_TIME_ZONE, SqlTimeWithTimeZone.class, createTestBlock()); + super(TIME_TZ_MILLIS, SqlTimeWithTimeZone.class, createTestBlock()); } public static Block createTestBlock() { - BlockBuilder blockBuilder = TIME_WITH_TIME_ZONE.createBlockBuilder(null, 15); - TIME_WITH_TIME_ZONE.writeLong(blockBuilder, packTimeWithTimeZone(1_111_000_000L, 0)); - TIME_WITH_TIME_ZONE.writeLong(blockBuilder, packTimeWithTimeZone(1_111_000_000L, 1)); - TIME_WITH_TIME_ZONE.writeLong(blockBuilder, packTimeWithTimeZone(1_111_000_000L, 2)); - TIME_WITH_TIME_ZONE.writeLong(blockBuilder, packTimeWithTimeZone(2_222_000_000L, 3)); - TIME_WITH_TIME_ZONE.writeLong(blockBuilder, packTimeWithTimeZone(2_222_000_000L, 4)); - TIME_WITH_TIME_ZONE.writeLong(blockBuilder, packTimeWithTimeZone(2_222_000_000L, 5)); - TIME_WITH_TIME_ZONE.writeLong(blockBuilder, packTimeWithTimeZone(2_222_000_000L, 6)); - TIME_WITH_TIME_ZONE.writeLong(blockBuilder, packTimeWithTimeZone(2_222_000_000L, 7)); - TIME_WITH_TIME_ZONE.writeLong(blockBuilder, packTimeWithTimeZone(3_333_000_000L, 8)); - TIME_WITH_TIME_ZONE.writeLong(blockBuilder, packTimeWithTimeZone(3_333_000_000L, 9)); - TIME_WITH_TIME_ZONE.writeLong(blockBuilder, packTimeWithTimeZone(4_444_000_000L, 10)); + BlockBuilder blockBuilder = TIME_TZ_MILLIS.createBlockBuilder(null, 15); + TIME_TZ_MILLIS.writeLong(blockBuilder, packTimeWithTimeZone(1_111_000_000L, 0)); + TIME_TZ_MILLIS.writeLong(blockBuilder, packTimeWithTimeZone(1_111_000_000L, 1)); + TIME_TZ_MILLIS.writeLong(blockBuilder, packTimeWithTimeZone(1_111_000_000L, 2)); + TIME_TZ_MILLIS.writeLong(blockBuilder, packTimeWithTimeZone(2_222_000_000L, 3)); + TIME_TZ_MILLIS.writeLong(blockBuilder, packTimeWithTimeZone(2_222_000_000L, 4)); + TIME_TZ_MILLIS.writeLong(blockBuilder, packTimeWithTimeZone(2_222_000_000L, 5)); + TIME_TZ_MILLIS.writeLong(blockBuilder, packTimeWithTimeZone(2_222_000_000L, 6)); + TIME_TZ_MILLIS.writeLong(blockBuilder, packTimeWithTimeZone(2_222_000_000L, 7)); + TIME_TZ_MILLIS.writeLong(blockBuilder, packTimeWithTimeZone(3_333_000_000L, 8)); + TIME_TZ_MILLIS.writeLong(blockBuilder, packTimeWithTimeZone(3_333_000_000L, 9)); + TIME_TZ_MILLIS.writeLong(blockBuilder, packTimeWithTimeZone(4_444_000_000L, 10)); return blockBuilder.build(); } diff --git a/core/trino-main/src/test/java/io/trino/type/TestTypeCoercion.java b/core/trino-main/src/test/java/io/trino/type/TestTypeCoercion.java index 40708bbaf5c..9ab2943c815 100644 --- a/core/trino-main/src/test/java/io/trino/type/TestTypeCoercion.java +++ b/core/trino-main/src/test/java/io/trino/type/TestTypeCoercion.java @@ -40,7 +40,7 @@ import static io.trino.spi.type.RowType.rowType; import static io.trino.spi.type.SmallintType.SMALLINT; import static io.trino.spi.type.TimeType.TIME_MILLIS; -import static io.trino.spi.type.TimeWithTimeZoneType.TIME_WITH_TIME_ZONE; +import static io.trino.spi.type.TimeWithTimeZoneType.TIME_TZ_MILLIS; import static io.trino.spi.type.TimestampType.TIMESTAMP_MILLIS; import static io.trino.spi.type.TimestampWithTimeZoneType.TIMESTAMP_TZ_MILLIS; import static io.trino.spi.type.TinyintType.TINYINT; @@ -126,7 +126,7 @@ public void testTypeCompatibility() assertThat(BIGINT, DOUBLE).hasCommonSuperType(DOUBLE).canCoerceFirstToSecondOnly(); assertThat(DATE, TIMESTAMP_MILLIS).hasCommonSuperType(TIMESTAMP_MILLIS).canCoerceFirstToSecondOnly(); assertThat(DATE, TIMESTAMP_TZ_MILLIS).hasCommonSuperType(TIMESTAMP_TZ_MILLIS).canCoerceFirstToSecondOnly(); - assertThat(TIME_MILLIS, TIME_WITH_TIME_ZONE).hasCommonSuperType(TIME_WITH_TIME_ZONE).canCoerceFirstToSecondOnly(); + assertThat(TIME_MILLIS, TIME_TZ_MILLIS).hasCommonSuperType(TIME_TZ_MILLIS).canCoerceFirstToSecondOnly(); assertThat(TIMESTAMP_MILLIS, TIMESTAMP_TZ_MILLIS).hasCommonSuperType(TIMESTAMP_TZ_MILLIS).canCoerceFirstToSecondOnly(); assertThat(VARCHAR, JONI_REGEXP).hasCommonSuperType(JONI_REGEXP).canCoerceFirstToSecondOnly(); assertThat(VARCHAR, re2jType).hasCommonSuperType(re2jType).canCoerceFirstToSecondOnly(); @@ -138,7 +138,7 @@ public void testTypeCompatibility() assertThat(REAL, INTEGER).hasCommonSuperType(REAL).canCoerceSecondToFirstOnly(); assertThat(REAL, BIGINT).hasCommonSuperType(REAL).canCoerceSecondToFirstOnly(); - assertThat(TIMESTAMP_MILLIS, TIME_WITH_TIME_ZONE).isIncompatible(); + assertThat(TIMESTAMP_MILLIS, TIME_TZ_MILLIS).isIncompatible(); assertThat(VARBINARY, VARCHAR).isIncompatible(); assertThat(UNKNOWN, new ArrayType(BIGINT)).hasCommonSuperType(new ArrayType(BIGINT)).canCoerceFirstToSecondOnly(); diff --git a/core/trino-spi/src/main/java/io/trino/spi/type/TimeWithTimeZoneParametricType.java b/core/trino-spi/src/main/java/io/trino/spi/type/TimeWithTimeZoneParametricType.java index 8f12fc6065e..701bfaab1eb 100644 --- a/core/trino-spi/src/main/java/io/trino/spi/type/TimeWithTimeZoneParametricType.java +++ b/core/trino-spi/src/main/java/io/trino/spi/type/TimeWithTimeZoneParametricType.java @@ -30,7 +30,7 @@ public String getName() public Type createType(TypeManager typeManager, List parameters) { if (parameters.isEmpty()) { - return TimeWithTimeZoneType.TIME_WITH_TIME_ZONE; + return TimeWithTimeZoneType.TIME_TZ_MILLIS; } if (parameters.size() != 1) { throw new IllegalArgumentException("Expected exactly one parameter for TIME WITH TIME ZONE"); diff --git a/lib/trino-record-decoder/src/main/java/io/trino/decoder/json/AbstractDateTimeJsonValueProvider.java b/lib/trino-record-decoder/src/main/java/io/trino/decoder/json/AbstractDateTimeJsonValueProvider.java index d016db84e37..b63bc4286f2 100644 --- a/lib/trino-record-decoder/src/main/java/io/trino/decoder/json/AbstractDateTimeJsonValueProvider.java +++ b/lib/trino-record-decoder/src/main/java/io/trino/decoder/json/AbstractDateTimeJsonValueProvider.java @@ -28,7 +28,7 @@ import static io.trino.spi.type.DateTimeEncoding.packTimeWithTimeZone; import static io.trino.spi.type.DateType.DATE; import static io.trino.spi.type.TimeType.TIME_MILLIS; -import static io.trino.spi.type.TimeWithTimeZoneType.TIME_WITH_TIME_ZONE; +import static io.trino.spi.type.TimeWithTimeZoneType.TIME_TZ_MILLIS; import static io.trino.spi.type.TimestampType.TIMESTAMP_MILLIS; import static io.trino.spi.type.TimestampWithTimeZoneType.TIMESTAMP_TZ_MILLIS; import static io.trino.spi.type.Timestamps.MICROSECONDS_PER_MILLISECOND; @@ -62,7 +62,7 @@ public final long getLong() Type type = columnHandle.getType(); - if (type.equals(TIME_MILLIS) || type.equals(TIME_WITH_TIME_ZONE)) { + if (type.equals(TIME_MILLIS) || type.equals(TIME_TZ_MILLIS)) { if (millis < 0 || millis >= TimeUnit.DAYS.toMillis(1)) { throw new TrinoException( DECODER_CONVERSION_NOT_SUPPORTED, @@ -82,7 +82,7 @@ public final long getLong() if (type.equals(TIMESTAMP_TZ_MILLIS)) { return packDateTimeWithZone(millis, getTimeZone()); } - if (type.equals(TIME_WITH_TIME_ZONE)) { + if (type.equals(TIME_TZ_MILLIS)) { int offsetMinutes = getTimeZone().getZoneId().getRules().getOffset(Instant.ofEpochMilli(millis)).getTotalSeconds() / 60; return packTimeWithTimeZone((millis + (offsetMinutes * 60 * MILLISECONDS_PER_SECOND)) * NANOSECONDS_PER_MILLISECOND, offsetMinutes); } diff --git a/lib/trino-record-decoder/src/main/java/io/trino/decoder/json/CustomDateTimeJsonFieldDecoder.java b/lib/trino-record-decoder/src/main/java/io/trino/decoder/json/CustomDateTimeJsonFieldDecoder.java index d9158c1e6e3..e2ee5c2fded 100644 --- a/lib/trino-record-decoder/src/main/java/io/trino/decoder/json/CustomDateTimeJsonFieldDecoder.java +++ b/lib/trino-record-decoder/src/main/java/io/trino/decoder/json/CustomDateTimeJsonFieldDecoder.java @@ -33,7 +33,7 @@ import static io.trino.spi.StandardErrorCode.GENERIC_USER_ERROR; import static io.trino.spi.type.DateType.DATE; import static io.trino.spi.type.TimeType.TIME_MILLIS; -import static io.trino.spi.type.TimeWithTimeZoneType.TIME_WITH_TIME_ZONE; +import static io.trino.spi.type.TimeWithTimeZoneType.TIME_TZ_MILLIS; import static io.trino.spi.type.TimeZoneKey.getTimeZoneKey; import static io.trino.spi.type.TimestampType.TIMESTAMP_MILLIS; import static io.trino.spi.type.TimestampWithTimeZoneType.TIMESTAMP_TZ_MILLIS; @@ -50,7 +50,7 @@ public class CustomDateTimeJsonFieldDecoder implements JsonFieldDecoder { - private static final Set SUPPORTED_TYPES = ImmutableSet.of(DATE, TIME_MILLIS, TIME_WITH_TIME_ZONE, TIMESTAMP_MILLIS, TIMESTAMP_TZ_MILLIS); + private static final Set SUPPORTED_TYPES = ImmutableSet.of(DATE, TIME_MILLIS, TIME_TZ_MILLIS, TIMESTAMP_MILLIS, TIMESTAMP_TZ_MILLIS); private final DecoderColumnHandle columnHandle; private final DateTimeFormatter formatter; diff --git a/lib/trino-record-decoder/src/main/java/io/trino/decoder/json/ISO8601JsonFieldDecoder.java b/lib/trino-record-decoder/src/main/java/io/trino/decoder/json/ISO8601JsonFieldDecoder.java index d27bbaa7390..9054fd75115 100644 --- a/lib/trino-record-decoder/src/main/java/io/trino/decoder/json/ISO8601JsonFieldDecoder.java +++ b/lib/trino-record-decoder/src/main/java/io/trino/decoder/json/ISO8601JsonFieldDecoder.java @@ -33,7 +33,7 @@ import static io.trino.spi.type.DateTimeEncoding.packTimeWithTimeZone; import static io.trino.spi.type.DateType.DATE; import static io.trino.spi.type.TimeType.TIME_MILLIS; -import static io.trino.spi.type.TimeWithTimeZoneType.TIME_WITH_TIME_ZONE; +import static io.trino.spi.type.TimeWithTimeZoneType.TIME_TZ_MILLIS; import static io.trino.spi.type.TimeZoneKey.getTimeZoneKey; import static io.trino.spi.type.TimestampType.TIMESTAMP_MILLIS; import static io.trino.spi.type.TimestampWithTimeZoneType.TIMESTAMP_TZ_MILLIS; @@ -60,7 +60,7 @@ public class ISO8601JsonFieldDecoder implements JsonFieldDecoder { - private static final Set SUPPORTED_TYPES = ImmutableSet.of(DATE, TIME_MILLIS, TIME_WITH_TIME_ZONE, TIMESTAMP_MILLIS, TIMESTAMP_TZ_MILLIS); + private static final Set SUPPORTED_TYPES = ImmutableSet.of(DATE, TIME_MILLIS, TIME_TZ_MILLIS, TIMESTAMP_MILLIS, TIMESTAMP_TZ_MILLIS); private final DecoderColumnHandle columnHandle; @@ -129,7 +129,7 @@ public long getLong() if (columnType.equals(TIME_MILLIS)) { return ISO_TIME.parse(textValue).getLong(MILLI_OF_DAY) * PICOSECONDS_PER_MILLISECOND; } - if (columnType.equals(TIME_WITH_TIME_ZONE)) { + if (columnType.equals(TIME_TZ_MILLIS)) { TemporalAccessor parseResult = ISO_OFFSET_TIME.parse(textValue); return packTimeWithTimeZone((long) (parseResult.get(MILLI_OF_DAY)) * NANOSECONDS_PER_MILLISECOND, ZoneOffset.from(parseResult).getTotalSeconds() / 60); } diff --git a/lib/trino-record-decoder/src/main/java/io/trino/decoder/json/MillisecondsSinceEpochJsonFieldDecoder.java b/lib/trino-record-decoder/src/main/java/io/trino/decoder/json/MillisecondsSinceEpochJsonFieldDecoder.java index 33ac8249f84..f30db8d441c 100644 --- a/lib/trino-record-decoder/src/main/java/io/trino/decoder/json/MillisecondsSinceEpochJsonFieldDecoder.java +++ b/lib/trino-record-decoder/src/main/java/io/trino/decoder/json/MillisecondsSinceEpochJsonFieldDecoder.java @@ -26,7 +26,7 @@ import static io.trino.decoder.DecoderErrorCode.DECODER_CONVERSION_NOT_SUPPORTED; import static io.trino.decoder.json.JsonRowDecoderFactory.throwUnsupportedColumnType; import static io.trino.spi.type.TimeType.TIME_MILLIS; -import static io.trino.spi.type.TimeWithTimeZoneType.TIME_WITH_TIME_ZONE; +import static io.trino.spi.type.TimeWithTimeZoneType.TIME_TZ_MILLIS; import static io.trino.spi.type.TimestampType.TIMESTAMP_MILLIS; import static io.trino.spi.type.TimestampWithTimeZoneType.TIMESTAMP_TZ_MILLIS; import static java.lang.Long.parseLong; @@ -41,7 +41,7 @@ public class MillisecondsSinceEpochJsonFieldDecoder implements JsonFieldDecoder { - private static final Set SUPPORTED_TYPES = ImmutableSet.of(TIME_MILLIS, TIME_WITH_TIME_ZONE, TIMESTAMP_MILLIS, TIMESTAMP_TZ_MILLIS); + private static final Set SUPPORTED_TYPES = ImmutableSet.of(TIME_MILLIS, TIME_TZ_MILLIS, TIMESTAMP_MILLIS, TIMESTAMP_TZ_MILLIS); private final DecoderColumnHandle columnHandle; diff --git a/lib/trino-record-decoder/src/main/java/io/trino/decoder/json/SecondsSinceEpochJsonFieldDecoder.java b/lib/trino-record-decoder/src/main/java/io/trino/decoder/json/SecondsSinceEpochJsonFieldDecoder.java index 1f39f1c1a55..31e29e0ab79 100644 --- a/lib/trino-record-decoder/src/main/java/io/trino/decoder/json/SecondsSinceEpochJsonFieldDecoder.java +++ b/lib/trino-record-decoder/src/main/java/io/trino/decoder/json/SecondsSinceEpochJsonFieldDecoder.java @@ -26,7 +26,7 @@ import static io.trino.decoder.DecoderErrorCode.DECODER_CONVERSION_NOT_SUPPORTED; import static io.trino.decoder.json.JsonRowDecoderFactory.throwUnsupportedColumnType; import static io.trino.spi.type.TimeType.TIME_MILLIS; -import static io.trino.spi.type.TimeWithTimeZoneType.TIME_WITH_TIME_ZONE; +import static io.trino.spi.type.TimeWithTimeZoneType.TIME_TZ_MILLIS; import static io.trino.spi.type.TimeZoneKey.UTC_KEY; import static io.trino.spi.type.TimestampType.TIMESTAMP_MILLIS; import static io.trino.spi.type.TimestampWithTimeZoneType.TIMESTAMP_TZ_MILLIS; @@ -43,7 +43,7 @@ public class SecondsSinceEpochJsonFieldDecoder implements JsonFieldDecoder { - private static final Set SUPPORTED_TYPES = ImmutableSet.of(TIME_MILLIS, TIME_WITH_TIME_ZONE, TIMESTAMP_MILLIS, TIMESTAMP_TZ_MILLIS); + private static final Set SUPPORTED_TYPES = ImmutableSet.of(TIME_MILLIS, TIME_TZ_MILLIS, TIMESTAMP_MILLIS, TIMESTAMP_TZ_MILLIS); private final DecoderColumnHandle columnHandle; diff --git a/lib/trino-record-decoder/src/test/java/io/trino/decoder/json/TestCustomDateTimeJsonFieldDecoder.java b/lib/trino-record-decoder/src/test/java/io/trino/decoder/json/TestCustomDateTimeJsonFieldDecoder.java index 7ec49613b85..a2c5d918c1f 100644 --- a/lib/trino-record-decoder/src/test/java/io/trino/decoder/json/TestCustomDateTimeJsonFieldDecoder.java +++ b/lib/trino-record-decoder/src/test/java/io/trino/decoder/json/TestCustomDateTimeJsonFieldDecoder.java @@ -23,7 +23,7 @@ import static io.trino.spi.type.DateTimeEncoding.packTimeWithTimeZone; import static io.trino.spi.type.DateType.DATE; import static io.trino.spi.type.TimeType.TIME_MILLIS; -import static io.trino.spi.type.TimeWithTimeZoneType.TIME_WITH_TIME_ZONE; +import static io.trino.spi.type.TimeWithTimeZoneType.TIME_TZ_MILLIS; import static io.trino.spi.type.TimeZoneKey.UTC_KEY; import static io.trino.spi.type.TimeZoneKey.getTimeZoneKeyForOffset; import static io.trino.spi.type.TimestampType.TIMESTAMP_MILLIS; @@ -50,9 +50,9 @@ public void testDecode() timeTester.assertDecodedAs("\"15:13:18\"", TIME_MILLIS, 47_718_000_000_000_000L); timeJustHourTester.assertDecodedAs("\"15\"", TIME_MILLIS, 54_000_000_000_000_000L); timeJustHourTester.assertDecodedAs("15", TIME_MILLIS, 54_000_000_000_000_000L); - timeTester.assertDecodedAs("\"15:13:18\"", TIME_WITH_TIME_ZONE, packTimeWithTimeZone(47_718_000_000_000L, 0)); - timeWTZTester.assertDecodedAs("\"15:13:18.123-04:00\"", TIME_WITH_TIME_ZONE, packTimeWithTimeZone(54_798_123_000_000L, -4 * 60)); - timeWTZTester.assertDecodedAs("\"15:13:18.123+08:00\"", TIME_WITH_TIME_ZONE, packTimeWithTimeZone(54_798_123_000_000L, 8 * 60)); + timeTester.assertDecodedAs("\"15:13:18\"", TIME_TZ_MILLIS, packTimeWithTimeZone(47_718_000_000_000L, 0)); + timeWTZTester.assertDecodedAs("\"15:13:18.123-04:00\"", TIME_TZ_MILLIS, packTimeWithTimeZone(54_798_123_000_000L, -4 * 60)); + timeWTZTester.assertDecodedAs("\"15:13:18.123+08:00\"", TIME_TZ_MILLIS, packTimeWithTimeZone(54_798_123_000_000L, 8 * 60)); dateTester.assertDecodedAs("\"02/2018/11\"", DATE, 17573); } @@ -65,8 +65,8 @@ public void testDecodeNulls() timeTester.assertDecodedAsNull("null", TIME_MILLIS); timeTester.assertMissingDecodedAsNull(TIME_MILLIS); - timeTester.assertDecodedAsNull("null", TIME_WITH_TIME_ZONE); - timeTester.assertMissingDecodedAsNull(TIME_WITH_TIME_ZONE); + timeTester.assertDecodedAsNull("null", TIME_TZ_MILLIS); + timeTester.assertMissingDecodedAsNull(TIME_TZ_MILLIS); timestampTester.assertDecodedAsNull("null", TIMESTAMP_MILLIS); timestampTester.assertMissingDecodedAsNull(TIMESTAMP_MILLIS); diff --git a/lib/trino-record-decoder/src/test/java/io/trino/decoder/json/TestISO8601JsonFieldDecoder.java b/lib/trino-record-decoder/src/test/java/io/trino/decoder/json/TestISO8601JsonFieldDecoder.java index b84828e1587..cd1a4f5ad06 100644 --- a/lib/trino-record-decoder/src/test/java/io/trino/decoder/json/TestISO8601JsonFieldDecoder.java +++ b/lib/trino-record-decoder/src/test/java/io/trino/decoder/json/TestISO8601JsonFieldDecoder.java @@ -20,7 +20,7 @@ import static io.trino.spi.type.DateTimeEncoding.packTimeWithTimeZone; import static io.trino.spi.type.DateType.DATE; import static io.trino.spi.type.TimeType.TIME_MILLIS; -import static io.trino.spi.type.TimeWithTimeZoneType.TIME_WITH_TIME_ZONE; +import static io.trino.spi.type.TimeWithTimeZoneType.TIME_TZ_MILLIS; import static io.trino.spi.type.TimeZoneKey.UTC_KEY; import static io.trino.spi.type.TimestampType.TIMESTAMP_MILLIS; import static io.trino.spi.type.TimestampWithTimeZoneType.TIMESTAMP_TZ_MILLIS; @@ -45,16 +45,16 @@ public void testDecode() tester.assertDecodedAs("\"2018-02-11\"", DATE, 17573); tester.assertDecodedAs("\"2018-02-19T09:20:11Z\"", TIMESTAMP_TZ_MILLIS, packDateTimeWithZone(1519032011000L, UTC_KEY)); tester.assertDecodedAs("\"2018-02-19T12:20:11+03:00\"", TIMESTAMP_TZ_MILLIS, packDateTimeWithZone(1519032011000L, "+03:00")); - tester.assertDecodedAs("\"13:15:18Z\"", TIME_WITH_TIME_ZONE, packTimeWithTimeZone(47_718_000_000_000L, 0)); - tester.assertDecodedAs("\"13:15:18+10:00\"", TIME_WITH_TIME_ZONE, packTimeWithTimeZone(47_718_000_000_000L, 10 * 60)); - tester.assertDecodedAs("\"15:13:18.123-04:00\"", TIME_WITH_TIME_ZONE, packTimeWithTimeZone(54_798_123_000_000L, -4 * 60)); - tester.assertDecodedAs("\"15:13:18.123+08:00\"", TIME_WITH_TIME_ZONE, packTimeWithTimeZone(54_798_123_000_000L, 8 * 60)); + tester.assertDecodedAs("\"13:15:18Z\"", TIME_TZ_MILLIS, packTimeWithTimeZone(47_718_000_000_000L, 0)); + tester.assertDecodedAs("\"13:15:18+10:00\"", TIME_TZ_MILLIS, packTimeWithTimeZone(47_718_000_000_000L, 10 * 60)); + tester.assertDecodedAs("\"15:13:18.123-04:00\"", TIME_TZ_MILLIS, packTimeWithTimeZone(54_798_123_000_000L, -4 * 60)); + tester.assertDecodedAs("\"15:13:18.123+08:00\"", TIME_TZ_MILLIS, packTimeWithTimeZone(54_798_123_000_000L, 8 * 60)); } @Test public void testDecodeNulls() { - for (Type type : asList(DATE, TIME_MILLIS, TIME_WITH_TIME_ZONE, TIMESTAMP_MILLIS, TIMESTAMP_TZ_MILLIS)) { + for (Type type : asList(DATE, TIME_MILLIS, TIME_TZ_MILLIS, TIMESTAMP_MILLIS, TIMESTAMP_TZ_MILLIS)) { tester.assertDecodedAsNull("null", type); tester.assertMissingDecodedAsNull(type); } @@ -83,9 +83,9 @@ public void testDecodeInvalid() tester.assertInvalidInput("\"2018-02-19\"", TIME_MILLIS, "\\Qcould not parse value '2018-02-19' as 'time(3)' for column 'some_column'\\E"); tester.assertInvalidInput("\"2018-02-19Z\"", TIME_MILLIS, "\\Qcould not parse value '2018-02-19Z' as 'time(3)' for column 'some_column'\\E"); - tester.assertInvalidInput("\"2018-02-19T09:20:11\"", TIME_WITH_TIME_ZONE, "\\Qcould not parse value '2018-02-19T09:20:11' as 'time(3) with time zone' for column 'some_column'\\E"); - tester.assertInvalidInput("\"2018-02-19T09:20:11Z\"", TIME_WITH_TIME_ZONE, "\\Qcould not parse value '2018-02-19T09:20:11Z' as 'time(3) with time zone' for column 'some_column'\\E"); - tester.assertInvalidInput("\"09:20:11\"", TIME_WITH_TIME_ZONE, "\\Qcould not parse value '09:20:11' as 'time(3) with time zone' for column 'some_column'\\E"); - tester.assertInvalidInput("\"2018-02-19\"", TIME_WITH_TIME_ZONE, "\\Qcould not parse value '2018-02-19' as 'time(3) with time zone' for column 'some_column'\\E"); + tester.assertInvalidInput("\"2018-02-19T09:20:11\"", TIME_TZ_MILLIS, "\\Qcould not parse value '2018-02-19T09:20:11' as 'time(3) with time zone' for column 'some_column'\\E"); + tester.assertInvalidInput("\"2018-02-19T09:20:11Z\"", TIME_TZ_MILLIS, "\\Qcould not parse value '2018-02-19T09:20:11Z' as 'time(3) with time zone' for column 'some_column'\\E"); + tester.assertInvalidInput("\"09:20:11\"", TIME_TZ_MILLIS, "\\Qcould not parse value '09:20:11' as 'time(3) with time zone' for column 'some_column'\\E"); + tester.assertInvalidInput("\"2018-02-19\"", TIME_TZ_MILLIS, "\\Qcould not parse value '2018-02-19' as 'time(3) with time zone' for column 'some_column'\\E"); } } diff --git a/lib/trino-record-decoder/src/test/java/io/trino/decoder/json/TestJsonDecoder.java b/lib/trino-record-decoder/src/test/java/io/trino/decoder/json/TestJsonDecoder.java index 2c6179c9039..079d453042d 100644 --- a/lib/trino-record-decoder/src/test/java/io/trino/decoder/json/TestJsonDecoder.java +++ b/lib/trino-record-decoder/src/test/java/io/trino/decoder/json/TestJsonDecoder.java @@ -41,7 +41,7 @@ import static io.trino.spi.type.RealType.REAL; import static io.trino.spi.type.SmallintType.SMALLINT; import static io.trino.spi.type.TimeType.TIME_MILLIS; -import static io.trino.spi.type.TimeWithTimeZoneType.TIME_WITH_TIME_ZONE; +import static io.trino.spi.type.TimeWithTimeZoneType.TIME_TZ_MILLIS; import static io.trino.spi.type.TimestampType.TIMESTAMP_MILLIS; import static io.trino.spi.type.TimestampWithTimeZoneType.TIMESTAMP_TZ_MILLIS; import static io.trino.spi.type.TinyintType.TINYINT; @@ -152,14 +152,14 @@ public void testSupportedDataTypeValidation() for (String dataFormat : ImmutableSet.of("iso8601", "custom-date-time")) { singleColumnDecoder(DATE, dataFormat); singleColumnDecoder(TIME_MILLIS, dataFormat); - singleColumnDecoder(TIME_WITH_TIME_ZONE, dataFormat); + singleColumnDecoder(TIME_TZ_MILLIS, dataFormat); singleColumnDecoder(TIMESTAMP_MILLIS, dataFormat); singleColumnDecoder(TIMESTAMP_TZ_MILLIS, dataFormat); } for (String dataFormat : ImmutableSet.of("seconds-since-epoch", "milliseconds-since-epoch")) { singleColumnDecoder(TIME_MILLIS, dataFormat); - singleColumnDecoder(TIME_WITH_TIME_ZONE, dataFormat); + singleColumnDecoder(TIME_TZ_MILLIS, dataFormat); singleColumnDecoder(TIMESTAMP_MILLIS, dataFormat); singleColumnDecoder(TIMESTAMP_TZ_MILLIS, dataFormat); } @@ -172,7 +172,7 @@ public void testSupportedDataTypeValidation() // temporal types are not supported for default field decoder assertUnsupportedColumnTypeException(() -> singleColumnDecoder(DATE, null)); assertUnsupportedColumnTypeException(() -> singleColumnDecoder(TIME_MILLIS, null)); - assertUnsupportedColumnTypeException(() -> singleColumnDecoder(TIME_WITH_TIME_ZONE, null)); + assertUnsupportedColumnTypeException(() -> singleColumnDecoder(TIME_TZ_MILLIS, null)); assertUnsupportedColumnTypeException(() -> singleColumnDecoder(TIMESTAMP_MILLIS, null)); assertUnsupportedColumnTypeException(() -> singleColumnDecoder(TIMESTAMP_TZ_MILLIS, null)); diff --git a/lib/trino-record-decoder/src/test/java/io/trino/decoder/json/TestMillisecondsSinceEpochJsonFieldDecoder.java b/lib/trino-record-decoder/src/test/java/io/trino/decoder/json/TestMillisecondsSinceEpochJsonFieldDecoder.java index a42f62639cd..b36acf2e303 100644 --- a/lib/trino-record-decoder/src/test/java/io/trino/decoder/json/TestMillisecondsSinceEpochJsonFieldDecoder.java +++ b/lib/trino-record-decoder/src/test/java/io/trino/decoder/json/TestMillisecondsSinceEpochJsonFieldDecoder.java @@ -21,7 +21,7 @@ import static io.trino.spi.type.DateTimeEncoding.packDateTimeWithZone; import static io.trino.spi.type.DateTimeEncoding.packTimeWithTimeZone; import static io.trino.spi.type.TimeType.TIME_MILLIS; -import static io.trino.spi.type.TimeWithTimeZoneType.TIME_WITH_TIME_ZONE; +import static io.trino.spi.type.TimeWithTimeZoneType.TIME_TZ_MILLIS; import static io.trino.spi.type.TimeZoneKey.UTC_KEY; import static io.trino.spi.type.TimestampType.TIMESTAMP_MILLIS; import static io.trino.spi.type.TimestampWithTimeZoneType.TIMESTAMP_TZ_MILLIS; @@ -36,8 +36,8 @@ public void testDecode() { tester.assertDecodedAs("33701000", TIME_MILLIS, 33_701_000_000_000_000L); tester.assertDecodedAs("\"33701000\"", TIME_MILLIS, 33_701_000_000_000_000L); - tester.assertDecodedAs("33701000", TIME_WITH_TIME_ZONE, packTimeWithTimeZone(33_701_000_000_000L, 0)); - tester.assertDecodedAs("\"33701000\"", TIME_WITH_TIME_ZONE, packTimeWithTimeZone(33_701_000_000_000L, 0)); + tester.assertDecodedAs("33701000", TIME_TZ_MILLIS, packTimeWithTimeZone(33_701_000_000_000L, 0)); + tester.assertDecodedAs("\"33701000\"", TIME_TZ_MILLIS, packTimeWithTimeZone(33_701_000_000_000L, 0)); tester.assertDecodedAs("1519032101123", TIMESTAMP_MILLIS, 1_519_032_101_123_000L); tester.assertDecodedAs("\"1519032101123\"", TIMESTAMP_MILLIS, 1_519_032_101_123_000L); tester.assertDecodedAs("1519032101123", TIMESTAMP_TZ_MILLIS, packDateTimeWithZone(1519032101123L, UTC_KEY)); @@ -47,7 +47,7 @@ public void testDecode() @Test public void testDecodeNulls() { - for (Type type : asList(TIME_MILLIS, TIME_WITH_TIME_ZONE, TIMESTAMP_MILLIS, TIMESTAMP_TZ_MILLIS)) { + for (Type type : asList(TIME_MILLIS, TIME_TZ_MILLIS, TIMESTAMP_MILLIS, TIMESTAMP_TZ_MILLIS)) { tester.assertDecodedAsNull("null", type); tester.assertMissingDecodedAsNull(type); } @@ -56,7 +56,7 @@ public void testDecodeNulls() @Test public void testDecodeInvalid() { - for (Type type : asList(TIME_MILLIS, TIME_WITH_TIME_ZONE, TIMESTAMP_MILLIS, TIMESTAMP_TZ_MILLIS)) { + for (Type type : asList(TIME_MILLIS, TIME_TZ_MILLIS, TIMESTAMP_MILLIS, TIMESTAMP_TZ_MILLIS)) { tester.assertInvalidInput("{}", type, "could not parse non-value node as '.*' for column 'some_column'"); tester.assertInvalidInput("[]", type, "could not parse non-value node as '.*' for column 'some_column'"); tester.assertInvalidInput("[10]", type, "could not parse non-value node as '.*' for column 'some_column'"); @@ -68,7 +68,7 @@ public void testDecodeInvalid() // TIME specific range checks tester.assertInvalidInput("-1", TIME_MILLIS, "\\Qcould not parse value '-1' as 'time(3)' for column 'some_column'\\E"); tester.assertInvalidInput("" + TimeUnit.DAYS.toMillis(1) + 1, TIME_MILLIS, "\\Qcould not parse value '864000001' as 'time(3)' for column 'some_column'\\E"); - tester.assertInvalidInput("-1", TIME_WITH_TIME_ZONE, "\\Qcould not parse value '-1' as 'time(3) with time zone' for column 'some_column'\\E"); - tester.assertInvalidInput("" + TimeUnit.DAYS.toMillis(1) + 1, TIME_WITH_TIME_ZONE, "\\Qcould not parse value '864000001' as 'time(3) with time zone' for column 'some_column'\\E"); + tester.assertInvalidInput("-1", TIME_TZ_MILLIS, "\\Qcould not parse value '-1' as 'time(3) with time zone' for column 'some_column'\\E"); + tester.assertInvalidInput("" + TimeUnit.DAYS.toMillis(1) + 1, TIME_TZ_MILLIS, "\\Qcould not parse value '864000001' as 'time(3) with time zone' for column 'some_column'\\E"); } } diff --git a/lib/trino-record-decoder/src/test/java/io/trino/decoder/json/TestSecondsSinceEpochJsonFieldDecoder.java b/lib/trino-record-decoder/src/test/java/io/trino/decoder/json/TestSecondsSinceEpochJsonFieldDecoder.java index a003db95bb4..0ea0e43c492 100644 --- a/lib/trino-record-decoder/src/test/java/io/trino/decoder/json/TestSecondsSinceEpochJsonFieldDecoder.java +++ b/lib/trino-record-decoder/src/test/java/io/trino/decoder/json/TestSecondsSinceEpochJsonFieldDecoder.java @@ -21,7 +21,7 @@ import static io.trino.spi.type.DateTimeEncoding.packDateTimeWithZone; import static io.trino.spi.type.DateTimeEncoding.packTimeWithTimeZone; import static io.trino.spi.type.TimeType.TIME_MILLIS; -import static io.trino.spi.type.TimeWithTimeZoneType.TIME_WITH_TIME_ZONE; +import static io.trino.spi.type.TimeWithTimeZoneType.TIME_TZ_MILLIS; import static io.trino.spi.type.TimeZoneKey.UTC_KEY; import static io.trino.spi.type.TimestampType.TIMESTAMP_MILLIS; import static io.trino.spi.type.TimestampWithTimeZoneType.TIMESTAMP_TZ_MILLIS; @@ -36,8 +36,8 @@ public void testDecode() { tester.assertDecodedAs("33701", TIME_MILLIS, 33_701_000_000_000_000L); tester.assertDecodedAs("\"33701\"", TIME_MILLIS, 33_701_000_000_000_000L); - tester.assertDecodedAs("33701", TIME_WITH_TIME_ZONE, packTimeWithTimeZone(33_701_000_000_000L, 0)); - tester.assertDecodedAs("\"33701\"", TIME_WITH_TIME_ZONE, packTimeWithTimeZone(33_701_000_000_000L, 0)); + tester.assertDecodedAs("33701", TIME_TZ_MILLIS, packTimeWithTimeZone(33_701_000_000_000L, 0)); + tester.assertDecodedAs("\"33701\"", TIME_TZ_MILLIS, packTimeWithTimeZone(33_701_000_000_000L, 0)); tester.assertDecodedAs("1519032101", TIMESTAMP_MILLIS, 1_519_032_101_000_000L); tester.assertDecodedAs("\"1519032101\"", TIMESTAMP_MILLIS, 1_519_032_101_000_000L); tester.assertDecodedAs("" + (Long.MAX_VALUE / 1_000_000), TIMESTAMP_MILLIS, Long.MAX_VALUE / 1_000_000 * 1_000_000); @@ -49,7 +49,7 @@ public void testDecode() @Test public void testDecodeNulls() { - for (Type type : asList(TIME_MILLIS, TIME_WITH_TIME_ZONE, TIMESTAMP_MILLIS, TIMESTAMP_TZ_MILLIS)) { + for (Type type : asList(TIME_MILLIS, TIME_TZ_MILLIS, TIMESTAMP_MILLIS, TIMESTAMP_TZ_MILLIS)) { tester.assertDecodedAsNull("null", type); tester.assertMissingDecodedAsNull(type); } @@ -58,7 +58,7 @@ public void testDecodeNulls() @Test public void testDecodeInvalid() { - for (Type type : asList(TIME_MILLIS, TIME_WITH_TIME_ZONE, TIMESTAMP_MILLIS, TIMESTAMP_TZ_MILLIS)) { + for (Type type : asList(TIME_MILLIS, TIME_TZ_MILLIS, TIMESTAMP_MILLIS, TIMESTAMP_TZ_MILLIS)) { tester.assertInvalidInput("{}", type, "could not parse non-value node as '.*' for column 'some_column'"); tester.assertInvalidInput("[]", type, "could not parse non-value node as '.*' for column 'some_column'"); tester.assertInvalidInput("[10]", type, "could not parse non-value node as '.*' for column 'some_column'"); @@ -72,7 +72,7 @@ public void testDecodeInvalid() // TIME specific range checks tester.assertInvalidInput("-1", TIME_MILLIS, "\\Qcould not parse value '-1' as 'time(3)' for column 'some_column'\\E"); tester.assertInvalidInput("" + TimeUnit.DAYS.toSeconds(1) + 1, TIME_MILLIS, "\\Qcould not parse value '864001' as 'time(3)' for column 'some_column'\\E"); - tester.assertInvalidInput("-1", TIME_WITH_TIME_ZONE, "\\Qcould not parse value '-1' as 'time(3) with time zone' for column 'some_column'\\E"); - tester.assertInvalidInput("" + TimeUnit.DAYS.toSeconds(1) + 1, TIME_WITH_TIME_ZONE, "\\Qcould not parse value '864001' as 'time(3) with time zone' for column 'some_column'\\E"); + tester.assertInvalidInput("-1", TIME_TZ_MILLIS, "\\Qcould not parse value '-1' as 'time(3) with time zone' for column 'some_column'\\E"); + tester.assertInvalidInput("" + TimeUnit.DAYS.toSeconds(1) + 1, TIME_TZ_MILLIS, "\\Qcould not parse value '864001' as 'time(3) with time zone' for column 'some_column'\\E"); } } diff --git a/plugin/trino-kafka/src/main/java/io/trino/plugin/kafka/encoder/json/JsonRowEncoder.java b/plugin/trino-kafka/src/main/java/io/trino/plugin/kafka/encoder/json/JsonRowEncoder.java index 93de2ecdc85..55284bf741d 100644 --- a/plugin/trino-kafka/src/main/java/io/trino/plugin/kafka/encoder/json/JsonRowEncoder.java +++ b/plugin/trino-kafka/src/main/java/io/trino/plugin/kafka/encoder/json/JsonRowEncoder.java @@ -46,7 +46,7 @@ import static io.trino.spi.type.IntegerType.INTEGER; import static io.trino.spi.type.SmallintType.SMALLINT; import static io.trino.spi.type.TimeType.TIME_MILLIS; -import static io.trino.spi.type.TimeWithTimeZoneType.TIME_WITH_TIME_ZONE; +import static io.trino.spi.type.TimeWithTimeZoneType.TIME_TZ_MILLIS; import static io.trino.spi.type.TimestampType.TIMESTAMP_MILLIS; import static io.trino.spi.type.TimestampWithTimeZoneType.TIMESTAMP_TZ_MILLIS; import static io.trino.spi.type.TinyintType.TINYINT; @@ -111,7 +111,7 @@ private static boolean isSupportedTemporalType(Type type) { return type.equals(DATE) || type.equals(TIME_MILLIS) || - type.equals(TIME_WITH_TIME_ZONE) || + type.equals(TIME_TZ_MILLIS) || type.equals(TIMESTAMP_MILLIS) || type.equals(TIMESTAMP_TZ_MILLIS); } diff --git a/plugin/trino-kafka/src/main/java/io/trino/plugin/kafka/encoder/json/format/CustomDateTimeFormatter.java b/plugin/trino-kafka/src/main/java/io/trino/plugin/kafka/encoder/json/format/CustomDateTimeFormatter.java index 5ae366587f0..8e76b8639f5 100644 --- a/plugin/trino-kafka/src/main/java/io/trino/plugin/kafka/encoder/json/format/CustomDateTimeFormatter.java +++ b/plugin/trino-kafka/src/main/java/io/trino/plugin/kafka/encoder/json/format/CustomDateTimeFormatter.java @@ -35,7 +35,7 @@ import static io.trino.plugin.kafka.encoder.json.format.util.TimeConversions.scalePicosToMillis; import static io.trino.spi.type.DateType.DATE; import static io.trino.spi.type.TimeType.TIME_MILLIS; -import static io.trino.spi.type.TimeWithTimeZoneType.TIME_WITH_TIME_ZONE; +import static io.trino.spi.type.TimeWithTimeZoneType.TIME_TZ_MILLIS; import static io.trino.spi.type.TimestampType.TIMESTAMP_MILLIS; import static io.trino.spi.type.TimestampWithTimeZoneType.TIMESTAMP_TZ_MILLIS; import static java.util.concurrent.TimeUnit.DAYS; @@ -50,7 +50,7 @@ public static boolean isSupportedType(Type type) { return type.equals(DATE) || type.equals(TIME_MILLIS) || - type.equals(TIME_WITH_TIME_ZONE) || + type.equals(TIME_TZ_MILLIS) || type.equals(TIMESTAMP_MILLIS) || type.equals(TIMESTAMP_TZ_MILLIS); } diff --git a/plugin/trino-kafka/src/main/java/io/trino/plugin/kafka/encoder/json/format/ISO8601DateTimeFormatter.java b/plugin/trino-kafka/src/main/java/io/trino/plugin/kafka/encoder/json/format/ISO8601DateTimeFormatter.java index abd764cd6ed..65b5b1628ff 100644 --- a/plugin/trino-kafka/src/main/java/io/trino/plugin/kafka/encoder/json/format/ISO8601DateTimeFormatter.java +++ b/plugin/trino-kafka/src/main/java/io/trino/plugin/kafka/encoder/json/format/ISO8601DateTimeFormatter.java @@ -37,7 +37,7 @@ import static io.trino.plugin.kafka.encoder.json.format.util.TimeConversions.scalePicosToNanos; import static io.trino.spi.type.DateType.DATE; import static io.trino.spi.type.TimeType.TIME_MILLIS; -import static io.trino.spi.type.TimeWithTimeZoneType.TIME_WITH_TIME_ZONE; +import static io.trino.spi.type.TimeWithTimeZoneType.TIME_TZ_MILLIS; import static io.trino.spi.type.TimestampType.TIMESTAMP_MILLIS; import static io.trino.spi.type.TimestampWithTimeZoneType.TIMESTAMP_TZ_MILLIS; import static java.time.ZoneOffset.UTC; @@ -51,7 +51,7 @@ public static boolean isSupportedType(Type type) { return type.equals(DATE) || type.equals(TIME_MILLIS) || - type.equals(TIME_WITH_TIME_ZONE) || + type.equals(TIME_TZ_MILLIS) || type.equals(TIMESTAMP_MILLIS) || type.equals(TIMESTAMP_TZ_MILLIS); } diff --git a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestKafkaConnectorTest.java b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestKafkaConnectorTest.java index 96f99e4e23f..11923f53ec0 100644 --- a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestKafkaConnectorTest.java +++ b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/TestKafkaConnectorTest.java @@ -53,7 +53,7 @@ import static io.trino.spi.type.DateType.DATE; import static io.trino.spi.type.DoubleType.DOUBLE; import static io.trino.spi.type.TimeType.TIME_MILLIS; -import static io.trino.spi.type.TimeWithTimeZoneType.TIME_WITH_TIME_ZONE; +import static io.trino.spi.type.TimeWithTimeZoneType.TIME_TZ_MILLIS; import static io.trino.spi.type.TimestampType.TIMESTAMP_MILLIS; import static io.trino.spi.type.TimestampWithTimeZoneType.TIMESTAMP_TZ_MILLIS; import static io.trino.spi.type.VarcharType.createVarcharType; @@ -533,7 +533,7 @@ private static List jsonDateTimeFormatsData() .setTopicName(JSON_CUSTOM_DATE_TIME_TABLE_NAME) .addField(DATE, CUSTOM_DATE_TIME.toString(), "yyyy-MM-dd", "DATE '2020-07-15'") .addField(TIME_MILLIS, CUSTOM_DATE_TIME.toString(), "HH:mm:ss.SSS", "TIME '01:02:03.456'") - .addField(TIME_WITH_TIME_ZONE, CUSTOM_DATE_TIME.toString(), "HH:mm:ss.SSS Z", "TIME '01:02:03.456 -04:00'") + .addField(TIME_TZ_MILLIS, CUSTOM_DATE_TIME.toString(), "HH:mm:ss.SSS Z", "TIME '01:02:03.456 -04:00'") .addField(TIMESTAMP_MILLIS, CUSTOM_DATE_TIME.toString(), "yyyy-dd-MM HH:mm:ss.SSS", "TIMESTAMP '2020-07-15 01:02:03.456'") .addField(TIMESTAMP_TZ_MILLIS, CUSTOM_DATE_TIME.toString(), "yyyy-dd-MM HH:mm:ss.SSS Z", "TIMESTAMP '2020-07-15 01:02:03.456 -04:00'") .build()) @@ -541,7 +541,7 @@ private static List jsonDateTimeFormatsData() .setTopicName(JSON_ISO8601_TABLE_NAME) .addField(DATE, ISO8601.toString(), "DATE '2020-07-15'") .addField(TIME_MILLIS, ISO8601.toString(), "TIME '01:02:03.456'") - .addField(TIME_WITH_TIME_ZONE, ISO8601.toString(), "TIME '01:02:03.456 -04:00'") + .addField(TIME_TZ_MILLIS, ISO8601.toString(), "TIME '01:02:03.456 -04:00'") .addField(TIMESTAMP_MILLIS, ISO8601.toString(), "TIMESTAMP '2020-07-15 01:02:03.456'") .addField(TIMESTAMP_TZ_MILLIS, ISO8601.toString(), "TIMESTAMP '2020-07-15 01:02:03.456 -04:00'") .build()) diff --git a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/json/TestJsonEncoder.java b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/json/TestJsonEncoder.java index 6458c3c578e..3ab85f54a25 100644 --- a/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/json/TestJsonEncoder.java +++ b/plugin/trino-kafka/src/test/java/io/trino/plugin/kafka/encoder/json/TestJsonEncoder.java @@ -39,7 +39,7 @@ import static io.trino.spi.type.RealType.REAL; import static io.trino.spi.type.SmallintType.SMALLINT; import static io.trino.spi.type.TimeType.TIME_MILLIS; -import static io.trino.spi.type.TimeWithTimeZoneType.TIME_WITH_TIME_ZONE; +import static io.trino.spi.type.TimeWithTimeZoneType.TIME_TZ_MILLIS; import static io.trino.spi.type.TimestampType.TIMESTAMP_MILLIS; import static io.trino.spi.type.TimestampWithTimeZoneType.TIMESTAMP_TZ_MILLIS; import static io.trino.spi.type.TinyintType.TINYINT; @@ -113,7 +113,7 @@ public void testColumnValidation() for (DateTimeFormat dataFormat : ImmutableList.of(CUSTOM_DATE_TIME, ISO8601)) { assertSupportedDataType(() -> singleColumnEncoder(DATE, dataFormat, "yyyy-dd-MM")); assertSupportedDataType(() -> singleColumnEncoder(TIME_MILLIS, dataFormat, "kk:mm:ss.SSS")); - assertSupportedDataType(() -> singleColumnEncoder(TIME_WITH_TIME_ZONE, dataFormat, "kk:mm:ss.SSS Z")); + assertSupportedDataType(() -> singleColumnEncoder(TIME_TZ_MILLIS, dataFormat, "kk:mm:ss.SSS Z")); assertSupportedDataType(() -> singleColumnEncoder(TIMESTAMP_MILLIS, dataFormat, "yyyy-dd-MM kk:mm:ss.SSS")); assertSupportedDataType(() -> singleColumnEncoder(TIMESTAMP_TZ_MILLIS, dataFormat, "yyyy-dd-MM kk:mm:ss.SSS Z")); } @@ -130,7 +130,7 @@ public void testColumnValidation() assertUnsupportedDataFormatException(() -> singleColumnEncoder(DATE)); assertUnsupportedDataFormatException(() -> singleColumnEncoder(TIME_MILLIS)); - assertUnsupportedDataFormatException(() -> singleColumnEncoder(TIME_WITH_TIME_ZONE)); + assertUnsupportedDataFormatException(() -> singleColumnEncoder(TIME_TZ_MILLIS)); assertUnsupportedDataFormatException(() -> singleColumnEncoder(TIMESTAMP_MILLIS)); assertUnsupportedDataFormatException(() -> singleColumnEncoder(TIMESTAMP_TZ_MILLIS)); diff --git a/plugin/trino-redis/src/main/java/io/trino/plugin/redis/decoder/hash/ISO8601HashRedisFieldDecoder.java b/plugin/trino-redis/src/main/java/io/trino/plugin/redis/decoder/hash/ISO8601HashRedisFieldDecoder.java index 3ba8d60211a..f2396c5c67a 100644 --- a/plugin/trino-redis/src/main/java/io/trino/plugin/redis/decoder/hash/ISO8601HashRedisFieldDecoder.java +++ b/plugin/trino-redis/src/main/java/io/trino/plugin/redis/decoder/hash/ISO8601HashRedisFieldDecoder.java @@ -26,7 +26,7 @@ import static io.trino.spi.type.DateTimeEncoding.packDateTimeWithZone; import static io.trino.spi.type.DateType.DATE; import static io.trino.spi.type.TimeType.TIME_MILLIS; -import static io.trino.spi.type.TimeWithTimeZoneType.TIME_WITH_TIME_ZONE; +import static io.trino.spi.type.TimeWithTimeZoneType.TIME_TZ_MILLIS; import static io.trino.spi.type.TimeZoneKey.getTimeZoneKey; import static io.trino.spi.type.TimestampType.TIMESTAMP_MILLIS; import static io.trino.spi.type.TimestampWithTimeZoneType.TIMESTAMP_TZ_MILLIS; @@ -72,7 +72,7 @@ public long getLong() if (type.equals(TIME_MILLIS)) { return millis * PICOSECONDS_PER_MILLISECOND; } - if (type.equals(TIMESTAMP_TZ_MILLIS) || type.equals(TIME_WITH_TIME_ZONE)) { + if (type.equals(TIMESTAMP_TZ_MILLIS) || type.equals(TIME_TZ_MILLIS)) { return packDateTimeWithZone(millis, getTimeZoneKey(dateTime.getZone().getID())); } diff --git a/plugin/trino-redis/src/test/java/io/trino/plugin/redis/util/RedisLoader.java b/plugin/trino-redis/src/test/java/io/trino/plugin/redis/util/RedisLoader.java index 9bb128da0a7..6d23dd40818 100644 --- a/plugin/trino-redis/src/test/java/io/trino/plugin/redis/util/RedisLoader.java +++ b/plugin/trino-redis/src/test/java/io/trino/plugin/redis/util/RedisLoader.java @@ -45,7 +45,7 @@ import static io.trino.spi.type.DoubleType.DOUBLE; import static io.trino.spi.type.IntegerType.INTEGER; import static io.trino.spi.type.TimeType.TIME_MILLIS; -import static io.trino.spi.type.TimeWithTimeZoneType.TIME_WITH_TIME_ZONE; +import static io.trino.spi.type.TimeWithTimeZoneType.TIME_TZ_MILLIS; import static io.trino.spi.type.TimestampType.TIMESTAMP_MILLIS; import static io.trino.spi.type.TimestampWithTimeZoneType.TIMESTAMP_TZ_MILLIS; import static io.trino.util.DateTimeUtils.parseLegacyTime; @@ -171,7 +171,7 @@ private Object convertValue(Object value, Type type) if (TIMESTAMP_MILLIS.equals(type)) { return ISO8601_FORMATTER.print(castToShortTimestamp(TIMESTAMP_MILLIS.getPrecision(), (String) value)); } - if (TIME_WITH_TIME_ZONE.equals(type) || TIMESTAMP_TZ_MILLIS.equals(type)) { + if (TIME_TZ_MILLIS.equals(type) || TIMESTAMP_TZ_MILLIS.equals(type)) { return ISO8601_FORMATTER.print(unpackMillisUtc(DateTimeUtils.convertToTimestampWithTimeZone(timeZoneKey, (String) value))); } throw new AssertionError("unhandled type: " + type); diff --git a/testing/trino-testing/src/main/java/io/trino/testing/H2QueryRunner.java b/testing/trino-testing/src/main/java/io/trino/testing/H2QueryRunner.java index b401bce4f3f..f86038c995d 100644 --- a/testing/trino-testing/src/main/java/io/trino/testing/H2QueryRunner.java +++ b/testing/trino-testing/src/main/java/io/trino/testing/H2QueryRunner.java @@ -26,6 +26,7 @@ import io.trino.spi.type.CharType; import io.trino.spi.type.DecimalType; import io.trino.spi.type.TimeType; +import io.trino.spi.type.TimeWithTimeZoneType; import io.trino.spi.type.TimestampType; import io.trino.spi.type.Type; import io.trino.spi.type.VarcharType; @@ -71,7 +72,6 @@ import static io.trino.spi.type.IntegerType.INTEGER; import static io.trino.spi.type.RealType.REAL; import static io.trino.spi.type.SmallintType.SMALLINT; -import static io.trino.spi.type.TimeWithTimeZoneType.TIME_WITH_TIME_ZONE; import static io.trino.spi.type.TimestampWithTimeZoneType.TIMESTAMP_TZ_MILLIS; import static io.trino.spi.type.TinyintType.TINYINT; import static io.trino.spi.type.UuidType.UUID; @@ -328,7 +328,7 @@ else if (type instanceof TimeType) { row.add(timeValue); } } - else if (TIME_WITH_TIME_ZONE.equals(type)) { + else if (type instanceof TimeWithTimeZoneType) { throw new UnsupportedOperationException("H2 does not support TIME WITH TIME ZONE"); } else if (type instanceof TimestampType) {