rdblue commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4021282883
##########
core/src/main/java/org/apache/iceberg/TrackedFileStruct.java:
##########
@@ -210,14 +216,55 @@ public long fileSizeInBytes() {
return fileSizeInBytes;
}
+ void setSpecsById(Map<Integer, PartitionSpec> newSpecsById) {
+ this.specsById = newSpecsById;
+ }
+
@Override
public Integer specId() {
return specId;
}
@Override
public StructLike partition() {
- return partitionData;
+ if (partitionData == null || specId == null || specsById == null) {
+ return partitionData;
+ }
+
+ StructProjection projection = partitionProjection(specId);
+ return projection != null ? projection.wrap(partitionData) : partitionData;
+ }
+
+ private StructProjection partitionProjection(int id) {
+ if (partitionProjections == null) {
+ this.partitionProjections = Maps.newHashMap();
+ }
+
+ if (!partitionProjections.containsKey(id)) {
+ PartitionSpec spec = specsById.get(id);
+ Types.StructType specType = spec != null ? spec.partitionType() : null;
+ // null when the stored tuple already matches the spec, so partition()
passes it through
+ partitionProjections.put(
+ id,
+ specType == null || partitionData.getPartitionType().equals(specType)
+ ? null
+ : StructProjection.create(partitionData.getPartitionType(),
specType));
Review Comment:
This `put` is too complicated and it forces the caller to handle `null`. The
projection should be created and stored in a variable so `put` can be separate
from the control flow for creating the projection.
I'd rather use a `Function<PartitionData, StructLike>` to project. That way
this can return `projection::wrap` or `Functions.identity` and the caller is
simpler.
--
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]