diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/thrift/ThriftMetastoreUtil.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/thrift/ThriftMetastoreUtil.java index c646aee968e5..7fd79ede9317 100644 --- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/thrift/ThriftMetastoreUtil.java +++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/metastore/thrift/ThriftMetastoreUtil.java @@ -485,8 +485,12 @@ public static Partition fromMetastoreApiPartition(io.trino.hive.thrift.metastore if (storageDescriptor == null) { throw new TrinoException(HIVE_INVALID_METADATA, "Partition does not contain a storage descriptor: " + partition); } + List schema = storageDescriptor.getCols(); + if (schema == null) { + throw new TrinoException(HIVE_INVALID_METADATA, "Partition storage descriptor does not contain columns to derive a schema: " + partition); + } - return fromMetastoreApiPartition(partition, storageDescriptor.getCols()); + return fromMetastoreApiPartition(partition, schema); } public static Partition fromMetastoreApiPartition(io.trino.hive.thrift.metastore.Partition partition, List schema) diff --git a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/metastore/thrift/TestThriftMetastoreUtil.java b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/metastore/thrift/TestThriftMetastoreUtil.java index 951244f7d1fc..e2297be2f189 100644 --- a/plugin/trino-hive/src/test/java/io/trino/plugin/hive/metastore/thrift/TestThriftMetastoreUtil.java +++ b/plugin/trino-hive/src/test/java/io/trino/plugin/hive/metastore/thrift/TestThriftMetastoreUtil.java @@ -41,6 +41,7 @@ import io.trino.metastore.IntegerStatistics; import io.trino.metastore.Partition; import io.trino.metastore.Table; +import io.trino.plugin.hive.HiveErrorCode; import io.trino.plugin.hive.metastore.MetastoreUtil; import io.trino.spi.security.RoleGrant; import io.trino.spi.security.TrinoPrincipal; @@ -82,6 +83,7 @@ import static io.trino.plugin.hive.util.SerdeConstants.SERIALIZATION_LIB; import static io.trino.spi.security.PrincipalType.ROLE; import static io.trino.spi.security.PrincipalType.USER; +import static io.trino.testing.assertions.TrinoExceptionAssert.assertTrinoExceptionThrownBy; import static org.assertj.core.api.Assertions.assertThat; public class TestThriftMetastoreUtil @@ -163,6 +165,25 @@ public class TestThriftMetastoreUtil 1234567893, TEST_STORAGE_DESCRIPTOR_WITH_UNSUPPORTED_FIELDS, ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3")); + private static final StorageDescriptor TEST_STORAGE_DESCRIPTOR_WITH_MISSING_COLUMNS = new StorageDescriptor( + null, + "hdfs://VOL1:9000/db_name/table_name", + "com.facebook.hive.orc.OrcInputFormat", + "com.facebook.hive.orc.OrcOutputFormat", + false, + 100, + new SerDeInfo("table_name", "com.facebook.hive.orc.OrcSerde", ImmutableMap.of("sdk1", "sdv1", "sdk2", "sdv2")), + null, + null, + ImmutableMap.of()); + private static final io.trino.hive.thrift.metastore.Partition TEST_PARTITION_WITH_MISSING_COLUMNS = new io.trino.hive.thrift.metastore.Partition( + ImmutableList.of("pk1v", "pk2v"), + "db_name", + "table_name", + 1234567892, + 1234567893, + TEST_STORAGE_DESCRIPTOR_WITH_MISSING_COLUMNS, + ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3")); static { TEST_STORAGE_DESCRIPTOR_WITH_UNSUPPORTED_FIELDS.setSkewedInfo(new SkewedInfo( @@ -237,6 +258,14 @@ public void testHiveSchemaCaseInsensitive() assertThat(actualPartition).isEqualTo(TEST_TABLE_METADATA); } + @Test + public void testHiveSchemaPartitionWithMissingColumns() + { + assertTrinoExceptionThrownBy(() -> ThriftMetastoreUtil.fromMetastoreApiPartition(TEST_PARTITION_WITH_MISSING_COLUMNS)) + .hasErrorCode(HiveErrorCode.HIVE_INVALID_METADATA) + .hasMessageContaining("Partition storage descriptor does not contain columns to derive a schema"); + } + @Test public void testLongStatsToColumnStatistics() {