World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#7098] Throw exception when converting timestamp with timezone to Hive type (#7103)
yunchi14d5328099b2
diff --git a/catalogs/hive-metastore-common/src/main/java/org/apache/gravitino/hive/converter/HiveDataTypeConverter.java b/catalogs/hive-metastore-common/src/main/java/org/apache/gravitino/hive/converter/HiveDataTypeConverter.javaindex 80c899ad23..bde5b6e134 100644--- a/catalogs/hive-metastore-common/src/main/java/org/apache/gravitino/hive/converter/HiveDataTypeConverter.java+++ b/catalogs/hive-metastore-common/src/main/java/org/apache/gravitino/hive/converter/HiveDataTypeConverter.java@@ -87,7 +87,17 @@ public class HiveDataTypeConverter implements DataTypeConverter<TypeInfo, Stringcase DATE:return getPrimitiveTypeInfo(DATE_TYPE_NAME);case TIMESTAMP:- return getPrimitiveTypeInfo(TIMESTAMP_TYPE_NAME);+ if (type instanceof Types.TimestampType) {+ Types.TimestampType tsType = (Types.TimestampType) type;+ // Timestamps are interpreted to be timezoneless in Hive:+ // https://hive.apache.org/docs/latest/languagemanual-types_27838462/#timestamps+ if (tsType.hasTimeZone()) {+ throw new UnsupportedOperationException(+ "Unsupported conversion: Please use the TIMESTAMP WITHOUT TIMEZONE type. TIMESTAMP WITH TIMEZONE type is not supported by Hive.");+ }+ return getPrimitiveTypeInfo(TIMESTAMP_TYPE_NAME);+ }+ throw new UnsupportedOperationException("Unknown timestamp type: " + type);case DECIMAL:Types.DecimalType decimalType = (Types.DecimalType) type;return getDecimalTypeInfo(decimalType.precision(), decimalType.scale());diff --git a/catalogs/hive-metastore-common/src/test/java/org/apache/gravitino/hive/converter/TestTypeConverter.java b/catalogs/hive-metastore-common/src/test/java/org/apache/gravitino/hive/converter/TestTypeConverter.javaindex 0b32b0c6e0..de6bd8272b 100644--- a/catalogs/hive-metastore-common/src/test/java/org/apache/gravitino/hive/converter/TestTypeConverter.java+++ b/catalogs/hive-metastore-common/src/test/java/org/apache/gravitino/hive/converter/TestTypeConverter.java@@ -91,6 +91,18 @@ public class TestTypeConverter {() -> CONVERTER.fromGravitino(Types.ExternalType.of(USER_DEFINED_TYPE)));}+ @Test+ public void testTimestampWithTimeZoneThrowsException() {+ Types.TimestampType timestampWithTimeZone = Types.TimestampType.withTimeZone();+ UnsupportedOperationException exception =+ Assertions.assertThrows(+ UnsupportedOperationException.class,+ () -> HiveDataTypeConverter.CONVERTER.fromGravitino(timestampWithTimeZone));+ Assertions.assertEquals(+ "Unsupported conversion: Please use the TIMESTAMP WITHOUT TIMEZONE type. TIMESTAMP WITH TIMEZONE type is not supported by Hive.",+ exception.getMessage());+ }+private void testConverter(String typeName) {TypeInfo hiveType = getTypeInfoFromTypeString(typeName);TypeInfo convertedType = CONVERTER.fromGravitino(CONVERTER.toGravitino(hiveType.getTypeName()));