RussellSpitzer commented on a change in pull request #2877:
URL: https://github.com/apache/iceberg/pull/2877#discussion_r677741660



##########
File path: 
spark/src/main/java/org/apache/iceberg/spark/source/RowDataReader.java
##########
@@ -194,20 +194,32 @@ protected Schema tableSchema() {
   }
 
   private static UnsafeProjection projection(Schema finalSchema, Schema 
readSchema) {
-    StructType struct = SparkSchemaUtil.convert(readSchema);
+    StructType readStruct = SparkSchemaUtil.convert(readSchema);
 
-    List<AttributeReference> refs = 
JavaConverters.seqAsJavaListConverter(struct.toAttributes()).asJava();
-    List<Attribute> attrs = 
Lists.newArrayListWithExpectedSize(struct.fields().length);
+    List<AttributeReference> readReferences = 
JavaConverters.seqAsJavaListConverter(readStruct.toAttributes()).asJava();
+    List<Attribute> attrs = 
Lists.newArrayListWithExpectedSize(readStruct.fields().length);
     List<org.apache.spark.sql.catalyst.expressions.Expression> exprs =
-        Lists.newArrayListWithExpectedSize(struct.fields().length);
+        Lists.newArrayListWithExpectedSize(readStruct.fields().length);
 
-    for (AttributeReference ref : refs) {
+    for (AttributeReference ref : readReferences) {
       attrs.add(ref.toAttribute());
     }
 
     for (Types.NestedField field : finalSchema.columns()) {
-      int indexInReadSchema = struct.fieldIndex(field.name());
-      exprs.add(refs.get(indexInReadSchema));
+      int indexInReadSchema = readStruct.fieldIndex(field.name());
+      if (field.type().isStructType()) {
+        // We may need to prune this attribute to only refer to our expected 
schema

Review comment:
       Yep, this basically creates the target expression from the attribute we 
are pruning but uses the pruned data type instead of the original read data type




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