talatuyarer commented on code in PR #17873:
URL: https://github.com/apache/iceberg/pull/17873#discussion_r3991419517


##########
flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/FlinkCatalog.java:
##########
@@ -473,6 +571,33 @@ private boolean isReservedProperty(String prop) {
         || 
FlinkCreateTableOptions.SRC_CATALOG_PROPS_KEY.equalsIgnoreCase(prop);
   }
 
+  private void createIcebergView(
+      ObjectPath tablePath, ResolvedCatalogView view, boolean ignoreIfExists)
+      throws CatalogException, TableAlreadyExistException {
+    Map<String, String> properties = Maps.newHashMap(view.getOptions());
+    if (!StringUtils.isNullOrWhitespaceOnly(view.getComment())) {
+      properties.put(ViewProperties.COMMENT, view.getComment());
+    }
+
+    try {
+      // the default catalog is intentionally left unset so that readers 
resolve it to the
+      // name this catalog is registered under (see toCatalogView)
+      asViewCatalog
+          .buildView(toIdentifier(tablePath))
+          .withSchema(FlinkSchemaUtil.convert(view.getResolvedSchema()))
+          .withDefaultNamespace(appendLevel(baseNamespace, 
tablePath.getDatabaseName()))

Review Comment:
   I have tested this and identified a session-related issue in here. In a 
session targeting `db2`, executing `CREATE VIEW db.v AS SELECT ... FROM t` 
(where `t` is in `db2`) is accepted. However, while the view works when read 
from the original `db2` session, it fails with "Object 't' not found" when 
accessed from any other session. This occurs because Flink's view expansion 
falls back to the reader's current database for any references missing from the 
view's database.
   
   The root cause is that the Iceberg spec requires the `default-namespace` to 
match the session's namespace at view creation, which the Flink Catalog API 
does not natively expose. I have implemented explicit validation at creation 
time to handle this.
   
   To ensure consistency, non-qualified references outside the view's catalog 
and database are now rejected with an error prompting for explicit 
qualification. Qualified cross-database references remain permitted, and I have 
added test cases to verify both scenarios.



-- 
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