From ee473c0cff403400bbd072d152b18461ac03de5c Mon Sep 17 00:00:00 2001 From: praveenkrishna Date: Thu, 22 Jun 2023 11:55:53 +0530 Subject: [PATCH] Derive read column type from the TypeCoercer --- .../java/io/trino/plugin/hive/HivePageSourceProvider.java | 5 +++-- .../java/io/trino/plugin/hive/coercions/CoercionUtils.java | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HivePageSourceProvider.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HivePageSourceProvider.java index 14c80878e579..4cc269ce57b8 100644 --- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HivePageSourceProvider.java +++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HivePageSourceProvider.java @@ -71,6 +71,7 @@ import static io.trino.plugin.hive.HivePageSourceProvider.ColumnMapping.toColumnHandles; import static io.trino.plugin.hive.HivePageSourceProvider.ColumnMappingKind.PREFILLED; import static io.trino.plugin.hive.HiveSessionProperties.getTimestampPrecision; +import static io.trino.plugin.hive.coercions.CoercionUtils.createTypeFromCoercer; import static io.trino.plugin.hive.util.HiveBucketing.HiveBucketFilter; import static io.trino.plugin.hive.util.HiveBucketing.getHiveBucketFilter; import static io.trino.plugin.hive.util.HiveUtil.getPrefilledColumnValue; @@ -564,14 +565,14 @@ public static List toColumnHandles(List regular projectedColumn.getDereferenceIndices(), projectedColumn.getDereferenceNames(), fromHiveType, - fromHiveType.getType(typeManager, timestampPrecision)); + createTypeFromCoercer(typeManager, fromHiveType, columnHandle.getHiveType(), timestampPrecision)); }); return new HiveColumnHandle( columnHandle.getBaseColumnName(), columnHandle.getBaseHiveColumnIndex(), fromHiveTypeBase, - fromHiveTypeBase.getType(typeManager, timestampPrecision), + createTypeFromCoercer(typeManager, fromHiveTypeBase, columnHandle.getBaseHiveType(), timestampPrecision), newColumnProjectionInfo, columnHandle.getColumnType(), columnHandle.getComment()); diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/coercions/CoercionUtils.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/coercions/CoercionUtils.java index a77641c1d780..abbe99be9b4e 100644 --- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/coercions/CoercionUtils.java +++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/coercions/CoercionUtils.java @@ -68,6 +68,13 @@ public final class CoercionUtils { private CoercionUtils() {} + public static Type createTypeFromCoercer(TypeManager typeManager, HiveType fromHiveType, HiveType toHiveType, HiveTimestampPrecision timestampPrecision) + { + return createCoercer(typeManager, fromHiveType, toHiveType, timestampPrecision) + .map(TypeCoercer::getFromType) + .orElseGet(() -> fromHiveType.getType(typeManager, timestampPrecision)); + } + public static Optional> createCoercer(TypeManager typeManager, HiveType fromHiveType, HiveType toHiveType, HiveTimestampPrecision timestampPrecision) { if (fromHiveType.equals(toHiveType)) {