diqiu50 commented on code in PR #6657:
URL: https://github.com/apache/gravitino/pull/6657#discussion_r2055520598
##########
trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/catalog/jdbc/mysql/MySQLDataTypeTransformer.java:
##########
@@ -38,23 +38,72 @@ public class MySQLDataTypeTransformer extends
GeneralDataTypeTransformer {
// column should be less than 16383. For more details, please refer to
// https://dev.mysql.com/doc/refman/8.0/en/char.html
private static final int MYSQL_VARCHAR_LENGTH_LIMIT = 16383;
+ private static final int TIMESTAMP_PRECISION_SECONDS = 0;
+ private static final int TIMESTAMP_PRECISION_MILLIS = 3;
+ private static final int TIMESTAMP_PRECISION_MICROS = 6;
@Override
public io.trino.spi.type.Type getTrinoType(Type type) {
if (type.name() == Name.STRING) {
return io.trino.spi.type.VarcharType.createUnboundedVarcharType();
} else if (Name.TIMESTAMP == type.name()) {
Types.TimestampType timestampType = (Types.TimestampType) type;
- if (timestampType.hasTimeZone()) {
+ return timestampType.hasTimeZone()
+ ? getTimestampWithTimeZoneType(timestampType)
+ : getTimestampType(timestampType);
+ } else if (Name.TIME == type.name()) {
+ return getTimeType(((Types.TimeType) type));
+ }
+ return super.getTrinoType(type);
+ }
+
+ private static TimestampWithTimeZoneType getTimestampWithTimeZoneType(
+ Types.TimestampType timestampType) {
+ int precision = timestampType.precision().orElse(0);
+ switch (precision) {
+ case TIMESTAMP_PRECISION_SECONDS:
return TimestampWithTimeZoneType.TIMESTAMP_TZ_SECONDS;
- } else {
+ case TIMESTAMP_PRECISION_MILLIS:
+ return TimestampWithTimeZoneType.TIMESTAMP_TZ_MILLIS;
+ case TIMESTAMP_PRECISION_MICROS:
+ return TimestampWithTimeZoneType.TIMESTAMP_TZ_MICROS;
+ default:
+ throw new TrinoException(
+ GravitinoErrorCode.GRAVITINO_ILLEGAL_ARGUMENT,
+ "Invalid MySQL timestamp precision: " + precision + ". Valid
values are 0, 3, 6");
+ }
+ }
+
+ private static TimestampType getTimestampType(Types.TimestampType
timestampType) {
+ int precision = timestampType.precision().orElse(0);
+ switch (precision) {
+ case TIMESTAMP_PRECISION_SECONDS:
return TimestampType.TIMESTAMP_SECONDS;
- }
- } else if (Name.TIME == type.name()) {
- return TimeType.TIME_SECONDS;
+ case TIMESTAMP_PRECISION_MILLIS:
+ return TimestampType.TIMESTAMP_MILLIS;
+ case TIMESTAMP_PRECISION_MICROS:
+ return TimestampType.TIMESTAMP_MICROS;
+ default:
+ throw new TrinoException(
+ GravitinoErrorCode.GRAVITINO_ILLEGAL_ARGUMENT,
+ "Invalid MySQL datetime precision: " + precision + ". Valid values
are 0, 3, 6");
}
+ }
- return super.getTrinoType(type);
+ private static TimeType getTimeType(Types.TimeType timeType) {
+ int precision = timeType.precision().orElse(0);
Review Comment:
using TIMESTAMP_PRECISION_SECONDS
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]