pvary commented on code in PR #17873:
URL: https://github.com/apache/iceberg/pull/17873#discussion_r4007728684
##########
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:
This is "magic", but sometimes it does not work:
```
CREATE VIEW cat.db.mixed_v AS
SELECT x.id FROM db2.shared x JOIN shared y ON x.id = y.id;
```
We can try to patch this back and forth, but maybe using `getExpandedQuery`
would be better?
--
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]