pvary commented on code in PR #17873:
URL: https://github.com/apache/iceberg/pull/17873#discussion_r4014163036
##########
flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/FlinkCatalog.java:
##########
@@ -529,6 +573,42 @@ private boolean isReservedProperty(String prop) {
||
FlinkCreateTableOptions.SRC_CATALOG_PROPS_KEY.equalsIgnoreCase(prop);
}
+ private void createIcebergView(
+ ObjectPath tablePath, ResolvedCatalogView view, boolean ignoreIfExists)
+ throws CatalogException, DatabaseNotExistException,
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()))
+ // the expanded query fully qualifies every table reference, so the
view resolves the
+ // same way regardless of the reader's session; views built
programmatically may not
+ // carry an expanded query, in which case the original query is
stored as-is
+ .withQuery(FLINK_DIALECT, viewQuery(view))
+ .withProperties(properties)
+ .create();
+ } catch (AlreadyExistsException e) {
+ if (!ignoreIfExists) {
+ throw new TableAlreadyExistException(getName(), tablePath, e);
+ }
+ } catch (NoSuchNamespaceException e) {
+ throw new DatabaseNotExistException(getName(),
tablePath.getDatabaseName(), e);
+ }
+ }
+
+ private static String viewQuery(ResolvedCatalogView view) {
+ return StringUtils.isNullOrWhitespaceOnly(view.getExpandedQuery())
+ ? view.getOriginalQuery()
+ : view.getExpandedQuery();
Review Comment:
Could this happen?
--
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]