Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hive] Determine timestamp ltz type based on hive runtime version #4571

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading