From b9307bbc216c8c1fe26bf0a3bb9b8d9a0e293519 Mon Sep 17 00:00:00 2001 From: Yingjie Luan <1275963@gmail.com> Date: Thu, 23 Mar 2023 10:53:36 -0700 Subject: [PATCH] Remove duplicate getParquetType method from ParquetPageSourceFactory --- .../parquet/ParquetPageSourceFactory.java | 48 +++++++------------ 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/parquet/ParquetPageSourceFactory.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/parquet/ParquetPageSourceFactory.java index c9b2a23cfa96..ac7384a9bd90 100644 --- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/parquet/ParquetPageSourceFactory.java +++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/parquet/ParquetPageSourceFactory.java @@ -329,21 +329,9 @@ public static Optional getParquetMessageType(List return message; } - public static Optional getParquetType(GroupType groupType, boolean useParquetColumnNames, HiveColumnHandle column) - { - if (useParquetColumnNames) { - return Optional.ofNullable(getParquetTypeByName(column.getBaseColumnName(), groupType)); - } - if (column.getBaseHiveColumnIndex() < groupType.getFieldCount()) { - return Optional.of(groupType.getType(column.getBaseHiveColumnIndex())); - } - - return Optional.empty(); - } - public static Optional getColumnType(HiveColumnHandle column, MessageType messageType, boolean useParquetColumnNames) { - Optional columnType = getParquetType(messageType, useParquetColumnNames, column); + Optional columnType = getBaseColumnParquetType(column, messageType, useParquetColumnNames); if (columnType.isEmpty() || column.getHiveColumnProjectionInfo().isEmpty()) { return columnType; } @@ -453,13 +441,13 @@ public static TupleDomain getParquetTupleDomain( descriptor = descriptorsByPath.get(ImmutableList.of(columnHandle.getName())); } else { - org.apache.parquet.schema.Type parquetField = getParquetType(columnHandle, fileSchema, false); - if (parquetField == null || !parquetField.isPrimitive()) { + Optional parquetField = getBaseColumnParquetType(columnHandle, fileSchema, false); + if (parquetField.isEmpty() || !parquetField.get().isPrimitive()) { // Parquet file has fewer column than partition // Or the field is a complex type continue; } - descriptor = descriptorsByPath.get(ImmutableList.of(parquetField.getName())); + descriptor = descriptorsByPath.get(ImmutableList.of(parquetField.get().getName())); } if (descriptor != null) { predicate.put(descriptor, entry.getValue()); @@ -468,18 +456,6 @@ public static TupleDomain getParquetTupleDomain( return TupleDomain.withColumnDomains(predicate.buildOrThrow()); } - public static org.apache.parquet.schema.Type getParquetType(HiveColumnHandle column, MessageType messageType, boolean useParquetColumnNames) - { - if (useParquetColumnNames) { - return getParquetTypeByName(column.getBaseColumnName(), messageType); - } - - if (column.getBaseHiveColumnIndex() < messageType.getFieldCount()) { - return messageType.getType(column.getBaseHiveColumnIndex()); - } - return null; - } - public interface ParquetReaderProvider { ParquetReader createParquetReader(List fields) @@ -503,8 +479,8 @@ public static ConnectorPageSource createParquetPageSource( continue; } checkArgument(column.getColumnType() == REGULAR, "column type must be REGULAR: %s", column); - org.apache.parquet.schema.Type parquetType = getParquetType(column, fileSchema, useColumnNames); - if (parquetType == null) { + Optional parquetType = getBaseColumnParquetType(column, fileSchema, useColumnNames); + if (parquetType.isEmpty()) { pageSourceBuilder.addNullColumn(column.getBaseType()); continue; } @@ -521,4 +497,16 @@ public static ConnectorPageSource createParquetPageSource( return pageSourceBuilder.build(parquetReaderProvider.createParquetReader(parquetColumnFieldsBuilder.build())); } + + private static Optional getBaseColumnParquetType(HiveColumnHandle column, MessageType messageType, boolean useParquetColumnNames) + { + if (useParquetColumnNames) { + return Optional.ofNullable(getParquetTypeByName(column.getBaseColumnName(), messageType)); + } + if (column.getBaseHiveColumnIndex() < messageType.getFieldCount()) { + return Optional.of(messageType.getType(column.getBaseHiveColumnIndex())); + } + + return Optional.empty(); + } }