-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Core: Registering tables to nonexistent target namespace leads to metadata deletion in HiveCatalog #13434
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: Registering tables to nonexistent target namespace leads to metadata deletion in HiveCatalog #13434
Changes from all commits
90aa75c
aa1f797
25871ba
a4ba226
5c1f393
6438f16
8374e71
58e9711
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 |
|---|---|---|
|
|
@@ -173,7 +173,7 @@ private void createTable(String newMetadataLocation) throws SQLException, Interr | |
| if (PropertyUtil.propertyAsBoolean(catalogProperties, JdbcUtil.STRICT_MODE_PROPERTY, false) | ||
| && !JdbcUtil.namespaceExists(catalogName, connections, namespace)) { | ||
| throw new NoSuchNamespaceException( | ||
| "Cannot create table %s in catalog %s. Namespace %s does not exist", | ||
| "Cannot create table %s in catalog %s. Namespace does not exist: %s", | ||
|
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. Change the error message b/c assertThatThrownBy(
() ->
catalog().buildTable(TableIdentifier.of("non-existing", "table"), SCHEMA).create())
.isInstanceOf(NoSuchNamespaceException.class)
.hasMessageContaining("Namespace does not exist: non-existing"); |
||
| tableIdentifier, catalogName, namespace); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -174,6 +174,7 @@ public void testRenameTable() { | |
|
|
||
| @Test | ||
| public void testRegisterTable() { | ||
| ecsCatalog.createNamespace(Namespace.of("a")); | ||
|
Contributor
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. can you elaborate why this change is needed?
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. It is because
// From CatalogTests
@Test
public void testRegisterTable() {
C catalog = catalog();
if (requiresNamespaceCreate()) {
catalog.createNamespace(TABLE.namespace());
}
// omitted
} |
||
| TableIdentifier identifier = TableIdentifier.of("a", "t1"); | ||
| ecsCatalog.createTable(identifier, SCHEMA); | ||
| Table registeringTable = ecsCatalog.loadTable(identifier); | ||
|
|
@@ -191,6 +192,7 @@ public void testRegisterTable() { | |
|
|
||
| @Test | ||
| public void testRegisterExistingTable() { | ||
| ecsCatalog.createNamespace(Namespace.of("a")); | ||
| TableIdentifier identifier = TableIdentifier.of("a", "t1"); | ||
| ecsCatalog.createTable(identifier, SCHEMA); | ||
| Table registeringTable = ecsCatalog.loadTable(identifier); | ||
|
|
@@ -201,4 +203,15 @@ public void testRegisterExistingTable() { | |
| .hasMessage("Table already exists: a.t1"); | ||
| assertThat(ecsCatalog.dropTable(identifier, true)).isTrue(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testRegisterTableToNonExistingNamespace() { | ||
| TableIdentifier targetIdentifier = TableIdentifier.of("non-existing", "table"); | ||
| assertThatThrownBy( | ||
| () -> | ||
| ecsCatalog.registerTable( | ||
| targetIdentifier, "table_metadata_loc_from_different_catalogs")) | ||
| .isInstanceOf(NoSuchNamespaceException.class) | ||
| .hasMessageStartingWith("Cannot register table"); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,9 +72,7 @@ protected RESTCatalog initCatalog(String catalogName, Map<String, String> additi | |
| @Override | ||
| protected boolean requiresNamespaceCreate() { | ||
| return PropertyUtil.propertyAsBoolean( | ||
| restCatalog.properties(), | ||
| RESTCompatibilityKitSuite.RCK_REQUIRES_NAMESPACE_CREATE, | ||
| super.requiresNamespaceCreate()); | ||
|
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.
|
||
| restCatalog.properties(), RESTCompatibilityKitSuite.RCK_REQUIRES_NAMESPACE_CREATE, true); | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
We're adding the namespace check at a central place that now affects all catalogs extending this class. I think the main issue is that not every catalog actually requires an explicit namespace creation before e.g. creating a table inside a namespace or registering a table. That's also why we introduced the
requiresNamespaceCreate()flag in the tests.That being said, I don't think we can actually perform this check here as it should be specific to the respective catalog implementation and depending on whether that catalog implementation actually requires a namespace to be created or not.
For example, the default behavior of the JDBC catalog is to not require a namespace to exist when you create a table. That means registering a table should also not require for that namespace to exist beforehand.
However, if you configure strict-mode, then namespace existence is required, meaning that the
targetNamespaceExistscheck should only be performed when strict-mode is onUh oh!
There was an error while loading. Please reload this page.
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.
@nastra Thank you for the feedback and I agree w/ you.
I like this idea when I am working on the test.
How about we make the
requiresNamespaceCreate()a default method (return false by default) inSupportsNamespaces?Doing so:
src/testtosrc/main.targetNamespaceExistscheck if the catalog implementation doesn't require it.