-
Notifications
You must be signed in to change notification settings - Fork 3k
Core: Add tests for catalogs supporting empty namespaces #9890
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -500,6 +500,10 @@ private JdbcUtil() {} | |
|
|
||
| static Namespace stringToNamespace(String namespace) { | ||
| Preconditions.checkArgument(namespace != null, "Invalid namespace %s", namespace); | ||
| if (namespace.isEmpty()) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. previously this method would return the identifier as I guess the question here is: is
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think they should be treated the same, I also hope it doesn't come up very often |
||
| return Namespace.empty(); | ||
| } | ||
|
|
||
| return Namespace.of(Iterables.toArray(SPLITTER_DOT.split(namespace), String.class)); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
| import static org.assertj.core.api.Assertions.setMaxStackTraceElementsDisplayed; | ||
| import static org.assertj.core.api.Assumptions.assumeThat; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.UncheckedIOException; | ||
|
|
@@ -181,6 +182,10 @@ protected boolean supportsNamesWithDot() { | |
| return true; | ||
| } | ||
|
|
||
| protected boolean supportsEmptyNamespace() { | ||
| return false; | ||
| } | ||
|
|
||
| @Test | ||
| public void testCreateNamespace() { | ||
| C catalog = catalog(); | ||
|
|
@@ -976,6 +981,74 @@ public void testListTables() { | |
| assertEmpty("Should not contain ns_2.table_1 after drop", catalog, ns2); | ||
| } | ||
|
|
||
| @Test | ||
| public void listNamespacesWithEmptyNamespace() { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this behavior applies for all catalogs |
||
| catalog().createNamespace(NS); | ||
|
|
||
| assertThat(catalog().namespaceExists(Namespace.empty())).isFalse(); | ||
| assertThat(catalog().listNamespaces()).contains(NS).doesNotContain(Namespace.empty()); | ||
| assertThat(catalog().listNamespaces(Namespace.empty())) | ||
| .contains(NS) | ||
| .doesNotContain(Namespace.empty()); | ||
| } | ||
|
|
||
| @Test | ||
| public void createAndDropEmptyNamespace() { | ||
| assumeThat(supportsEmptyNamespace()) | ||
| .as("Only valid for catalogs that support creating/dropping empty namespaces") | ||
| .isTrue(); | ||
|
|
||
| assertThat(catalog().namespaceExists(Namespace.empty())).isFalse(); | ||
| catalog().createNamespace(Namespace.empty()); | ||
| assertThat(catalog().namespaceExists(Namespace.empty())).isTrue(); | ||
|
|
||
| // TODO: if a catalog supports creating an empty namespace, what should be the expected behavior | ||
| // when listing all namespaces? | ||
| assertThat(catalog().listNamespaces()).isEmpty(); | ||
| assertThat(catalog().listNamespaces(Namespace.empty())).isEmpty(); | ||
|
|
||
| catalog().dropNamespace(Namespace.empty()); | ||
| assertThat(catalog().namespaceExists(Namespace.empty())).isFalse(); | ||
| } | ||
|
|
||
| @Test | ||
| public void namespacePropertiesOnEmptyNamespace() { | ||
| assumeThat(supportsEmptyNamespace()) | ||
| .as("Only valid for catalogs that support properties on empty namespaces") | ||
| .isTrue(); | ||
|
|
||
| catalog().createNamespace(Namespace.empty()); | ||
|
|
||
| Map<String, String> properties = ImmutableMap.of("owner", "user", "created-at", "sometime"); | ||
| catalog().setProperties(Namespace.empty(), properties); | ||
|
|
||
| assertThat(catalog().loadNamespaceMetadata(Namespace.empty())).containsAllEntriesOf(properties); | ||
|
|
||
| catalog().removeProperties(Namespace.empty(), ImmutableSet.of("owner")); | ||
| assertThat(catalog().loadNamespaceMetadata(Namespace.empty())) | ||
| .containsAllEntriesOf(ImmutableMap.of("created-at", "sometime")); | ||
| } | ||
|
|
||
| @Test | ||
| public void listTablesInEmptyNamespace() { | ||
| assumeThat(supportsEmptyNamespace()) | ||
| .as("Only valid for catalogs that support listing tables in empty namespaces") | ||
| .isTrue(); | ||
|
|
||
| if (requiresNamespaceCreate()) { | ||
| catalog().createNamespace(Namespace.empty()); | ||
| catalog().createNamespace(NS); | ||
| } | ||
|
|
||
| TableIdentifier table1 = TableIdentifier.of(Namespace.empty(), "table_1"); | ||
| TableIdentifier table2 = TableIdentifier.of(NS, "table_2"); | ||
|
|
||
| catalog().buildTable(table1, SCHEMA).create(); | ||
| catalog().buildTable(table2, SCHEMA).create(); | ||
|
|
||
| assertThat(catalog().listTables(Namespace.empty())).containsExactly(table1); | ||
| } | ||
|
|
||
| @Test | ||
| public void testUpdateTableSchema() { | ||
| C catalog = catalog(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,12 +103,12 @@ protected JdbcCatalog catalog() { | |
| } | ||
|
|
||
| @Override | ||
| protected boolean supportsNamespaceProperties() { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Intellij flags this because |
||
| protected boolean supportsNestedNamespaces() { | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean supportsNestedNamespaces() { | ||
| protected boolean supportsEmptyNamespace() { | ||
| return true; | ||
| } | ||
|
|
||
|
|
@@ -763,11 +763,11 @@ public void testListNamespace() { | |
|
|
||
| List<Namespace> nsp3 = catalog.listNamespaces(); | ||
| Set<String> tblSet2 = Sets.newHashSet(nsp3.stream().map(Namespace::toString).iterator()); | ||
| assertThat(tblSet2).hasSize(5).contains("db", "db2", "d_", "d%", ""); | ||
| assertThat(tblSet2).hasSize(4).contains("db", "db2", "d_", "d%"); | ||
|
|
||
| List<Namespace> nsp4 = catalog.listNamespaces(); | ||
| Set<String> tblSet3 = Sets.newHashSet(nsp4.stream().map(Namespace::toString).iterator()); | ||
| assertThat(tblSet3).hasSize(5).contains("db", "db2", "d_", "d%", ""); | ||
| assertThat(tblSet3).hasSize(4).contains("db", "db2", "d_", "d%"); | ||
|
|
||
| List<Namespace> nsp5 = catalog.listNamespaces(Namespace.of("d_")); | ||
| assertThat(nsp5).hasSize(1); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -143,4 +143,10 @@ public void testV0toV1SqlStatements() throws Exception { | |
| assertThat(updated).isEqualTo(1); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void emptyNamespaceInIdentifier() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| assertThat(JdbcUtil.stringToTableIdentifier("", "tblName")) | ||
| .isEqualTo(TableIdentifier.of(Namespace.empty(), "tblName")); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this would previously fail in L303 when calling
listNamespaces(Namespace.empty())There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So does this one support empty namespaces or not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering what the behavior should be here, since it is a valid namespace so shouldn't we be able to list it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes,
InMemoryCatalogsupports empty namespaces and this comes back to the TODO I added in https://github.com/apache/iceberg/pull/9890/files#diff-de393039ffcf049ebb22892ac1b9aad88d53274c1e86431b45e776e4568246f8R1037 to determine what the listing behavior with empty namespaces should be