kumarpritam863 commented on code in PR #18582:
URL: https://github.com/apache/iceberg/pull/18582#discussion_r4315856313


##########
flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/sink/dynamic/TableUpdater.java:
##########
@@ -78,13 +77,18 @@ private void findOrCreateTable(
       TableIdentifier identifier, Schema schema, PartitionSpec spec, 
TableCreator tableCreator) {
     Tuple2<Boolean, Exception> exists = cache.exists(identifier);
     if (Boolean.FALSE.equals(exists.f0)) {
-      if (exists.f1 instanceof NoSuchNamespaceException) {
+      // The lookup cannot tell a missing table from a missing namespace: the 
Glue catalog, for
+      // instance, reports a table in a namespace that does not exist as 
NoSuchTableException. Ask
+      // the catalog directly.
+      if (catalog instanceof SupportsNamespaces && 
!identifier.namespace().isEmpty()) {

Review Comment:
   I think it is needed as a table identifier without a namespace is valid 
(TableIdentifier.parse("myTable") in the tests), and without the check 
HadoopCatalog.namespaceExists(Namespace.empty()) throws 
IllegalArgumentException: Can not create a Path from an empty string; three 
existing tests fail. I added a comment.



##########
flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/sink/dynamic/TableUpdater.java:
##########
@@ -78,13 +77,18 @@ private void findOrCreateTable(
       TableIdentifier identifier, Schema schema, PartitionSpec spec, 
TableCreator tableCreator) {
     Tuple2<Boolean, Exception> exists = cache.exists(identifier);
     if (Boolean.FALSE.equals(exists.f0)) {
-      if (exists.f1 instanceof NoSuchNamespaceException) {
+      // The lookup cannot tell a missing table from a missing namespace: the 
Glue catalog, for
+      // instance, reports a table in a namespace that does not exist as 
NoSuchTableException. Ask
+      // the catalog directly.
+      if (catalog instanceof SupportsNamespaces && 
!identifier.namespace().isEmpty()) {
         SupportsNamespaces catalogWithNameSpace = (SupportsNamespaces) catalog;
-        LOG.info("Namespace {} not found during table search. Creating 
namespace", identifier);
-        try {
-          catalogWithNameSpace.createNamespace(identifier.namespace());
-        } catch (AlreadyExistsException e) {
-          LOG.debug("Namespace {} created concurrently", 
identifier.namespace(), e);
+        if (!catalogWithNameSpace.namespaceExists(identifier.namespace())) {
+          LOG.info("Namespace {} not found during table search. Creating 
namespace", identifier);
+          try {
+            catalogWithNameSpace.createNamespace(identifier.namespace());
+          } catch (AlreadyExistsException e) {
+            LOG.debug("Namespace {} created concurrently", 
identifier.namespace(), e);
+          }
         }

Review Comment:
   For a catalog without SupportsNamespaces it now throws a clear 
UnsupportedOperationException when the lookup reported a missing namespace



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to