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

Kafka-connect: Handle namespace creation for auto table creation #10186

Merged
merged 3 commits into from
May 15, 2024

Conversation

ajantha-bhat
Copy link
Member

Some catalogs like Inmemory, Hive, Nessie, REST catalog expects the namespace to be present before creating the table. Hence, the auto table creation feature will not work currently for these catalogs if the namespace is missing.

Added a support to create the missing namespace and its parents while auto creating the table.

@@ -47,7 +54,7 @@ public class IcebergWriterFactoryTest {
@ValueSource(booleans = {true, false})
@SuppressWarnings("unchecked")
public void testAutoCreateTable(boolean partitioned) {
Catalog catalog = mock(Catalog.class);
Catalog catalog = mock(InMemoryCatalog.class);
Copy link
Member Author

Choose a reason for hiding this comment

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

Need to change it to some catalog that supports namespace creation. As the code now calls createNamespaceIfNotExist

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather not rely on InMemoryCatalog API here. You could do something like this instead, Catalog catalog = mock(Catalog.class, withSettings().extraInterfaces(SupportsNamespaces.class));

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Namespace namespace = Namespace.of(Arrays.copyOfRange(levels, 0, index + 1));
try {
((SupportsNamespaces) catalog).createNamespace(namespace);
} catch (AlreadyExistsException ex) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We went the other way with Flink: #7795

Can we also swallow the exception where the user doesn't have permission to create a namespace.

Copy link
Member Author

Choose a reason for hiding this comment

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

I assumed if the auto create table is enabled, means user has permission to create tables. So, They can create Namespaces also. But that assumptions can be wrong for some catalogs. Let me catch ForbiddenException also for ignoring it.

Copy link
Contributor

@Fokko Fokko left a comment

Choose a reason for hiding this comment

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

Thanks for working on this @ajantha-bhat 👍

Any concerns @bryanck? We could also make this configurable through a flag, but I don't think we want to overcomplicate things.

for (int index = 0; index < levels.length; index++) {
Namespace namespace = Namespace.of(Arrays.copyOfRange(levels, 0, index + 1));
try {
((SupportsNamespaces) catalog).createNamespace(namespace);
Copy link
Contributor

@bryanck bryanck Apr 25, 2024

Choose a reason for hiding this comment

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

This can cause a ClassCastException so we should check that the catalog implements SupportsNamespaces first.

Copy link
Member Author

Choose a reason for hiding this comment

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

done.

TableIdentifier.of(Namespace.of("foo1", "foo2", "foo3"), "bar");
Schema schema = new Schema(Types.NestedField.required(1, "id", Types.StringType.get()));

try (InMemoryCatalog catalog = new InMemoryCatalog()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer using the ArgumentCaptor approach, rather than relying on InMemoryCatalog. This is consistent with the auto create test.

Copy link
Member Author

Choose a reason for hiding this comment

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

done. Updated the existing testcase

@ajantha-bhat
Copy link
Member Author

ping @bryanck

@bryanck
Copy link
Contributor

bryanck commented May 15, 2024

Thanks for the contribution @ajantha-bhat , it looks good!

@bryanck bryanck merged commit 4c9f47d into apache:main May 15, 2024
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants