This is an automated email from the ASF dual-hosted git repository.

mchades pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git


The following commit(s) were added to refs/heads/main by this push:
     new 14d5328099 [#7098] Throw exception when converting timestamp with 
timezone to Hive type (#7103)
14d5328099 is described below

commit 14d5328099b24222a8933945662c2887b54431d2
Author: yunchi <[email protected]>
AuthorDate: Tue Apr 29 18:47:35 2025 -0700

    [#7098] Throw exception when converting timestamp with timezone to Hive 
type (#7103)
    
    ### What changes were proposed in this pull request?
    
    - add case handling to `HiveDataTypeConverter`: if trying to convert
    gravitino timestamp with timezone to Hive, throws
    `UnsupportedOperationException`
    - add one more test case (timestamp with timezone) to
    `TestTypeConverter`
    
    ### Why are the changes needed?
    
    Fix: #7098
    
    ### Does this PR introduce _any_ user-facing change?
    
    No
    
    ### How was this patch tested?
    
    <img width="1204" alt="image"
    
src="https://github.com/user-attachments/assets/05461308-f89e-4c50-b916-9125cde43bcb";
    />
---
 .../gravitino/hive/converter/HiveDataTypeConverter.java      | 12 +++++++++++-
 .../apache/gravitino/hive/converter/TestTypeConverter.java   | 12 ++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

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.java
index 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, String
       case 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.java
index 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()));

Reply via email to