From d80e49aa3ebf4a98aa3a1a726508ba903e66aafb Mon Sep 17 00:00:00 2001 From: Rebecca Schlussel Date: Mon, 4 Mar 2024 12:14:50 -0500 Subject: [PATCH] Consolidate error handling for ParquetPageSourceFactory create a utility method so we can share the error handling code between aggregated and batch page source factories. --- .../ParquetAggregatedPageSourceFactory.java | 36 ++----------------- .../parquet/ParquetPageSourceFactory.java | 34 ++---------------- 2 files changed, 4 insertions(+), 66 deletions(-) diff --git a/presto-hive/src/main/java/com/facebook/presto/hive/parquet/ParquetAggregatedPageSourceFactory.java b/presto-hive/src/main/java/com/facebook/presto/hive/parquet/ParquetAggregatedPageSourceFactory.java index 8c9bbc9138e30..7144141e289c4 100644 --- a/presto-hive/src/main/java/com/facebook/presto/hive/parquet/ParquetAggregatedPageSourceFactory.java +++ b/presto-hive/src/main/java/com/facebook/presto/hive/parquet/ParquetAggregatedPageSourceFactory.java @@ -22,39 +22,29 @@ import com.facebook.presto.hive.HiveFileContext; import com.facebook.presto.hive.HiveFileSplit; import com.facebook.presto.hive.metastore.Storage; -import com.facebook.presto.parquet.ParquetCorruptionException; import com.facebook.presto.parquet.ParquetDataSource; import com.facebook.presto.parquet.cache.ParquetMetadataSource; import com.facebook.presto.spi.ConnectorPageSource; import com.facebook.presto.spi.ConnectorSession; -import com.facebook.presto.spi.PrestoException; import com.facebook.presto.spi.function.StandardFunctionResolution; import com.google.common.collect.ImmutableSet; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.security.AccessControlException; -import org.apache.parquet.crypto.HiddenColumnException; import org.apache.parquet.crypto.InternalFileDecryptor; import org.apache.parquet.hadoop.metadata.ParquetMetadata; import javax.inject.Inject; -import java.io.FileNotFoundException; import java.io.IOException; import java.util.List; import java.util.Optional; import java.util.Set; import static com.facebook.presto.hive.HiveCommonSessionProperties.getReadNullMaskedParquetEncryptedValue; -import static com.facebook.presto.hive.HiveErrorCode.HIVE_BAD_DATA; -import static com.facebook.presto.hive.HiveErrorCode.HIVE_CANNOT_OPEN_SPLIT; -import static com.facebook.presto.hive.HiveErrorCode.HIVE_MISSING_DATA; +import static com.facebook.presto.hive.orc.OrcPageSourceFactoryUtils.mapToPrestoException; import static com.facebook.presto.hive.parquet.HdfsParquetDataSource.buildHdfsParquetDataSource; import static com.facebook.presto.hive.parquet.ParquetPageSourceFactory.createDecryptor; -import static com.facebook.presto.spi.StandardErrorCode.PERMISSION_DENIED; -import static com.google.common.base.Strings.nullToEmpty; -import static java.lang.String.format; import static java.util.Objects.requireNonNull; public class ParquetAggregatedPageSourceFactory @@ -154,29 +144,7 @@ public static ConnectorPageSource createParquetPageSource( } catch (IOException ignored) { } - if (e instanceof PrestoException) { - throw (PrestoException) e; - } - if (e instanceof ParquetCorruptionException) { - throw new PrestoException(HIVE_BAD_DATA, e); - } - if (e instanceof AccessControlException) { - throw new PrestoException(PERMISSION_DENIED, e.getMessage(), e); - } - if (nullToEmpty(e.getMessage()).trim().equals("Filesystem closed") || - e instanceof FileNotFoundException) { - throw new PrestoException(HIVE_CANNOT_OPEN_SPLIT, e); - } - String message = format("Error opening Hive split %s (offset=%s, length=%s): %s", path, fileSplit.getStart(), fileSplit.getLength(), e.getMessage()); - if (e.getClass().getSimpleName().equals("BlockMissingException")) { - throw new PrestoException(HIVE_MISSING_DATA, message, e); - } - if (e instanceof HiddenColumnException) { - message = format("User does not have access to encryption key for encrypted column = %s. If returning 'null' for encrypted " + - "columns is acceptable to your query, please add 'set session hive.read_null_masked_parquet_encrypted_value_enabled=true' before your query", ((HiddenColumnException) e).getColumn()); - throw new PrestoException(PERMISSION_DENIED, message, e); - } - throw new PrestoException(HIVE_CANNOT_OPEN_SPLIT, message, e); + throw mapToPrestoException(e, path, fileSplit); } } } diff --git a/presto-hive/src/main/java/com/facebook/presto/hive/parquet/ParquetPageSourceFactory.java b/presto-hive/src/main/java/com/facebook/presto/hive/parquet/ParquetPageSourceFactory.java index 656761451c76d..efbca4fe040f6 100644 --- a/presto-hive/src/main/java/com/facebook/presto/hive/parquet/ParquetPageSourceFactory.java +++ b/presto-hive/src/main/java/com/facebook/presto/hive/parquet/ParquetPageSourceFactory.java @@ -31,7 +31,6 @@ import com.facebook.presto.hive.metastore.Storage; import com.facebook.presto.memory.context.AggregatedMemoryContext; import com.facebook.presto.parquet.Field; -import com.facebook.presto.parquet.ParquetCorruptionException; import com.facebook.presto.parquet.ParquetDataSource; import com.facebook.presto.parquet.RichColumnDescriptor; import com.facebook.presto.parquet.cache.ParquetMetadataSource; @@ -49,11 +48,9 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FSDataInputStream; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.security.AccessControlException; import org.apache.parquet.column.ColumnDescriptor; import org.apache.parquet.crypto.DecryptionPropertiesFactory; import org.apache.parquet.crypto.FileDecryptionProperties; -import org.apache.parquet.crypto.HiddenColumnException; import org.apache.parquet.crypto.InternalFileDecryptor; import org.apache.parquet.hadoop.metadata.BlockMetaData; import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData; @@ -69,7 +66,6 @@ import javax.inject.Inject; -import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -105,11 +101,9 @@ import static com.facebook.presto.hive.HiveCommonSessionProperties.isParquetBatchReaderVerificationEnabled; import static com.facebook.presto.hive.HiveCommonSessionProperties.isParquetBatchReadsEnabled; import static com.facebook.presto.hive.HiveCommonSessionProperties.isUseParquetColumnNames; -import static com.facebook.presto.hive.HiveErrorCode.HIVE_BAD_DATA; -import static com.facebook.presto.hive.HiveErrorCode.HIVE_CANNOT_OPEN_SPLIT; -import static com.facebook.presto.hive.HiveErrorCode.HIVE_MISSING_DATA; import static com.facebook.presto.hive.HiveErrorCode.HIVE_PARTITION_SCHEMA_MISMATCH; import static com.facebook.presto.hive.HiveSessionProperties.columnIndexFilterEnabled; +import static com.facebook.presto.hive.orc.OrcPageSourceFactoryUtils.mapToPrestoException; import static com.facebook.presto.hive.parquet.HdfsParquetDataSource.buildHdfsParquetDataSource; import static com.facebook.presto.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext; import static com.facebook.presto.parquet.ParquetTypeUtils.columnPathFromSubfield; @@ -121,9 +115,7 @@ import static com.facebook.presto.parquet.ParquetTypeUtils.nestedColumnPath; import static com.facebook.presto.parquet.predicate.PredicateUtils.buildPredicate; import static com.facebook.presto.parquet.predicate.PredicateUtils.predicateMatches; -import static com.facebook.presto.spi.StandardErrorCode.PERMISSION_DENIED; import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Strings.nullToEmpty; import static java.lang.String.format; import static java.util.Objects.requireNonNull; import static org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector.Category.PRIMITIVE; @@ -325,29 +317,7 @@ else if (getParquetType(type, fileSchema, useParquetColumnNames, column, tableNa } catch (IOException ignored) { } - if (e instanceof PrestoException) { - throw (PrestoException) e; - } - if (e instanceof ParquetCorruptionException) { - throw new PrestoException(HIVE_BAD_DATA, e); - } - if (e instanceof AccessControlException) { - throw new PrestoException(PERMISSION_DENIED, e.getMessage(), e); - } - if (nullToEmpty(e.getMessage()).trim().equals("Filesystem closed") || - e instanceof FileNotFoundException) { - throw new PrestoException(HIVE_CANNOT_OPEN_SPLIT, e); - } - String message = format("Error opening Hive split %s (offset=%s, length=%s): %s", path, fileSplit.getStart(), fileSplit.getLength(), e.getMessage()); - if (e.getClass().getSimpleName().equals("BlockMissingException")) { - throw new PrestoException(HIVE_MISSING_DATA, message, e); - } - if (e instanceof HiddenColumnException) { - message = format("User does not have access to encryption key for encrypted column = %s. If returning 'null' for encrypted " + - "columns is acceptable to your query, please add 'set session hive.read_null_masked_parquet_encrypted_value_enabled=true' before your query", ((HiddenColumnException) e).getColumn()); - throw new PrestoException(PERMISSION_DENIED, message, e); - } - throw new PrestoException(HIVE_CANNOT_OPEN_SPLIT, message, e); + throw mapToPrestoException(e, path, fileSplit); } }