Skip to content

Commit

Permalink
Fix listing Glue tables with null type
Browse files Browse the repository at this point in the history
  • Loading branch information
pajaks authored and ebyhr committed Feb 4, 2025
1 parent 5e32f69 commit b1d2302
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ private List<TableInfo> getTablesInternal(Consumer<Table> cacheTable, String dat
return glueTables.stream()
.map(table -> new TableInfo(
new SchemaTableName(databaseName, table.name()),
TableInfo.ExtendedRelationType.fromTableTypeAndComment(GlueConverter.getTableTypeNullable(table), table.parameters().get(TABLE_COMMENT))))
TableInfo.ExtendedRelationType.fromTableTypeAndComment(GlueConverter.getTableType(table), table.parameters().get(TABLE_COMMENT))))
.toList();
}
catch (EntityNotFoundException _) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import software.amazon.awssdk.services.glue.model.TableInput;

import java.nio.file.Path;
import java.util.List;
import java.util.Set;

import static io.trino.plugin.hive.metastore.glue.GlueMetastoreModule.createGlueClient;
Expand All @@ -47,6 +48,7 @@ public class TestHiveGlueMetadataListing
extends AbstractTestQueryFramework
{
public static final String FAILING_TABLE_WITH_NULL_STORAGE_DESCRIPTOR_NAME = "failing_table_with_null_storage_descriptor";
public static final String FAILING_TABLE_WITH_NULL_TYPE = "failing_table_with_null_type";
private static final Logger LOG = Logger.get(TestHiveGlueMetadataListing.class);
private static final String HIVE_CATALOG = "hive";
private final String tpchSchema = "test_tpch_schema_" + randomNameSuffix();
Expand Down Expand Up @@ -76,7 +78,7 @@ protected QueryRunner createQueryRunner()
queryRunner.execute("CREATE SCHEMA " + tpchSchema + " WITH (location = '" + dataDirectory.toUri() + "')");
copyTpchTables(queryRunner, "tpch", TINY_SCHEMA_NAME, hiveSession, ImmutableList.of(TpchTable.REGION, TpchTable.NATION));

createBrokenTable(dataDirectory);
createBrokenTables(dataDirectory);

return queryRunner;
}
Expand All @@ -103,38 +105,50 @@ public void testReadInformationSchema()
.add(TpchTable.REGION.getTableName())
.add(TpchTable.NATION.getTableName())
.add(FAILING_TABLE_WITH_NULL_STORAGE_DESCRIPTOR_NAME)
.add(FAILING_TABLE_WITH_NULL_TYPE)
.build();

assertThat(computeActual("SELECT table_name FROM hive.information_schema.tables").getOnlyColumnAsSet()).containsAll(expectedTables);
assertThat(computeActual("SELECT table_name FROM hive.information_schema.tables WHERE table_schema='" + tpchSchema + "'").getOnlyColumnAsSet()).containsAll(expectedTables);
assertThat(computeScalar("SELECT table_name FROM hive.information_schema.tables WHERE table_name = 'region' AND table_schema='" + tpchSchema + "'"))
.isEqualTo(TpchTable.REGION.getTableName());
assertQueryReturnsEmptyResult(format("SELECT table_name FROM hive.information_schema.tables WHERE table_name = '%s' AND table_schema='%s'", FAILING_TABLE_WITH_NULL_STORAGE_DESCRIPTOR_NAME, tpchSchema));
assertQueryReturnsEmptyResult(format("SELECT table_name FROM hive.information_schema.tables WHERE table_name = '%s' AND table_schema='%s'", FAILING_TABLE_WITH_NULL_TYPE, tpchSchema));

assertQuery("SELECT table_name, column_name from hive.information_schema.columns WHERE table_schema = '" + tpchSchema + "'",
"VALUES ('region', 'regionkey'), ('region', 'name'), ('region', 'comment'), ('nation', 'nationkey'), ('nation', 'name'), ('nation', 'regionkey'), ('nation', 'comment')");
assertQuery("SELECT table_name, column_name from hive.information_schema.columns WHERE table_name = 'region' AND table_schema='" + tpchSchema + "'",
"VALUES ('region', 'regionkey'), ('region', 'name'), ('region', 'comment')");
assertQueryReturnsEmptyResult(format("SELECT table_name FROM hive.information_schema.columns WHERE table_name = '%s' AND table_schema='%s'", FAILING_TABLE_WITH_NULL_STORAGE_DESCRIPTOR_NAME, tpchSchema));
assertQueryReturnsEmptyResult(format("SELECT table_name FROM hive.information_schema.columns WHERE table_name = '%s' AND table_schema='%s'", FAILING_TABLE_WITH_NULL_TYPE, tpchSchema));

assertThat(computeActual("SHOW TABLES FROM hive." + tpchSchema).getOnlyColumnAsSet()).isEqualTo(expectedTables);
}

private void createBrokenTable(Path dataDirectory)
private void createBrokenTables(Path dataDirectory)
{
TableInput nullStorageTable = TableInput.builder()
.name(FAILING_TABLE_WITH_NULL_STORAGE_DESCRIPTOR_NAME)
.tableType("HIVE")
.build();
TableInput nullTypeTable = TableInput.builder()
.name(FAILING_TABLE_WITH_NULL_TYPE)
.build();
createBrokenTable(List.of(nullStorageTable, nullTypeTable), dataDirectory);
}

private void createBrokenTable(List<TableInput> tablesInput, Path dataDirectory)
{
GlueHiveMetastoreConfig glueConfig = new GlueHiveMetastoreConfig()
.setDefaultWarehouseDir(dataDirectory.toString());
try (GlueClient glueClient = createGlueClient(glueConfig, ImmutableSet.of())) {
TableInput tableInput = TableInput.builder()
.name(FAILING_TABLE_WITH_NULL_STORAGE_DESCRIPTOR_NAME)
.tableType("HIVE")
.build();

CreateTableRequest createTableRequest = CreateTableRequest.builder()
.databaseName(tpchSchema)
.tableInput(tableInput)
.build();
glueClient.createTable(createTableRequest);
for (TableInput tableInput : tablesInput) {
CreateTableRequest createTableRequest = CreateTableRequest.builder()
.databaseName(tpchSchema)
.tableInput(tableInput)
.build();
glueClient.createTable(createTableRequest);
}
}
}
}

0 comments on commit b1d2302

Please sign in to comment.