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

Fix NPE in ThriftMetastoreUtil to provide proper error message #23371

Merged
merged 1 commit into from
Sep 12, 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 @@ -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<FieldSchema> 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<FieldSchema> schema)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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()
{
Expand Down