You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2019/12/05 00:18:31 UTC

[GitHub] [incubator-iceberg] rdblue commented on a change in pull request #585: Fix Iceberg Reader for nested partitions (#575)

rdblue commented on a change in pull request #585: Fix Iceberg Reader for nested partitions (#575)
URL: https://github.com/apache/incubator-iceberg/pull/585#discussion_r354054235
 
 

 ##########
 File path: spark/src/main/java/org/apache/iceberg/spark/source/Reader.java
 ##########
 @@ -408,36 +406,39 @@ public void close() throws IOException {
       Iterator<InternalRow> iter;
 
       if (hasJoinedPartitionColumns) {
-        // schema used to read data files
-        Schema readSchema = TypeUtil.selectNot(requiredSchema, idColumns);
-        Schema partitionSchema = TypeUtil.select(requiredSchema, idColumns);
-        PartitionRowConverter convertToRow = new PartitionRowConverter(partitionSchema, spec);
-        JoinedRow joined = new JoinedRow();
-
-        InternalRow partition = convertToRow.apply(file.partition());
-        joined.withRight(partition);
+        Map<Integer, Object> partitionValueMap = Maps.newHashMap();
+        Map<Integer, Integer> partitionSpecFieldIndexMap = Maps.newHashMap();
+        Map<Integer, DataType> partitionSpecDataTypeMap = Maps.newHashMap();
+
+        for (int i = 0; i < spec.fields().size(); i++) {
+          PartitionField partitionField = spec.fields().get(i);
+          Integer sourceId = partitionField.sourceId();
+          partitionSpecFieldIndexMap.put(sourceId, i);
+          DataType partitionType = SparkSchemaUtil.convert(spec.partitionType().field(partitionField.name()).type());
+          partitionSpecDataTypeMap.put(sourceId, partitionType);
+        }
 
-        // create joined rows and project from the joined schema to the final schema
-        iterSchema = TypeUtil.join(readSchema, partitionSchema);
-        iter = Iterators.transform(open(task, readSchema), joined::withLeft);
+        for (Map.Entry<Integer, Integer> entry : partitionSpecFieldIndexMap.entrySet()) {
+          Object partitionValue = convert(file.partition().get(entry.getValue(), Object.class),
+              partitionSpecDataTypeMap.get(entry.getKey()));
+          partitionValueMap.put(entry.getKey(), partitionValue);
+        }
 
+        iterSchema = requiredSchema;
+        iter = open(task, finalSchema, partitionValueMap);
 
 Review comment:
   This isn't right. This reports that the iterator's schema (`iterSchema`) is `requiredSchema`, but then opens tasks with `finalSchema`.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org