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 TestTrinoGlueCatalog.testListTables #20325

Merged
Merged
Changes from 1 commit
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 @@ -29,6 +29,7 @@
import io.trino.spi.security.PrincipalType;
import io.trino.spi.security.TrinoPrincipal;
import io.trino.spi.type.VarcharType;
import io.trino.util.AutoCloseableCloser;
import org.apache.iceberg.NullOrder;
import org.apache.iceberg.PartitionSpec;
import org.apache.iceberg.Schema;
Expand Down Expand Up @@ -391,39 +392,46 @@ public void testListTables()
{
TrinoCatalog catalog = createTrinoCatalog(false);
TrinoPrincipal principal = new TrinoPrincipal(PrincipalType.USER, SESSION.getUser());
String ns1 = "ns1";
String ns2 = "ns2";

catalog.createNamespace(SESSION, ns1, defaultNamespaceProperties(ns1), principal);
catalog.createNamespace(SESSION, ns2, defaultNamespaceProperties(ns2), principal);
SchemaTableName table1 = new SchemaTableName(ns1, "t1");
SchemaTableName table2 = new SchemaTableName(ns2, "t2");
catalog.newCreateTableTransaction(
SESSION,
table1,
new Schema(Types.NestedField.of(1, true, "col1", Types.LongType.get())),
PartitionSpec.unpartitioned(),
SortOrder.unsorted(),
arbitraryTableLocation(catalog, SESSION, table1),
ImmutableMap.of())
.commitTransaction();

catalog.newCreateTableTransaction(
SESSION,
table2,
new Schema(Types.NestedField.of(1, true, "col1", Types.LongType.get())),
PartitionSpec.unpartitioned(),
SortOrder.unsorted(),
arbitraryTableLocation(catalog, SESSION, table2),
ImmutableMap.of())
.commitTransaction();

// No namespace provided, all tables across all namespaces should be returned
assertThat(catalog.listTables(SESSION, Optional.empty())).containsAll(ImmutableList.of(table1, table2));
// Namespace is provided and exists
assertThat(catalog.listTables(SESSION, Optional.of(ns1))).isEqualTo(ImmutableList.of(table1));
// Namespace is provided and does not exist
assertThat(catalog.listTables(SESSION, Optional.of("non_existing"))).isEmpty();

try (AutoCloseableCloser closer = AutoCloseableCloser.create()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better than finally :)

String ns1 = "ns1" + randomNameSuffix();
String ns2 = "ns2" + randomNameSuffix();
catalog.createNamespace(SESSION, ns1, defaultNamespaceProperties(ns1), principal);
closer.register(() -> catalog.dropNamespace(SESSION, ns1));
catalog.createNamespace(SESSION, ns2, defaultNamespaceProperties(ns2), principal);
closer.register(() -> catalog.dropNamespace(SESSION, ns2));

SchemaTableName table1 = new SchemaTableName(ns1, "t1");
SchemaTableName table2 = new SchemaTableName(ns2, "t2");
catalog.newCreateTableTransaction(
SESSION,
table1,
new Schema(Types.NestedField.of(1, true, "col1", Types.LongType.get())),
PartitionSpec.unpartitioned(),
SortOrder.unsorted(),
arbitraryTableLocation(catalog, SESSION, table1),
ImmutableMap.of())
.commitTransaction();
closer.register(() -> catalog.dropTable(SESSION, table1));

catalog.newCreateTableTransaction(
SESSION,
table2,
new Schema(Types.NestedField.of(1, true, "col1", Types.LongType.get())),
PartitionSpec.unpartitioned(),
SortOrder.unsorted(),
arbitraryTableLocation(catalog, SESSION, table2),
ImmutableMap.of())
.commitTransaction();
closer.register(() -> catalog.dropTable(SESSION, table2));

// No namespace provided, all tables across all namespaces should be returned
assertThat(catalog.listTables(SESSION, Optional.empty())).containsAll(ImmutableList.of(table1, table2));
// Namespace is provided and exists
assertThat(catalog.listTables(SESSION, Optional.of(ns1))).isEqualTo(ImmutableList.of(table1));
// Namespace is provided and does not exist
assertThat(catalog.listTables(SESSION, Optional.of("non_existing"))).isEmpty();
}
}

private String arbitraryTableLocation(TrinoCatalog catalog, ConnectorSession session, SchemaTableName schemaTableName)
Expand Down