Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#6656 ] fix(trino-connector): support read MySQL time/datetime/timestamp columns with precision #6657

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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 @@ -55,24 +55,54 @@ public io.trino.spi.type.Type getTrinoType(Type type) {
}

private static TimestampWithTimeZoneType getTimestampWithTimeZoneType(int precision) {
if (precision == 0) return TimestampWithTimeZoneType.TIMESTAMP_TZ_SECONDS;
if (precision <= 3) return TimestampWithTimeZoneType.TIMESTAMP_TZ_MILLIS;
if (precision <= 6) return TimestampWithTimeZoneType.TIMESTAMP_TZ_MICROS;
return TimestampWithTimeZoneType.TIMESTAMP_TZ_NANOS;
switch (precision) {
case 0:
return TimestampWithTimeZoneType.TIMESTAMP_TZ_SECONDS;
case 3:
return TimestampWithTimeZoneType.TIMESTAMP_TZ_MILLIS;
case 6:
return TimestampWithTimeZoneType.TIMESTAMP_TZ_MICROS;
case 9:
return TimestampWithTimeZoneType.TIMESTAMP_TZ_NANOS;
default:
throw new TrinoException(
GravitinoErrorCode.GRAVITINO_ILLEGAL_ARGUMENT,
"Invalid timestamp precision: " + precision + ". Valid values are 0, 3, 6, 9");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two problems:

  1. Is mysql support timestamp(9)?
  2. The error message should like "Invalid mysql timestamp precision".

}
}

private static TimestampType getTimestampType(int precision) {
if (precision == 0) return TimestampType.TIMESTAMP_SECONDS;
if (precision <= 3) return TimestampType.TIMESTAMP_MILLIS;
if (precision <= 6) return TimestampType.TIMESTAMP_MICROS;
return TimestampType.TIMESTAMP_NANOS;
switch (precision) {
case 0:
return TimestampType.TIMESTAMP_SECONDS;
case 3:
return TimestampType.TIMESTAMP_MILLIS;
case 6:
return TimestampType.TIMESTAMP_MICROS;
case 9:
return TimestampType.TIMESTAMP_NANOS;
default:
throw new TrinoException(
GravitinoErrorCode.GRAVITINO_ILLEGAL_ARGUMENT,
"Invalid timestamp precision: " + precision + ". Valid values are 0, 3, 6, 9");
}
}

private static TimeType getTimeType(int precision) {
if (precision == 0) return TimeType.TIME_SECONDS;
if (precision <= 3) return TimeType.TIME_MILLIS;
if (precision <= 6) return TimeType.TIME_MICROS;
return TimeType.TIME_NANOS;
switch (precision) {
case 0:
return TimeType.TIME_SECONDS;
case 3:
return TimeType.TIME_MILLIS;
case 6:
return TimeType.TIME_MICROS;
case 9:
return TimeType.TIME_NANOS;
default:
throw new TrinoException(
GravitinoErrorCode.GRAVITINO_ILLEGAL_ARGUMENT,
"Invalid time precision: " + precision + ". Valid values are 0, 3, 6, 9");
}
}

@Override
Expand Down