Skip to content

Commit

Permalink
[hive] Determine timestamp ltz type based on hive runtime version (#4571
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Zouxxyy authored Nov 22, 2024
1 parent 89f97c7 commit be54d7d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public TypeInfo visit(TimestampType timestampType) {

@Override
public TypeInfo visit(LocalZonedTimestampType localZonedTimestampType) {
return LocalZonedTimestampTypeUtils.toHiveType(localZonedTimestampType);
return LocalZonedTimestampTypeUtils.hiveLocalZonedTimestampType();
}

@Override
Expand Down Expand Up @@ -254,7 +254,7 @@ static DataType visit(TypeInfo type, HiveToPaimonTypeVisitor visitor) {
}

public DataType atomic(TypeInfo atomic) {
if (LocalZonedTimestampTypeUtils.isLocalZonedTimestampType(atomic)) {
if (LocalZonedTimestampTypeUtils.isHiveLocalZonedTimestampType(atomic)) {
return DataTypes.TIMESTAMP_WITH_LOCAL_TIME_ZONE();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,27 @@
import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo;
import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;

/** To maintain compatibility with Hive 3. */
import java.lang.reflect.Field;

/**
* Utils to convert between Hive TimestampLocalTZTypeInfo and Paimon {@link
* LocalZonedTimestampType}, using reflection to solve compatibility between Hive 2 and Hive 3.
*/
public class LocalZonedTimestampTypeUtils {

public static boolean isLocalZonedTimestampType(TypeInfo hiveTypeInfo) {
return false;
public static boolean isHiveLocalZonedTimestampType(TypeInfo hiveTypeInfo) {
return "org.apache.hadoop.hive.serde2.typeinfo.TimestampLocalTZTypeInfo"
.equals(hiveTypeInfo.getClass().getName());
}

public static TypeInfo toHiveType(LocalZonedTimestampType paimonType) {
return TypeInfoFactory.timestampTypeInfo;
public static TypeInfo hiveLocalZonedTimestampType() {
try {
Class<?> typeInfoFactoryClass =
Class.forName("org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory");
Field field = typeInfoFactoryClass.getField("timestampLocalTZTypeInfo");
return (TypeInfo) field.get(null);
} catch (Exception e) {
return TypeInfoFactory.timestampTypeInfo;
}
}
}

This file was deleted.

0 comments on commit be54d7d

Please sign in to comment.