-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Core: Add tests for catalogs supporting empty namespaces #9890
Conversation
@@ -102,12 +102,12 @@ protected JdbcCatalog catalog() { | |||
} | |||
|
|||
@Override | |||
protected boolean supportsNamespaceProperties() { |
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.
Intellij flags this because supportsNamespaceProperties()
is true
by default in CatalogTests
, so no need to override this method here
@@ -140,17 +142,17 @@ protected boolean supportsNestedNamespaces() { | |||
return true; | |||
} | |||
|
|||
@Override | |||
protected boolean supportsNamespaceProperties() { | |||
return true; |
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.
Intellij flags this because supportsNamespaceProperties()
is true
by default in CatalogTests
, so no need to override this method here
a3ddfab
to
61cfa9d
Compare
61cfa9d
to
6fecd82
Compare
6fecd82
to
ea594d8
Compare
@@ -468,6 +468,10 @@ private JdbcUtil() {} | |||
|
|||
static Namespace stringToNamespace(String namespace) { | |||
Preconditions.checkArgument(namespace != null, "Invalid namespace %s", namespace); | |||
if (namespace.isEmpty()) { |
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.
previously this method would return the identifier as .tblName
instead of tblName
when using an empty namespace, because L475 passes an array with a single empty string to Namespace.of()
.
I guess the question here is: is Namespace.of("")
the same as Namespace.empty()
and should we maybe fix Namespace.of()
?
It seems there are currently no existing tests that would indicate what the correct behavior should be in this case
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.
I think they should be treated the same, I also hope it doesn't come up very often
3a9fde1
to
e4cee23
Compare
@@ -987,6 +991,38 @@ public void testListTables() { | |||
assertEmpty("Should not contain ns_2.table_1 after drop", catalog, ns2); | |||
} | |||
|
|||
@Test | |||
public void emptyNamespace() { |
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.
added this test because JDBC was previously returning namespace ""
(empty string) when listing all namespaces
|
||
// TODO this lists all available tables and deviates from the behavior in other catalogs and | ||
// should probably be fixed | ||
Assertions.assertThat(catalog().listTables(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.
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.
But nessie supports creating a table/view withing the empty namespace, which is a valid use case. If creating a table/view in an empty namespace is supported, then listing should be supported as well
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.
An empty namespace is not an "entity", right? Why would we want to "create" it?
That said, creating tables in the "empty" / "root" namespace should work with Nessie, IIRC.
core/src/main/java/org/apache/iceberg/inmemory/InMemoryCatalog.java
Outdated
Show resolved
Hide resolved
core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java
Outdated
Show resolved
Hide resolved
f062549
to
95b0416
Compare
@@ -987,6 +995,61 @@ public void testListTables() { | |||
assertEmpty("Should not contain ns_2.table_1 after drop", catalog, ns2); | |||
} | |||
|
|||
@Test | |||
public void listNamespacesWithEmptyNamespace() { |
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 behavior applies for all catalogs
95b0416
to
b6129ef
Compare
@@ -288,6 +288,7 @@ public List<Namespace> listNamespaces(Namespace namespace) throws NoSuchNamespac | |||
|
|||
List<Namespace> filteredNamespaces = | |||
namespaces.keySet().stream() | |||
.filter(n -> !n.isEmpty()) |
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, InMemoryCatalog
supports 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
Object[] v1 = row(NAMESPACE.toString(), "v1", false); | ||
Object[] v2 = row(NAMESPACE.toString(), "prefixV2", false); | ||
Object[] v3 = row(NAMESPACE.toString(), "prefixV3", false); | ||
assertThat(sql("SHOW VIEWS")).contains(v2, v3, v1, tempView); |
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.
nit: (ocd) It tares me up that you define v1, v2, v3 and then check contains v2, v3, v1
@@ -45,4 +47,10 @@ public void testFilterAndRemovePrefix() { | |||
|
|||
assertThat(expected).isEqualTo(actual); | |||
} | |||
|
|||
@Test | |||
public void emptyNamespaceInIdentifier() { |
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.
👍
Object[] v1 = row(NAMESPACE.toString(), "v1", false); | ||
Object[] v2 = row(NAMESPACE.toString(), "prefixV2", false); | ||
Object[] v3 = row(NAMESPACE.toString(), "prefixV3", false); | ||
assertThat(sql("SHOW VIEWS")).contains(v2, v3, v1, tempView); |
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.
the order here
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.
LGTM, only small issue with test rows being defined, 1, 2, 3 then used 2, 3, 1. I keep thinking there is a secret there but I know there isn't.
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions. |
6ae6aec
to
39f4033
Compare
39f4033
to
e02ef8a
Compare
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.
Looks good, thanks @nastra. Thanks @RussellSpitzer for the review, let's get this in and follow up on the TODO in a separate PR
From all the catalogs that extend
CatalogTests
, only Hive + REST don't support creating a table/view and also listing tables/views in an empty namespace.JDBC + InMemory do support that and therefore override the
supportsEmptyNamespace()
feature in their tests.Additionally, this PR also fixes listing tables/views for InMemory as previously this would list all available tables/views, instead of just the ones in that namespace.
I've decided to not adjust the Nessie tests, since the behavior deviates from the current behavior that can be found for JDBC + InMemory. While Nessie doesn't support creation/removal of empty namespaces, it does support creating a table/view in an empty namespace. Listing tables/views in an empty namespace returns all available tables/views.