mchades commented on code in PR #11288:
URL: https://github.com/apache/gravitino/pull/11288#discussion_r3341932315
##########
spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/catalog/BaseCatalog.java:
##########
@@ -421,6 +435,45 @@ public boolean dropNamespace(String[] namespace, boolean
cascade)
}
}
+ /**
+ * Loads a Gravitino view as a Spark Table when {@link
#loadTable(Identifier)} fails because the
+ * object is a view. Subclasses can override {@link #createSparkView} to
enable view support.
+ *
+ * @param ident the identifier to load
+ * @return Spark Table wrapping the view
+ * @throws NoSuchTableException if no view exists or views are not supported
by this catalog
+ */
+ protected Table loadViewAsTable(Identifier ident) throws
NoSuchTableException {
+ View gravitinoView;
+ try {
+ gravitinoView =
+ gravitinoCatalogClient
+ .asViewCatalog()
+ .loadView(NameIdentifier.of(getDatabase(ident), ident.name()));
+ } catch (NoSuchViewException | UnsupportedOperationException |
ForbiddenException e) {
+ throw new NoSuchTableException(ident);
+ }
+ // Call sparkCatalog.loadTable directly to surface NoSuchTableException as
checked,
+ // avoiding the RuntimeException wrapping in loadSparkTable.
+ Table sparkTable = sparkCatalog.loadTable(ident);
+ return createSparkView(ident, gravitinoView, sparkTable);
+ }
+
+ /**
+ * Creates a catalog-specific Spark Table wrapping a Gravitino view.
Subclasses that support views
+ * must override this method.
+ *
+ * @param ident the identifier
+ * @param gravitinoView the Gravitino view metadata
+ * @param sparkTable the underlying Spark table for IO (view expansion)
+ * @return a Spark Table representing the view
+ * @throws UnsupportedOperationException if views are not supported by this
catalog
+ */
+ protected Table createSparkView(Identifier ident, View gravitinoView, Table
sparkTable) {
Review Comment:
better to use `convertToTable`?
--
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]