Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -627,7 +627,7 @@ protected Type visitCurrentTime(CurrentTime node, StackableAstVisitorContext<Con
if (node.getPrecision() != null) {
yield setExpressionType(node, createTimeWithTimeZoneType(node.getPrecision()));
}
yield setExpressionType(node, TIME_WITH_TIME_ZONE);
yield setExpressionType(node, TIME_TZ_MILLIS);
}
case LOCALTIME -> {
if (node.getPrecision() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public String getName()
public Type createType(TypeManager typeManager, List<TypeParameter> 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -50,7 +50,7 @@
public class CustomDateTimeJsonFieldDecoder
implements JsonFieldDecoder
{
private static final Set<Type> SUPPORTED_TYPES = ImmutableSet.of(DATE, TIME_MILLIS, TIME_WITH_TIME_ZONE, TIMESTAMP_MILLIS, TIMESTAMP_TZ_MILLIS);
private static final Set<Type> SUPPORTED_TYPES = ImmutableSet.of(DATE, TIME_MILLIS, TIME_TZ_MILLIS, TIMESTAMP_MILLIS, TIMESTAMP_TZ_MILLIS);

private final DecoderColumnHandle columnHandle;
private final DateTimeFormatter formatter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -60,7 +60,7 @@
public class ISO8601JsonFieldDecoder
implements JsonFieldDecoder
{
private static final Set<Type> SUPPORTED_TYPES = ImmutableSet.of(DATE, TIME_MILLIS, TIME_WITH_TIME_ZONE, TIMESTAMP_MILLIS, TIMESTAMP_TZ_MILLIS);
private static final Set<Type> SUPPORTED_TYPES = ImmutableSet.of(DATE, TIME_MILLIS, TIME_TZ_MILLIS, TIMESTAMP_MILLIS, TIMESTAMP_TZ_MILLIS);

private final DecoderColumnHandle columnHandle;

Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,7 +41,7 @@
public class MillisecondsSinceEpochJsonFieldDecoder
implements JsonFieldDecoder
{
private static final Set<Type> SUPPORTED_TYPES = ImmutableSet.of(TIME_MILLIS, TIME_WITH_TIME_ZONE, TIMESTAMP_MILLIS, TIMESTAMP_TZ_MILLIS);
private static final Set<Type> SUPPORTED_TYPES = ImmutableSet.of(TIME_MILLIS, TIME_TZ_MILLIS, TIMESTAMP_MILLIS, TIMESTAMP_TZ_MILLIS);

private final DecoderColumnHandle columnHandle;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,7 +43,7 @@
public class SecondsSinceEpochJsonFieldDecoder
implements JsonFieldDecoder
{
private static final Set<Type> SUPPORTED_TYPES = ImmutableSet.of(TIME_MILLIS, TIME_WITH_TIME_ZONE, TIMESTAMP_MILLIS, TIMESTAMP_TZ_MILLIS);
private static final Set<Type> SUPPORTED_TYPES = ImmutableSet.of(TIME_MILLIS, TIME_TZ_MILLIS, TIMESTAMP_MILLIS, TIMESTAMP_TZ_MILLIS);

private final DecoderColumnHandle columnHandle;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}

Expand All @@ -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);
Expand Down
Loading