rdblue commented on a change in pull request #1508: URL: https://github.com/apache/iceberg/pull/1508#discussion_r496934771
########## File path: core/src/main/java/org/apache/iceberg/BaseTable.java ########## @@ -59,6 +60,45 @@ public Schema schema() { return ops.current().schema(); } + @Override + public Schema schemaForSnapshot(long snapshotId) { + TableMetadata current = ops.current(); + if (current.currentSnapshot() != null && + current.currentSnapshot().snapshotId() == snapshotId) { + return current.schema(); + } + Long snapshotTs = null; + for (HistoryEntry logEntry : current.snapshotLog()) { + if (logEntry.snapshotId() == snapshotId) { + snapshotTs = logEntry.timestampMillis(); + } + } + Preconditions.checkArgument(snapshotTs != null, + "Cannot find a snapshot with id %s", snapshotId); + TableMetadata.MetadataLogEntry metadataLogEntry = null; + for (TableMetadata.MetadataLogEntry logEntry : current.previousFiles()) { + if (logEntry.timestampMillis() <= snapshotTs) { + metadataLogEntry = logEntry; + } + } + String metadataFile = metadataLogEntry.file(); + TableMetadata metadata = TableMetadataParser.read(io(), metadataFile); + return metadata.schema(); + } + + @Override + public Schema schemaForSnapshotAsOfTime(long timestampMillis) { Review comment: We don't need two methods. We can use the history log to find out what snapshot was current at a given time, then get the schema from that snapshot. ---------------------------------------------------------------- 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. 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