predator4ann commented on code in PR #6657: URL: https://github.com/apache/gravitino/pull/6657#discussion_r2000136798
########## trino-connector/trino-connector/src/main/java/org/apache/gravitino/trino/connector/catalog/jdbc/mysql/MySQLDataTypeTransformer.java: ########## @@ -45,18 +45,36 @@ public io.trino.spi.type.Type getTrinoType(Type type) { return io.trino.spi.type.VarcharType.createUnboundedVarcharType(); } else if (Name.TIMESTAMP == type.name()) { Types.TimestampType timestampType = (Types.TimestampType) type; - if (timestampType.hasTimeZone()) { - return TimestampWithTimeZoneType.TIMESTAMP_TZ_SECONDS; - } else { - return TimestampType.TIMESTAMP_SECONDS; - } + return timestampType.hasTimeZone() + ? getTimestampWithTimeZoneType(timestampType.precision()) + : getTimestampType(timestampType.precision()); } else if (Name.TIME == type.name()) { - return TimeType.TIME_SECONDS; + return getTimeType(((Types.TimeType) type).precision()); } - return super.getTrinoType(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; + } + + private static TimestampType getTimestampType(int precision) { Review Comment: @mchades Hello, I have checked the DataTypeTransformer code of Iceberg, Hive, and MySQL. It seems that the current changes are consistent with the previous behavior. Can you please confirm it again? Or is there anything I haven't considered? ```java // HiveDataTypeTransformer @Override public io.trino.spi.type.Type getTrinoType(Type type) { if ((Type.Name.TIMESTAMP == type.name() && ((Types.TimestampType) type).hasTimeZone()) || Type.Name.TIME == type.name()) { throw new TrinoException( GravitinoErrorCode.GRAVITINO_UNSUPPORTED_GRAVITINO_DATATYPE, "Unsupported gravitino datatype: " + type); } return super.getTrinoType(type); } // IcebergDataTypeTransformer @Override public io.trino.spi.type.Type getTrinoType(Type type) { if (Name.FIXED == type.name()) { return VarbinaryType.VARBINARY; } else if (Name.TIME == type.name()) { return TimeType.TIME_MICROS; } else if (Name.TIMESTAMP == type.name()) { Types.TimestampType timestampType = (Types.TimestampType) type; if (timestampType.hasTimeZone()) { return TimestampWithTimeZoneType.TIMESTAMP_TZ_MICROS; } else { return TimestampType.TIMESTAMP_MICROS; } } return super.getTrinoType(type); } // MySQLDataTypeTransformer @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 TimestampWithTimeZoneType.TIMESTAMP_TZ_SECONDS; } else { return TimestampType.TIMESTAMP_SECONDS; } } else if (Name.TIME == type.name()) { return TimeType.TIME_SECONDS; } return super.getTrinoType(type); } ``` -- 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: commits-unsubscr...@gravitino.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org