nastra commented on code in PR #9455: URL: https://github.com/apache/iceberg/pull/9455#discussion_r1452261664
########## spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/SparkTable.java: ########## @@ -122,6 +124,7 @@ public class SparkTable private final Set<TableCapability> capabilities; private String branch; private StructType lazyTableSchema = null; + private Long lazyFixedSnapshotId; Review Comment: instead of introducing a new field, we could just use the exising one: ``` --- a/spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/SparkTable.java +++ b/spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/source/SparkTable.java @@ -23,6 +23,7 @@ import static org.apache.iceberg.TableProperties.FORMAT_VERSION; import java.io.IOException; import java.util.Map; +import java.util.Objects; import java.util.Set; import org.apache.iceberg.BaseMetadataTable; import org.apache.iceberg.BaseTable; @@ -34,6 +35,7 @@ import org.apache.iceberg.PartitionSpec; import org.apache.iceberg.Partitioning; import org.apache.iceberg.PositionDeletesTable; import org.apache.iceberg.Schema; +import org.apache.iceberg.Snapshot; import org.apache.iceberg.SnapshotRef; import org.apache.iceberg.Table; import org.apache.iceberg.TableOperations; @@ -117,7 +119,7 @@ public class SparkTable .build(); private final Table icebergTable; - private final Long snapshotId; + private Long snapshotId; private final boolean refreshEagerly; private final Set<TableCapability> capabilities; private String branch; @@ -131,12 +133,12 @@ public class SparkTable public SparkTable(Table icebergTable, String branch, boolean refreshEagerly) { this(icebergTable, refreshEagerly); this.branch = branch; + Snapshot snapshot = icebergTable.snapshot(branch); ValidationException.check( - branch == null - || SnapshotRef.MAIN_BRANCH.equals(branch) - || icebergTable.snapshot(branch) != null, + branch == null || SnapshotRef.MAIN_BRANCH.equals(branch) || snapshot != null, "Cannot use branch (does not exist): %s", branch); + this.snapshotId = snapshot.snapshotId(); } public SparkTable(Table icebergTable, Long snapshotId, boolean refreshEagerly) { @@ -407,13 +409,14 @@ public class SparkTable // use only name in order to correctly invalidate Spark cache SparkTable that = (SparkTable) other; - return icebergTable.name().equals(that.icebergTable.name()); + return icebergTable.name().equals(that.icebergTable.name()) + && Objects.equals(snapshotId, that.snapshotId); } @Override public int hashCode() { // use only name in order to correctly invalidate Spark cache - return icebergTable.name().hashCode(); + return Objects.hash(icebergTable.name(), snapshotId); ``` -- 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: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org