kbendick commented on a change in pull request #2983:
URL: https://github.com/apache/iceberg/pull/2983#discussion_r689826475
##########
File path: spark3/src/main/java/org/apache/iceberg/spark/Spark3Util.java
##########
@@ -755,6 +755,27 @@ private static String
sqlString(org.apache.iceberg.expressions.Literal<?> lit) {
return null;
}
+ /**
+ * Returns an Iceberg Table by its name from a Spark V2 Catalog
+ *
+ * @param spark SparkSession used for looking up catalog references and
tables
+ * @param name The multipart identifier of the Iceberg table
+ * @return an Iceberg table
+ */
+ public static org.apache.iceberg.Table loadIcebergTable(SparkSession spark,
String name)
+ throws ParseException, NoSuchTableException {
+ CatalogAndIdentifier catalogAndIdentifier = catalogAndIdentifier(spark,
name);
+
+ CatalogPlugin catalog = catalogAndIdentifier.catalog;
+ Preconditions.checkArgument(catalog instanceof BaseCatalog, "Catalog
%s(%s) cannot be used " +
+ "to load Iceberg tables", catalog.name(),
catalog.getClass().toString());
+ BaseCatalog baseCatalog = (BaseCatalog) catalogAndIdentifier.catalog;
+ Table table = baseCatalog.loadTable(catalogAndIdentifier.identifier);
Review comment:
Small nit: As this is `org.apache.spark.sql.connector.catalog.Table`,
and the return type is `org.apache.iceberg.Table`, does it make sense to fully
qualify the type used on this line?
I was initially a little confused on why we were taking a `Table`, checking
if it's a `SparkTable`, casting it, and then grabbing `.table()` from it. I see
now that it's a spark catalog table before casing it to Iceberg's `SparkTable`
and then grabbing the iceberg `Table` from it, but it could arguably be a
little hard for readability.
But given that the return type is well specified, I wouldn't say it's
something you necessarily have to change.
--
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]