findinpath commented on code in PR #9830:
URL: https://github.com/apache/iceberg/pull/9830#discussion_r2988777757
##########
spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/SparkCatalog.java:
##########
@@ -524,6 +530,80 @@ public View loadView(Identifier ident) throws
NoSuchViewException {
throw new NoSuchViewException(ident);
}
+ private boolean isMaterializedView(org.apache.iceberg.view.View view) {
+ return view.currentVersion().storageTable() != null;
+ }
+
+ private org.apache.iceberg.catalog.TableIdentifier getStorageTableId(
+ org.apache.iceberg.view.View view) {
+ org.apache.iceberg.catalog.TableIdentifier storageTable =
view.currentVersion().storageTable();
+ Preconditions.checkState(
+ storageTable != null, "Storage table identifier is not set for
materialized view.");
+ return storageTable;
+ }
+
+ private Table loadStorageTable(org.apache.iceberg.view.View view) {
+ org.apache.iceberg.catalog.TableIdentifier storageTableId =
getStorageTableId(view);
+ try {
+ Identifier sparkIdent =
+ Identifier.of(storageTableId.namespace().levels(),
storageTableId.name());
+ return loadTable(sparkIdent);
+ } catch (NoSuchTableException e) {
+ throw new IllegalStateException("Unable to load storage table for
materialized view.", e);
+ }
+ }
+
+ private boolean isFresh(org.apache.iceberg.view.View view) {
+ Table sparkStorageTable = loadStorageTable(view);
+ org.apache.iceberg.Table storageTable = ((SparkTable)
sparkStorageTable).table();
+ if (storageTable.currentSnapshot() == null) {
+ return false;
+ }
+
+ String refreshStateJson =
+ storageTable
+ .currentSnapshot()
+ .summary()
+
.get(org.apache.iceberg.view.RefreshState.REFRESH_STATE_SUMMARY_KEY);
+ if (refreshStateJson == null) {
+ return false;
+ }
+
+ org.apache.iceberg.view.RefreshState refreshState =
+ org.apache.iceberg.view.RefreshStateParser.fromJson(refreshStateJson);
+
+ if (refreshState.viewVersionId() != view.currentVersion().versionId()) {
+ return false;
+ }
+
+ for (org.apache.iceberg.view.SourceState sourceState :
refreshState.sourceStates()) {
+ if (sourceState instanceof org.apache.iceberg.view.SourceTableState) {
+ org.apache.iceberg.view.SourceTableState tableState =
+ (org.apache.iceberg.view.SourceTableState) sourceState;
+ org.apache.iceberg.catalog.TableIdentifier sourceId =
+ org.apache.iceberg.catalog.TableIdentifier.of(
+ org.apache.iceberg.catalog.Namespace.of(
+ tableState.namespace().toArray(new String[0])),
+ tableState.name());
+ try {
+ org.apache.iceberg.Table sourceTable =
+ ((org.apache.iceberg.catalog.Catalog)
icebergCatalog()).loadTable(sourceId);
Review Comment:
remove `(org.apache.iceberg.catalog.Catalog)`
--
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]