rdblue commented on a change in pull request #1508:
URL: https://github.com/apache/iceberg/pull/1508#discussion_r698064164



##########
File path: spark2/src/main/java/org/apache/iceberg/spark/source/Reader.java
##########
@@ -152,20 +153,30 @@
       this.localityPreferred = false;
     }
 
-    this.schema = table.schema();
+    this.schema = snapshotSchema();
     this.caseSensitive = caseSensitive;
     this.batchSize = 
options.get(SparkReadOptions.VECTORIZATION_BATCH_SIZE).map(Integer::parseInt).orElseGet(()
 ->
         PropertyUtil.propertyAsInt(table.properties(),
           TableProperties.PARQUET_BATCH_SIZE, 
TableProperties.PARQUET_BATCH_SIZE_DEFAULT));
   }
 
+  protected Schema snapshotSchema() {
+    if (snapshotId != null && table instanceof BaseTable) {

Review comment:
       I think this should use the snapshot's schema ID, like this:
   
   ```java
   if (snapshotId != null) {
     Schema snapshotSchema = 
table.schemas().get(table.snapshot(snapshotId).schemaId());
     if (snapshotSchema != null) {
       return snapshotSchema;
     }
   
     // TODO: recover the schema using a util class
     return table.schema();
   } else {
     return table.schema();
   }
   ```




-- 
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]

Reply via email to