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


##########
flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/FlinkCatalog.java:
##########
@@ -473,6 +574,74 @@ private boolean isReservedProperty(String prop) {
         || 
FlinkCreateTableOptions.SRC_CATALOG_PROPS_KEY.equalsIgnoreCase(prop);
   }
 
+  /**
+   * The stored view SQL is later resolved against the view's own database, 
but Flink validated it
+   * against the session's current database. An unqualified reference to a 
table outside the view's
+   * database would therefore resolve differently (or not at all) depending on 
the reader's session,
+   * so such queries are rejected. Flink's expanded query fully qualifies 
every table reference,
+   * which makes the mismatch detectable without parsing SQL.
+   */
+  private void validateViewReferences(ObjectPath tablePath, 
ResolvedCatalogView view) {
+    String originalQuery = view.getOriginalQuery();
+    String expandedQuery = view.getExpandedQuery();
+    if (StringUtils.isNullOrWhitespaceOnly(originalQuery)
+        || StringUtils.isNullOrWhitespaceOnly(expandedQuery)) {
+      // views built programmatically may not carry Flink's normalized 
queries; the check only
+      // applies to parser-produced text
+      return;
+    }
+
+    Matcher references = QUALIFIED_REFERENCE.matcher(expandedQuery);

Review Comment:
   Yeah, you are right, your example breaks the check. 😄  I switched to storing 
getExpandedQuery() and removed the whole validation. Now every reference is 
qualified at creation time, so nothing depends on the reader's session anymore. 
   
   The trade-off is the catalog name ends up inside the stored SQL, so if 
someone registers the catalog under a different name the view fails with 
"catalog not found" but it is better loud failure instead of wrong results. I 
think this also answers your earlier default-namespace question, since the 
stored query does not rely on it now.



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