You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "anoopj (via GitHub)" <gi...@apache.org> on 2026/09/14 20:30:50 UTC
[PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
anoopj opened a new pull request, #18108:
URL: https://github.com/apache/iceberg/pull/18108
TrackedFileAdapters exposed the manifest's union-type partition tuple unchanged while reporting the file's own spec ID. Residual evaluation and partition-constant injection read the tuple by the spec's field ordinals, so on partition-evolved tables a later spec's field (at a different position in the union than in its own spec) was read from the wrong slot, silently dropping rows or injecting null partition constants.
Project each file's partition onto its resolved spec's partition type before exposing it, so partition() is always in the file's own spec order.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "yangshangqing95 (via GitHub)" <gi...@apache.org>.
yangshangqing95 commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4020172617
##########
core/src/test/java/org/apache/iceberg/TestV4ManifestReader.java:
##########
@@ -684,6 +684,38 @@ public void filterMatchesFilesAcrossDisjointSpecs(FileFormat format) throws IOEx
}
}
+ @ParameterizedTest
+ @FieldSource("MANIFEST_FORMATS")
+ public void narrowPartitionProjectionReadsFullUnionTuple(FileFormat format) throws IOException {
+ PartitionSpec idSpec =
+ PartitionSpec.builderFor(TABLE_SCHEMA)
+ .withSpecId(0)
+ .add(1, 1000, "id", Transforms.identity())
+ .build();
+ PartitionSpec dataSpec =
+ PartitionSpec.builderFor(TABLE_SCHEMA)
+ .withSpecId(1)
+ .add(2, 1001, "data", Transforms.identity())
+ .build();
+ Map<Integer, PartitionSpec> specsById =
+ ImmutableMap.of(idSpec.specId(), idSpec, dataSpec.specId(), dataSpec);
+ Types.StructType unionType = Partitioning.unionPartitionTypes(specsById.values());
+
+ TrackedFile file =
+ dataFile("by-data.parquet", dataSpec.specId(), unionPartition(unionType, null, "x"));
+ ManifestFile manifest = writeManifest(format, unionType, ImmutableList.of(file));
+
+ // select id, which this file's spec does not use; the reader must still read the whole union
+ // tuple (including data) so partition() can project it onto the file's data spec
+ try (V4ManifestReader reader =
+ V4ManifestReader.builder(manifest, io, specsById, TABLE_LOCATION)
+ .select("partition.id")
+ .build()) {
+ TrackedFile actual = Iterables.getOnlyElement(reader);
+ assertThat(actual.partition().get(0, CharSequence.class)).hasToString("x");
+ }
+ }
+
Review Comment:
Nit, non-blocking: would it be worth adding a regression test that goes through `TrackedFileAdapters` as well?
The current tests cover the projection behavior in `TrackedFileStruct` and `V4ManifestReader` well, but the original failure shows up downstream when the partition tuple is interpreted using the file's spec, e.g. during residual evaluation or partition-constant injection.
A test along the lines of `V4ManifestReader` -> `TrackedFileAdapters` -> `partition/residual evaluation` would help lock in the user-visible behavior and guard against the adapter boundary regressing in the future.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4021293025
##########
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));
+ }
+
+ return partitionProjections.get(id);
+ }
+
+ private PartitionData materializedPartition() {
Review Comment:
I think this class should use `StructUtil.copy(partition())`. There's no need to ensure that the result is a `PartitionData`. Won't any `StructLike` work?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "anoopj (via GitHub)" <gi...@apache.org>.
anoopj commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4040704710
##########
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) {
Review Comment:
Actually there is a Checkstyle's `HiddenField` rule: the param `specId` collides with the specId field. I renamed it to `partitionSpecId` to avoid collision.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4148916813
##########
core/src/test/java/org/apache/iceberg/TestV4ManifestReader.java:
##########
@@ -1495,40 +1495,109 @@ public void partitionFilterWithMultipleSpecs(FileFormat format) throws IOExcepti
.build();
Map<Integer, PartitionSpec> specsById =
ImmutableMap.of(idSpec.specId(), idSpec, dataSpec.specId(), dataSpec);
-
- PartitionData dataPartitionX = partition(dataSpec, "x");
- TrackedFile dataPartitionedFile =
- dataFileWithoutStats(
- "s3://bucket/table/data=x/file-c.parquet", dataSpec.specId(), dataPartitionX);
-
- ManifestFile idPartitionedManifest =
- writeManifest(format, idSpec.partitionType(), ImmutableList.of(FILE_A, FILE_B));
- ManifestFile dataPartitionedManifest =
- writeManifest(format, dataSpec.partitionType(), dataPartitionedFile);
-
- List<TrackedFile> files = Lists.newArrayList();
- files.addAll(
- read(
- V4ManifestReader.builder(idPartitionedManifest, IO, TABLE_SCHEMA, specsById)
- .metricsConfig(METRICS_CONFIG)));
- files.addAll(
- read(
- V4ManifestReader.builder(dataPartitionedManifest, IO, TABLE_SCHEMA, specsById)
- .metricsConfig(METRICS_CONFIG)));
-
Types.StructType unionType = Partitioning.unionPartitionTypes(specsById.values());
+ int idPos = unionType.fields().indexOf(unionType.field("id"));
+ int dataPos = unionType.fields().indexOf(unionType.field("data"));
+
+ // a mixed-spec manifest stores every file's partition in the union type
+ PartitionData idOne = new PartitionData(unionType);
+ idOne.set(idPos, 1);
+ PartitionData idTwo = new PartitionData(unionType);
+ idTwo.set(idPos, 2);
+ PartitionData dataX = new PartitionData(unionType);
+ dataX.set(dataPos, "x");
+
+ TrackedFile idFileKept =
+ dataFileWithoutStats("s3://bucket/table/id=1/file-a.parquet", idSpec.specId(), idOne);
+ TrackedFile idFilePruned =
+ dataFileWithoutStats("s3://bucket/table/id=2/file-b.parquet", idSpec.specId(), idTwo);
+ TrackedFile dataFile =
+ dataFileWithoutStats("s3://bucket/table/data=x/file-c.parquet", dataSpec.specId(), dataX);
- ManifestFile manifest = writeManifest(format, unionType, files);
+ ManifestFile manifest =
+ writeManifest(format, unionType, ImmutableList.of(idFileKept, idFilePruned, dataFile));
V4ManifestReader.Builder builder =
V4ManifestReader.builder(manifest, IO, TABLE_SCHEMA, specsById)
.filter(Expressions.equal("id", 1))
.metricsConfig(METRICS_CONFIG);
- // the comparator is built for ID partitioning, so only check the location
assertThat(read(builder))
.extracting(TrackedFile::location)
- .containsExactlyInAnyOrder(FILE_A.location(), dataPartitionedFile.location());
+ .containsExactlyInAnyOrder(idFileKept.location(), dataFile.location());
+ }
+
+ @ParameterizedTest
+ @FieldSource("MANIFEST_FORMATS")
+ public void narrowPartitionProjectionReadsFullUnionTuple(FileFormat format) throws IOException {
+ PartitionSpec idSpec =
+ PartitionSpec.builderFor(TABLE_SCHEMA)
+ .withSpecId(1)
+ .add(1, 1000, "id", Transforms.identity())
+ .build();
+ PartitionSpec dataSpec =
+ PartitionSpec.builderFor(TABLE_SCHEMA)
+ .withSpecId(2)
+ .add(2, 1001, "data", Transforms.identity())
+ .build();
+ Map<Integer, PartitionSpec> specsById =
+ ImmutableMap.of(idSpec.specId(), idSpec, dataSpec.specId(), dataSpec);
+ Types.StructType unionType = Partitioning.unionPartitionTypes(specsById.values());
+
+ PartitionData unionPartition = new PartitionData(unionType);
+ unionPartition.set(unionType.fields().indexOf(unionType.field("data")), "x");
+ TrackedFile file =
+ dataFileWithoutStats(
+ "s3://bucket/table/data=x/file.parquet", dataSpec.specId(), unionPartition);
+ ManifestFile manifest = writeManifest(format, unionType, ImmutableList.of(file));
+
+ TrackedFile actual =
+ readOne(
+ V4ManifestReader.builder(manifest, IO, TABLE_SCHEMA, specsById)
+ .metricsConfig(METRICS_CONFIG)
+ .select("partition.id"));
+ assertThat(actual.partition().get(0, CharSequence.class)).hasToString("x");
+ }
+
+ @ParameterizedTest
+ @FieldSource("MANIFEST_FORMATS")
+ public void unknownSpecPartitionIsNotProjected(FileFormat format) throws IOException {
Review Comment:
I don't think this is quite the right behavior. If the spec is unknown then `partition` cannot fulfill its contract, which is to return the original partition tuple with the spec's output type. That type is unknown and we can't just substitute the union type.
I think the choice is between returning null and failing. Failing is safer, but returning null should have mostly the same effect because a file should not have a `null` partition when it has a non-null spec ID.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "anoopj (via GitHub)" <gi...@apache.org>.
anoopj commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4020408875
##########
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() {
Review Comment:
I can clarify this, but to me it was a basic expectation from this field.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "anoopj (via GitHub)" <gi...@apache.org>.
anoopj commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4040709437
##########
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));
+ }
+
+ return partitionProjections.get(id);
+ }
+
+ private PartitionData materializedPartition() {
Review Comment:
Yes, I didn't know about `StructlikeUtil.copy()`. Thanks.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "anoopj (via GitHub)" <gi...@apache.org>.
anoopj commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4040680490
##########
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:
That looks a lot nicer. Making that change.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4160118451
##########
core/src/test/java/org/apache/iceberg/TestV4ManifestReader.java:
##########
@@ -1548,7 +1619,10 @@ public void partitionFilterKeepsFileWithUnknownSpec(FileFormat format) throws IO
TrackedFile actual = readOne(builder);
- assertThat(actual).usingComparator(FILE_COMPARATOR).isEqualTo(file);
+ assertThat(actual.location()).isEqualTo(file.location());
+ assertThat(actual.partition())
+ .as("unknown spec's partition cannot be projected to its output type")
+ .isNull();
Review Comment:
Related to the changes above, I think that the file should be skipped by the filter and returned. That means that `partition()` should throw an exception that is caught by the filter code. Probably `ValidationException`. This test should validate that the file is returned and that its `partition()` method throws the exception.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "anoopj (via GitHub)" <gi...@apache.org>.
anoopj commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4139837751
##########
core/src/main/java/org/apache/iceberg/TrackedFileAdapters.java:
##########
@@ -101,7 +101,8 @@ public int specId() {
@Override
public StructLike partition() {
- return file().partition() != null ? file().partition() : PartitionData.EMPTY;
+ StructLike partition = file.partition();
+ return partition != null ? partition : PartitionData.EMPTY;
Review Comment:
It was not a no-op. The original code evaluated `file().partition()` twice, and the change was to do it just once. I kept the single call but switched back from the file field to the file() accessor to stay consistent.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "anoopj (via GitHub)" <gi...@apache.org>.
anoopj commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4139939766
##########
core/src/main/java/org/apache/iceberg/V4ManifestReader.java:
##########
@@ -153,6 +154,12 @@ private TrackedFile applyInheritance(TrackedFile file) {
}
}
+ Integer specId = file.specId();
+ PartitionSpec spec = specId != null ? specsById.get(specId) : null;
+ if (file instanceof TrackedFileStruct) {
+ ((TrackedFileStruct) file).setPartitionType(spec != null ? spec.partitionType() : null);
Review Comment:
Removed. Doing cast directly.
##########
core/src/main/java/org/apache/iceberg/V4ManifestReader.java:
##########
@@ -153,6 +154,12 @@ private TrackedFile applyInheritance(TrackedFile file) {
}
}
+ Integer specId = file.specId();
+ PartitionSpec spec = specId != null ? specsById.get(specId) : null;
+ if (file instanceof TrackedFileStruct) {
Review Comment:
I think the method was renamed to `inheritance` recently, I should have changed it after rebasing. Moved it out to a `projectPartition` transform.
##########
core/src/main/java/org/apache/iceberg/TrackedFileStruct.java:
##########
@@ -142,7 +145,8 @@ private TrackedFileStruct(TrackedFileStruct toCopy, Set<Integer> statsIds) {
this.recordCount = toCopy.recordCount;
this.fileSizeInBytes = toCopy.fileSizeInBytes;
this.specId = toCopy.specId;
- this.partitionData = toCopy.partitionData != null ? toCopy.partitionData.copy() : null;
+ this.partitionData = copyOf(toCopy.partitionData);
Review Comment:
I did it this way because the getter method on the copied file will return the stored union tuple (for writes). I have changed it such that the two partition fields are collapsed into a single `StructLike` partition plus a transient `StructProjection`. The copy now materializes just the projected tuple via a `StructLikeUtil.copy()`
##########
core/src/main/java/org/apache/iceberg/TrackedFile.java:
##########
@@ -169,7 +169,10 @@ static Schema readSchema(Types.StructType partitionType, Types.StructType conten
/** Returns the ID of the partition spec used to partition this file, or null. */
Integer specId();
- /** Returns partition for this file as a {@link StructLike}, or null. */
+ /**
+ * Returns the partition for this file as a {@link StructLike} in the field order of the file's
Review Comment:
Done. reworded to "Returns the partition for this file as a struct with the partition spec's output type, or null."
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4021253886
##########
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) {
Review Comment:
Nit: which ID? Generally better to be specific and use `specId`.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "anoopj (via GitHub)" <gi...@apache.org>.
anoopj commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4020391754
##########
core/src/test/java/org/apache/iceberg/TestV4ManifestReader.java:
##########
@@ -684,6 +684,38 @@ public void filterMatchesFilesAcrossDisjointSpecs(FileFormat format) throws IOEx
}
}
+ @ParameterizedTest
+ @FieldSource("MANIFEST_FORMATS")
+ public void narrowPartitionProjectionReadsFullUnionTuple(FileFormat format) throws IOException {
+ PartitionSpec idSpec =
+ PartitionSpec.builderFor(TABLE_SCHEMA)
+ .withSpecId(0)
+ .add(1, 1000, "id", Transforms.identity())
+ .build();
+ PartitionSpec dataSpec =
+ PartitionSpec.builderFor(TABLE_SCHEMA)
+ .withSpecId(1)
+ .add(2, 1001, "data", Transforms.identity())
+ .build();
+ Map<Integer, PartitionSpec> specsById =
+ ImmutableMap.of(idSpec.specId(), idSpec, dataSpec.specId(), dataSpec);
+ Types.StructType unionType = Partitioning.unionPartitionTypes(specsById.values());
+
+ TrackedFile file =
+ dataFile("by-data.parquet", dataSpec.specId(), unionPartition(unionType, null, "x"));
+ ManifestFile manifest = writeManifest(format, unionType, ImmutableList.of(file));
+
+ // select id, which this file's spec does not use; the reader must still read the whole union
+ // tuple (including data) so partition() can project it onto the file's data spec
+ try (V4ManifestReader reader =
+ V4ManifestReader.builder(manifest, io, specsById, TABLE_LOCATION)
+ .select("partition.id")
+ .build()) {
+ TrackedFile actual = Iterables.getOnlyElement(reader);
+ assertThat(actual.partition().get(0, CharSequence.class)).hasToString("x");
+ }
+ }
+
Review Comment:
We do have coverage in the scan planner here: https://github.com/apache/iceberg/pull/17541 You can see that there is a test failure (which will be red until this PR is merged)
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "anoopj (via GitHub)" <gi...@apache.org>.
anoopj commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4048591712
##########
core/src/main/java/org/apache/iceberg/TrackedFileStruct.java:
##########
@@ -210,14 +214,27 @@ public long fileSizeInBytes() {
return fileSizeInBytes;
}
+ void setPartitionType(Types.StructType newPartitionType) {
+ this.partitionType = newPartitionType;
+ }
+
@Override
public Integer specId() {
return specId;
}
@Override
public StructLike partition() {
- return partitionData;
+ if (partitionData == null
+ || partitionType == null
+ || partitionData.getPartitionType().equals(partitionType)) {
+ return partitionData;
+ }
+
+ return new PartitionData(partitionType)
Review Comment:
We are intentionally not caching this for thread safety, so we pay the cost for a few object allocations. Note that in the common case (single spec manifests), we dont pay this cost.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4158374175
##########
core/src/main/java/org/apache/iceberg/TrackedFileAdapters.java:
##########
@@ -101,7 +101,8 @@ public int specId() {
@Override
public StructLike partition() {
- return file().partition() != null ? file().partition() : PartitionData.EMPTY;
+ StructLike partition = file.partition();
+ return partition != null ? partition : PartitionData.EMPTY;
Review Comment:
Yes, this is not needed and should be removed. We don't want to touch extra files if we don't have to.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4158985110
##########
core/src/main/java/org/apache/iceberg/TrackedFileStruct.java:
##########
@@ -210,14 +207,27 @@ public long fileSizeInBytes() {
return fileSizeInBytes;
}
+ void setPartitionProjection(StructProjection projection) {
+ this.partitionProjection = projection;
+ }
+
+ void clearPartition() {
+ this.partition = null;
+ this.partitionProjection = null;
+ }
+
@Override
public Integer specId() {
return specId;
}
@Override
public StructLike partition() {
- return partitionData;
+ if (partition == null || partitionProjection == null) {
Review Comment:
Now that the partition is cleared if it is not valid, I think that this method should throw `IllegalStateException` when the spec ID is present, but the partition is null. That way we are not relying on the caller to recognize that the partition is invalid, rather than assuming that a null partition tuple indicates an unpartitioned file.
I think this is needed for correctness. If we are matching equality deletes with data files, we need to fail when the partition is missing.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4148864450
##########
core/src/test/java/org/apache/iceberg/TestV4ManifestReader.java:
##########
@@ -1495,40 +1495,109 @@ public void partitionFilterWithMultipleSpecs(FileFormat format) throws IOExcepti
.build();
Map<Integer, PartitionSpec> specsById =
ImmutableMap.of(idSpec.specId(), idSpec, dataSpec.specId(), dataSpec);
-
- PartitionData dataPartitionX = partition(dataSpec, "x");
- TrackedFile dataPartitionedFile =
- dataFileWithoutStats(
- "s3://bucket/table/data=x/file-c.parquet", dataSpec.specId(), dataPartitionX);
-
- ManifestFile idPartitionedManifest =
- writeManifest(format, idSpec.partitionType(), ImmutableList.of(FILE_A, FILE_B));
- ManifestFile dataPartitionedManifest =
- writeManifest(format, dataSpec.partitionType(), dataPartitionedFile);
-
- List<TrackedFile> files = Lists.newArrayList();
- files.addAll(
- read(
- V4ManifestReader.builder(idPartitionedManifest, IO, TABLE_SCHEMA, specsById)
- .metricsConfig(METRICS_CONFIG)));
- files.addAll(
- read(
- V4ManifestReader.builder(dataPartitionedManifest, IO, TABLE_SCHEMA, specsById)
- .metricsConfig(METRICS_CONFIG)));
-
Types.StructType unionType = Partitioning.unionPartitionTypes(specsById.values());
+ int idPos = unionType.fields().indexOf(unionType.field("id"));
+ int dataPos = unionType.fields().indexOf(unionType.field("data"));
+
+ // a mixed-spec manifest stores every file's partition in the union type
+ PartitionData idOne = new PartitionData(unionType);
+ idOne.set(idPos, 1);
+ PartitionData idTwo = new PartitionData(unionType);
+ idTwo.set(idPos, 2);
+ PartitionData dataX = new PartitionData(unionType);
+ dataX.set(dataPos, "x");
+
+ TrackedFile idFileKept =
+ dataFileWithoutStats("s3://bucket/table/id=1/file-a.parquet", idSpec.specId(), idOne);
+ TrackedFile idFilePruned =
+ dataFileWithoutStats("s3://bucket/table/id=2/file-b.parquet", idSpec.specId(), idTwo);
+ TrackedFile dataFile =
+ dataFileWithoutStats("s3://bucket/table/data=x/file-c.parquet", dataSpec.specId(), dataX);
- ManifestFile manifest = writeManifest(format, unionType, files);
+ ManifestFile manifest =
+ writeManifest(format, unionType, ImmutableList.of(idFileKept, idFilePruned, dataFile));
V4ManifestReader.Builder builder =
V4ManifestReader.builder(manifest, IO, TABLE_SCHEMA, specsById)
.filter(Expressions.equal("id", 1))
.metricsConfig(METRICS_CONFIG);
- // the comparator is built for ID partitioning, so only check the location
assertThat(read(builder))
.extracting(TrackedFile::location)
- .containsExactlyInAnyOrder(FILE_A.location(), dataPartitionedFile.location());
+ .containsExactlyInAnyOrder(idFileKept.location(), dataFile.location());
+ }
+
+ @ParameterizedTest
+ @FieldSource("MANIFEST_FORMATS")
+ public void narrowPartitionProjectionReadsFullUnionTuple(FileFormat format) throws IOException {
Review Comment:
I'm not sure that this is the correct behavior, but it seems okay for now.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4149619156
##########
core/src/main/java/org/apache/iceberg/TrackedFileStruct.java:
##########
@@ -142,7 +145,8 @@ private TrackedFileStruct(TrackedFileStruct toCopy, Set<Integer> statsIds) {
this.recordCount = toCopy.recordCount;
this.fileSizeInBytes = toCopy.fileSizeInBytes;
this.specId = toCopy.specId;
- this.partitionData = toCopy.partitionData != null ? toCopy.partitionData.copy() : null;
+ this.partitionData = copyOf(toCopy.partitionData);
Review Comment:
> the getter method on the copied file will return the stored union tuple (for writes)
I think this is the behavior for reuse at read time, not for writes. Writes will wrap the value returned by `partition()` with a projection back to the current union spec 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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "anoopj (via GitHub)" <gi...@apache.org>.
anoopj commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4009386846
##########
core/src/main/java/org/apache/iceberg/TrackedFileAdapters.java:
##########
@@ -549,6 +565,22 @@ public ManifestFile copy() {
}
}
+ // Manifests store partitions in the union of all specs' partition types, but each file's
+ // partition must be read using its own spec's field order.
+ private static StructLike projectPartition(StructLike partition, Types.StructType specType) {
+ if (partition == null) {
+ return PartitionData.EMPTY;
+ }
+
+ Types.StructType unionType = ((PartitionData) partition).getPartitionType();
+ if (unionType.equals(specType)) {
+ return partition;
+ }
+
+ return new PartitionData(specType)
+ .copyFor(StructProjection.create(unionType, specType).wrap(partition));
Review Comment:
It may not be worth optimizing also, because mixed spec manifests aren't that common. We don't do these allocations on manifests with a single spec.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4021251595
##########
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() {
Review Comment:
I agree that we should update the Javadoc to reflect this expectation.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4138368513
##########
core/src/main/java/org/apache/iceberg/TrackedFile.java:
##########
@@ -169,7 +169,10 @@ static Schema readSchema(Types.StructType partitionType, Types.StructType conten
/** Returns the ID of the partition spec used to partition this file, or null. */
Integer specId();
- /** Returns partition for this file as a {@link StructLike}, or null. */
+ /**
+ * Returns the partition for this file as a {@link StructLike} in the field order of the file's
Review Comment:
I think field order makes this sound like order is the issue, but what this needs to say is that the struct's type is the partition spec's output type. I would rephrase this to:
> Return the partition for this file as a struct with the partition spec's output 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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4138455551
##########
core/src/main/java/org/apache/iceberg/V4ManifestReader.java:
##########
@@ -72,7 +70,8 @@ static Builder uncommitted(
private final Schema readSchema;
private final String tableLocation;
private final InclusiveStatsEvaluator statsFilter;
- private final Map<Integer, Pair<Evaluator, StructProjection>> partitionFilters; // by spec ID
+ private final Map<Integer, Evaluator> partitionFilters; // by spec ID
+ private final Map<Integer, PartitionSpec> specsById;
Review Comment:
I think this should still track `StructProjection` and should set the projection on the `TrackedFileStruct`.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4148574616
##########
core/src/main/java/org/apache/iceberg/TrackedFileAdapters.java:
##########
@@ -101,7 +101,8 @@ public int specId() {
@Override
public StructLike partition() {
- return file().partition() != null ? file().partition() : PartitionData.EMPTY;
+ StructLike partition = file.partition();
+ return partition != null ? partition : PartitionData.EMPTY;
Review Comment:
If `file().partition()` is doing work on access that isn't reused, isn't that a problem?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "anoopj (via GitHub)" <gi...@apache.org>.
anoopj commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4048591712
##########
core/src/main/java/org/apache/iceberg/TrackedFileStruct.java:
##########
@@ -210,14 +214,27 @@ public long fileSizeInBytes() {
return fileSizeInBytes;
}
+ void setPartitionType(Types.StructType newPartitionType) {
+ this.partitionType = newPartitionType;
+ }
+
@Override
public Integer specId() {
return specId;
}
@Override
public StructLike partition() {
- return partitionData;
+ if (partitionData == null
+ || partitionType == null
+ || partitionData.getPartitionType().equals(partitionType)) {
+ return partitionData;
+ }
+
+ return new PartitionData(partitionType)
Review Comment:
We are intentionally not caching this for thread safety, so we pay the cost for a few object allocations. Note that in the common case (single spec manifests), we dont pay this cost.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "anoopj (via GitHub)" <gi...@apache.org>.
anoopj commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4009333330
##########
core/src/main/java/org/apache/iceberg/TrackedFileAdapters.java:
##########
@@ -549,6 +565,22 @@ public ManifestFile copy() {
}
}
+ // Manifests store partitions in the union of all specs' partition types, but each file's
+ // partition must be read using its own spec's field order.
+ private static StructLike projectPartition(StructLike partition, Types.StructType specType) {
+ if (partition == null) {
+ return PartitionData.EMPTY;
+ }
+
+ Types.StructType unionType = ((PartitionData) partition).getPartitionType();
+ if (unionType.equals(specType)) {
+ return partition;
+ }
+
+ return new PartitionData(specType)
+ .copyFor(StructProjection.create(unionType, specType).wrap(partition));
Review Comment:
Note to reviewers: We are doing three object allocations here, which isn't great. We can cache the first two (ie the `PartitionData` and `StructProjection`), but that will require changing the factory into a stateful class we can hang the cache on.
Is there a better option?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "anoopj (via GitHub)" <gi...@apache.org>.
anoopj commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4048591712
##########
core/src/main/java/org/apache/iceberg/TrackedFileStruct.java:
##########
@@ -210,14 +214,27 @@ public long fileSizeInBytes() {
return fileSizeInBytes;
}
+ void setPartitionType(Types.StructType newPartitionType) {
+ this.partitionType = newPartitionType;
+ }
+
@Override
public Integer specId() {
return specId;
}
@Override
public StructLike partition() {
- return partitionData;
+ if (partitionData == null
+ || partitionType == null
+ || partitionData.getPartitionType().equals(partitionType)) {
+ return partitionData;
+ }
+
+ return new PartitionData(partitionType)
Review Comment:
We are intentionally not caching this for thread safety, so we pay the cost for a few object allocations. Note that in the common case (single spec tables), we dont pay this cost.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4148692699
##########
core/src/main/java/org/apache/iceberg/TrackedFileStruct.java:
##########
@@ -80,14 +82,16 @@ class TrackedFileStruct extends SupportsIndexProjection implements TrackedFile,
private long[] splitOffsets = null;
private int[] equalityIds = null;
+ private transient StructProjection partitionProjection = null;
Review Comment:
If this is transient, then serialization will change the behavior of the tracked file. Is this `Serializable`? If so then we could make it non-transient. Otherwise we'll have to evaluate other options.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4148605545
##########
core/src/main/java/org/apache/iceberg/TrackedFileStruct.java:
##########
@@ -329,7 +341,7 @@ public String toString() {
.add("record_count", recordCount)
.add("file_size_in_bytes", fileSizeInBytes)
.add("spec_id", specId())
- .add("partition", partitionData)
+ .add("partition", partition)
Review Comment:
Minor: a follow up is to ensure that other classes used for partition also have a `toString` representation for debugging
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "anoopj (via GitHub)" <gi...@apache.org>.
anoopj commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4161454128
##########
core/src/main/java/org/apache/iceberg/TrackedFileAdapters.java:
##########
@@ -101,7 +101,8 @@ public int specId() {
@Override
public StructLike partition() {
- return file().partition() != null ? file().partition() : PartitionData.EMPTY;
+ StructLike partition = file.partition();
+ return partition != null ? partition : PartitionData.EMPTY;
Review Comment:
Reverted
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "anoopj (via GitHub)" <gi...@apache.org>.
anoopj commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4140061845
##########
core/src/main/java/org/apache/iceberg/V4ManifestReader.java:
##########
@@ -468,8 +472,10 @@ private Schema readSchema(boolean includePartition) {
ImmutableMap.of(TrackedFile.TRACKING.fieldId(), TrackingStruct.BASE_TYPE));
if (requestedProjection != null) {
+ boolean projectsPartition =
+ includePartition || requestedProjection.findField(TrackedFile.PARTITION_ID) != null;
Review Comment:
Exactly. It makes sure the whole partition struct are read whenever any partition field is needed. The caller can select a sub-field (e.g. `partition.id`). Restoring widens it to the full union tuple and pulls in `spec_id`.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "anoopj (via GitHub)" <gi...@apache.org>.
anoopj commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4040761650
##########
core/src/main/java/org/apache/iceberg/TrackedFileStruct.java:
##########
@@ -210,14 +216,55 @@ public long fileSizeInBytes() {
return fileSizeInBytes;
}
+ void setSpecsById(Map<Integer, PartitionSpec> newSpecsById) {
Review Comment:
Agree. Leaving it as is for now, and we can remove it as part of the change to recover partition tuple from stats.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "anoopj (via GitHub)" <gi...@apache.org>.
anoopj commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4048718448
##########
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:
FYI, I did this change, but this implementation had a thread safety issue, so I [changed](https://github.com/apache/iceberg/pull/18108/changes/bda24dabc70c69e54a4f830e947e0f620823c353) this.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "anoopj (via GitHub)" <gi...@apache.org>.
anoopj commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4040676857
##########
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) {
Review Comment:
Renamed.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "anoopj (via GitHub)" <gi...@apache.org>.
anoopj commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4040663147
##########
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() {
Review Comment:
Updated the javadocs
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4148803834
##########
core/src/test/java/org/apache/iceberg/TestTrackedFileStruct.java:
##########
@@ -340,6 +342,78 @@ void projectedStructLike() {
assertThat(file.get(1, Long.class)).isEqualTo(1024L);
}
+ @Test
+ void partitionIsProjectedOntoResolvedSpec() {
Review Comment:
I would say "to" rather than "onto".
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4148590408
##########
core/src/main/java/org/apache/iceberg/TrackedFileStruct.java:
##########
@@ -80,14 +82,16 @@ class TrackedFileStruct extends SupportsIndexProjection implements TrackedFile,
private long[] splitOffsets = null;
private int[] equalityIds = null;
+ private transient StructProjection partitionProjection = null;
+
/** Used by internal readers to instantiate this class with a projection schema. */
TrackedFileStruct(Types.StructType projection) {
super(BASE_TYPE, projection);
// partition type may be null if the field was not projected, or unknown for unpartitioned
// manifests
Type partType = projection.fieldType(TrackedFile.PARTITION_NAME);
if (partType != null && partType.isStructType()) {
- this.partitionData = new PartitionData(partType.asStructType());
+ this.partition = new PartitionData(partType.asStructType());
Review Comment:
It looks like this is not using the typical path for injecting a class for `InternalData` readers. Couldn't this just set `PartitionData.class` for the partition's field ID in the manifest reader?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#issuecomment-5956812187
Thanks for fixing this, @anoopj!
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4138493170
##########
core/src/main/java/org/apache/iceberg/V4ManifestReader.java:
##########
@@ -468,8 +472,10 @@ private Schema readSchema(boolean includePartition) {
ImmutableMap.of(TrackedFile.TRACKING.fieldId(), TrackingStruct.BASE_TYPE));
if (requestedProjection != null) {
+ boolean projectsPartition =
+ includePartition || requestedProjection.findField(TrackedFile.PARTITION_ID) != null;
Review Comment:
Is this to ensure that all partition fields are projected if one field is projected? I'm trying to understand the need for this change.
If the requested projection already includes the partition, then why should it be restored?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "anoopj (via GitHub)" <gi...@apache.org>.
anoopj commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4139992426
##########
core/src/main/java/org/apache/iceberg/TrackedFileStruct.java:
##########
@@ -210,14 +214,34 @@ public long fileSizeInBytes() {
return fileSizeInBytes;
}
+ void setPartitionType(Types.StructType newPartitionType) {
+ this.projectedPartition = project(partitionData, newPartitionType);
+ }
+
@Override
public Integer specId() {
return specId;
}
@Override
public StructLike partition() {
- return partitionData;
+ return projectedPartition != null ? projectedPartition : partitionData;
+ }
+
+ private static PartitionData copyOf(PartitionData partition) {
+ return partition != null ? partition.copy() : null;
+ }
+
+ private static PartitionData project(PartitionData partition, Types.StructType partitionType) {
Review Comment:
Thanks for the suggestion! This is much better. I changed it such that the projection is created once per spec ID and cached in the reader, and set on each struct. `partition()` just applies the pre-built projection, or returns the tuple as-is when there's none.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "anoopj (via GitHub)" <gi...@apache.org>.
anoopj commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4158341841
##########
core/src/main/java/org/apache/iceberg/TrackedFileAdapters.java:
##########
@@ -101,7 +101,8 @@ public int specId() {
@Override
public StructLike partition() {
- return file().partition() != null ? file().partition() : PartitionData.EMPTY;
+ StructLike partition = file.partition();
+ return partition != null ? partition : PartitionData.EMPTY;
Review Comment:
With the recent change we did to calculate most of the projection in the reader, the work done in `partition()` is fairly cheap. But calling it once and reusing the reference reads cleaner than evaluating the same method twice in the ternary. Happy to revert if you'd prefer to keep this method out of the diff entirely.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "anoopj (via GitHub)" <gi...@apache.org>.
anoopj commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4161483528
##########
core/src/main/java/org/apache/iceberg/TrackedFileStruct.java:
##########
@@ -210,14 +207,27 @@ public long fileSizeInBytes() {
return fileSizeInBytes;
}
+ void setPartitionProjection(StructProjection projection) {
+ this.partitionProjection = projection;
+ }
+
+ void clearPartition() {
+ this.partition = null;
+ this.partitionProjection = null;
+ }
+
@Override
public Integer specId() {
return specId;
}
@Override
public StructLike partition() {
- return partitionData;
+ if (partition == null || partitionProjection == null) {
Review Comment:
Added the check. I went with `ValidationException` instead of `IllegalStateException` to reconcile this with your filter comment on the test below.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "anoopj (via GitHub)" <gi...@apache.org>.
anoopj commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4150631673
##########
core/src/main/java/org/apache/iceberg/TrackedFileStruct.java:
##########
@@ -80,14 +82,16 @@ class TrackedFileStruct extends SupportsIndexProjection implements TrackedFile,
private long[] splitOffsets = null;
private int[] equalityIds = null;
+ private transient StructProjection partitionProjection = null;
+
/** Used by internal readers to instantiate this class with a projection schema. */
TrackedFileStruct(Types.StructType projection) {
super(BASE_TYPE, projection);
// partition type may be null if the field was not projected, or unknown for unpartitioned
// manifests
Type partType = projection.fieldType(TrackedFile.PARTITION_NAME);
if (partType != null && partType.isStructType()) {
- this.partitionData = new PartitionData(partType.asStructType());
+ this.partition = new PartitionData(partType.asStructType());
Review Comment:
You're right - It was unnecessary because reader already registers `setCustomType` for `PartitionData`. Ive removed it.
##########
core/src/test/java/org/apache/iceberg/TestTrackedFileStruct.java:
##########
@@ -340,6 +342,78 @@ void projectedStructLike() {
assertThat(file.get(1, Long.class)).isEqualTo(1024L);
}
+ @Test
+ void partitionIsProjectedOntoResolvedSpec() {
+ // a table whose partitioning evolved from id to category
+ Schema schema =
+ new Schema(
+ Types.NestedField.required(1, "id", Types.IntegerType.get()),
+ Types.NestedField.required(2, "category", Types.StringType.get()));
+ PartitionSpec idSpec =
+ PartitionSpec.builderFor(schema)
+ .withSpecId(0)
+ .add(1, 1000, "id", Transforms.identity())
+ .build();
+ PartitionSpec categorySpec =
+ PartitionSpec.builderFor(schema)
+ .withSpecId(1)
+ .add(2, 1001, "category", Transforms.identity())
+ .build();
+ Map<Integer, PartitionSpec> specsById =
+ ImmutableMap.of(idSpec.specId(), idSpec, categorySpec.specId(), categorySpec);
+
+ // the manifest stores partitions in the union type, where category sits after id
+ Types.StructType unionType = Partitioning.unionPartitionTypes(specsById.values());
+ int categoryUnionPos = unionType.fields().indexOf(unionType.field("category"));
+ PartitionData unionPartition = new PartitionData(unionType);
+ unionPartition.set(categoryUnionPos, "books");
+
+ TrackedFileStruct file = trackedFile(categorySpec.specId(), unionPartition);
+ file.setPartitionProjection(StructProjection.create(unionType, categorySpec.partitionType()));
+
+ // category is at position 1 in the union but position 0 in categorySpec; reading by the spec's
+ // ordinal must return category, not id (null)
+ assertThat(file.partition().get(0, CharSequence.class)).hasToString("books");
+
+ StructLike copyPartition = file.copy().partition();
+ unionPartition.set(categoryUnionPos, "changed");
+ assertThat(copyPartition.get(0, CharSequence.class)).hasToString("books");
+ }
+
+ @Test
+ void partitionReturnedAsIsWhenNoProjection() {
+ PartitionData partition =
+ new PartitionData(
+ Types.StructType.of(
+ Types.NestedField.required(1000, "category", Types.StringType.get())));
+ partition.set(0, "music");
+
+ TrackedFileStruct file = trackedFile(1, partition);
+
+ // no projection is set, so partition() returns the stored tuple unchanged
+ assertThat(file.partition()).isSameAs(partition);
+ }
+
+ private static TrackedFileStruct trackedFile(int specId, PartitionData partition) {
Review Comment:
Moved it to below.
##########
core/src/main/java/org/apache/iceberg/TrackedFileStruct.java:
##########
@@ -329,7 +341,7 @@ public String toString() {
.add("record_count", recordCount)
.add("file_size_in_bytes", fileSizeInBytes)
.add("spec_id", specId())
- .add("partition", partitionData)
+ .add("partition", partition)
Review Comment:
Will do.
##########
core/src/test/java/org/apache/iceberg/TestV4ManifestReader.java:
##########
@@ -1495,40 +1495,109 @@ public void partitionFilterWithMultipleSpecs(FileFormat format) throws IOExcepti
.build();
Map<Integer, PartitionSpec> specsById =
ImmutableMap.of(idSpec.specId(), idSpec, dataSpec.specId(), dataSpec);
-
- PartitionData dataPartitionX = partition(dataSpec, "x");
- TrackedFile dataPartitionedFile =
- dataFileWithoutStats(
- "s3://bucket/table/data=x/file-c.parquet", dataSpec.specId(), dataPartitionX);
-
- ManifestFile idPartitionedManifest =
- writeManifest(format, idSpec.partitionType(), ImmutableList.of(FILE_A, FILE_B));
- ManifestFile dataPartitionedManifest =
- writeManifest(format, dataSpec.partitionType(), dataPartitionedFile);
-
- List<TrackedFile> files = Lists.newArrayList();
- files.addAll(
- read(
- V4ManifestReader.builder(idPartitionedManifest, IO, TABLE_SCHEMA, specsById)
- .metricsConfig(METRICS_CONFIG)));
- files.addAll(
- read(
- V4ManifestReader.builder(dataPartitionedManifest, IO, TABLE_SCHEMA, specsById)
- .metricsConfig(METRICS_CONFIG)));
-
Types.StructType unionType = Partitioning.unionPartitionTypes(specsById.values());
+ int idPos = unionType.fields().indexOf(unionType.field("id"));
+ int dataPos = unionType.fields().indexOf(unionType.field("data"));
+
+ // a mixed-spec manifest stores every file's partition in the union type
+ PartitionData idOne = new PartitionData(unionType);
+ idOne.set(idPos, 1);
+ PartitionData idTwo = new PartitionData(unionType);
+ idTwo.set(idPos, 2);
+ PartitionData dataX = new PartitionData(unionType);
+ dataX.set(dataPos, "x");
+
+ TrackedFile idFileKept =
+ dataFileWithoutStats("s3://bucket/table/id=1/file-a.parquet", idSpec.specId(), idOne);
+ TrackedFile idFilePruned =
+ dataFileWithoutStats("s3://bucket/table/id=2/file-b.parquet", idSpec.specId(), idTwo);
+ TrackedFile dataFile =
+ dataFileWithoutStats("s3://bucket/table/data=x/file-c.parquet", dataSpec.specId(), dataX);
- ManifestFile manifest = writeManifest(format, unionType, files);
+ ManifestFile manifest =
+ writeManifest(format, unionType, ImmutableList.of(idFileKept, idFilePruned, dataFile));
V4ManifestReader.Builder builder =
V4ManifestReader.builder(manifest, IO, TABLE_SCHEMA, specsById)
.filter(Expressions.equal("id", 1))
.metricsConfig(METRICS_CONFIG);
- // the comparator is built for ID partitioning, so only check the location
assertThat(read(builder))
.extracting(TrackedFile::location)
- .containsExactlyInAnyOrder(FILE_A.location(), dataPartitionedFile.location());
+ .containsExactlyInAnyOrder(idFileKept.location(), dataFile.location());
+ }
+
+ @ParameterizedTest
+ @FieldSource("MANIFEST_FORMATS")
+ public void narrowPartitionProjectionReadsFullUnionTuple(FileFormat format) throws IOException {
+ PartitionSpec idSpec =
+ PartitionSpec.builderFor(TABLE_SCHEMA)
+ .withSpecId(1)
+ .add(1, 1000, "id", Transforms.identity())
+ .build();
+ PartitionSpec dataSpec =
+ PartitionSpec.builderFor(TABLE_SCHEMA)
+ .withSpecId(2)
+ .add(2, 1001, "data", Transforms.identity())
+ .build();
+ Map<Integer, PartitionSpec> specsById =
+ ImmutableMap.of(idSpec.specId(), idSpec, dataSpec.specId(), dataSpec);
+ Types.StructType unionType = Partitioning.unionPartitionTypes(specsById.values());
+
+ PartitionData unionPartition = new PartitionData(unionType);
+ unionPartition.set(unionType.fields().indexOf(unionType.field("data")), "x");
+ TrackedFile file =
+ dataFileWithoutStats(
+ "s3://bucket/table/data=x/file.parquet", dataSpec.specId(), unionPartition);
+ ManifestFile manifest = writeManifest(format, unionType, ImmutableList.of(file));
+
+ TrackedFile actual =
+ readOne(
+ V4ManifestReader.builder(manifest, IO, TABLE_SCHEMA, specsById)
+ .metricsConfig(METRICS_CONFIG)
+ .select("partition.id"));
+ assertThat(actual.partition().get(0, CharSequence.class)).hasToString("x");
+ }
+
+ @ParameterizedTest
+ @FieldSource("MANIFEST_FORMATS")
+ public void unknownSpecPartitionIsNotProjected(FileFormat format) throws IOException {
Review Comment:
I agree. I went with `null` so that an unknown spec can't be projected to its output type, so `partition()` returns null instead of the raw union tuple. Also renamed the tests.
##########
core/src/test/java/org/apache/iceberg/TestTrackedFileStruct.java:
##########
@@ -387,6 +461,38 @@ void serializationRoundTrip(RoundTripSerializer<TrackedFileStruct> serializer) t
assertThat(deserialized.equalityIds()).containsExactly(1, 2, 3);
}
+ @ParameterizedTest
+ @MethodSource("org.apache.iceberg.TestHelpers#serializers")
+ void partitionProjectionSurvivesSerialization(RoundTripSerializer<TrackedFileStruct> serializer)
+ throws Exception {
+ Schema schema =
+ new Schema(
+ Types.NestedField.required(1, "id", Types.IntegerType.get()),
+ Types.NestedField.required(2, "category", Types.StringType.get()));
+ PartitionSpec idSpec =
+ PartitionSpec.builderFor(schema)
+ .withSpecId(0)
+ .add(1, 1000, "id", Transforms.identity())
+ .build();
+ PartitionSpec categorySpec =
+ PartitionSpec.builderFor(schema)
+ .withSpecId(1)
+ .add(2, 1001, "category", Transforms.identity())
+ .build();
+ Map<Integer, PartitionSpec> specsById =
+ ImmutableMap.of(idSpec.specId(), idSpec, categorySpec.specId(), categorySpec);
+
+ Types.StructType unionType = Partitioning.unionPartitionTypes(specsById.values());
+ PartitionData unionPartition = new PartitionData(unionType);
+ unionPartition.set(unionType.fields().indexOf(unionType.field("category")), "books");
+
+ TrackedFileStruct file = trackedFile(categorySpec.specId(), unionPartition);
+ file.setPartitionProjection(StructProjection.create(unionType, categorySpec.partitionType()));
+
+ TrackedFileStruct deserialized = serializer.apply((TrackedFileStruct) file.copy());
Review Comment:
Done.
##########
core/src/test/java/org/apache/iceberg/TestTrackedFileStruct.java:
##########
@@ -340,6 +342,78 @@ void projectedStructLike() {
assertThat(file.get(1, Long.class)).isEqualTo(1024L);
}
+ @Test
+ void partitionIsProjectedOntoResolvedSpec() {
Review Comment:
Done.
##########
core/src/test/java/org/apache/iceberg/TestTrackedFileStruct.java:
##########
@@ -340,6 +342,78 @@ void projectedStructLike() {
assertThat(file.get(1, Long.class)).isEqualTo(1024L);
}
+ @Test
+ void partitionIsProjectedOntoResolvedSpec() {
+ // a table whose partitioning evolved from id to category
+ Schema schema =
+ new Schema(
+ Types.NestedField.required(1, "id", Types.IntegerType.get()),
+ Types.NestedField.required(2, "category", Types.StringType.get()));
+ PartitionSpec idSpec =
+ PartitionSpec.builderFor(schema)
+ .withSpecId(0)
+ .add(1, 1000, "id", Transforms.identity())
+ .build();
+ PartitionSpec categorySpec =
+ PartitionSpec.builderFor(schema)
+ .withSpecId(1)
+ .add(2, 1001, "category", Transforms.identity())
+ .build();
+ Map<Integer, PartitionSpec> specsById =
+ ImmutableMap.of(idSpec.specId(), idSpec, categorySpec.specId(), categorySpec);
+
+ // the manifest stores partitions in the union type, where category sits after id
+ Types.StructType unionType = Partitioning.unionPartitionTypes(specsById.values());
+ int categoryUnionPos = unionType.fields().indexOf(unionType.field("category"));
+ PartitionData unionPartition = new PartitionData(unionType);
+ unionPartition.set(categoryUnionPos, "books");
+
+ TrackedFileStruct file = trackedFile(categorySpec.specId(), unionPartition);
+ file.setPartitionProjection(StructProjection.create(unionType, categorySpec.partitionType()));
+
+ // category is at position 1 in the union but position 0 in categorySpec; reading by the spec's
+ // ordinal must return category, not id (null)
+ assertThat(file.partition().get(0, CharSequence.class)).hasToString("books");
Review Comment:
Thanks, done.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4148827749
##########
core/src/test/java/org/apache/iceberg/TestTrackedFileStruct.java:
##########
@@ -340,6 +342,78 @@ void projectedStructLike() {
assertThat(file.get(1, Long.class)).isEqualTo(1024L);
}
+ @Test
+ void partitionIsProjectedOntoResolvedSpec() {
+ // a table whose partitioning evolved from id to category
+ Schema schema =
+ new Schema(
+ Types.NestedField.required(1, "id", Types.IntegerType.get()),
+ Types.NestedField.required(2, "category", Types.StringType.get()));
+ PartitionSpec idSpec =
+ PartitionSpec.builderFor(schema)
+ .withSpecId(0)
+ .add(1, 1000, "id", Transforms.identity())
+ .build();
+ PartitionSpec categorySpec =
+ PartitionSpec.builderFor(schema)
+ .withSpecId(1)
+ .add(2, 1001, "category", Transforms.identity())
+ .build();
+ Map<Integer, PartitionSpec> specsById =
+ ImmutableMap.of(idSpec.specId(), idSpec, categorySpec.specId(), categorySpec);
+
+ // the manifest stores partitions in the union type, where category sits after id
+ Types.StructType unionType = Partitioning.unionPartitionTypes(specsById.values());
+ int categoryUnionPos = unionType.fields().indexOf(unionType.field("category"));
+ PartitionData unionPartition = new PartitionData(unionType);
+ unionPartition.set(categoryUnionPos, "books");
+
+ TrackedFileStruct file = trackedFile(categorySpec.specId(), unionPartition);
+ file.setPartitionProjection(StructProjection.create(unionType, categorySpec.partitionType()));
+
+ // category is at position 1 in the union but position 0 in categorySpec; reading by the spec's
+ // ordinal must return category, not id (null)
+ assertThat(file.partition().get(0, CharSequence.class)).hasToString("books");
Review Comment:
Probably better to use a StructComparator instead of dealing with CharSequence and `hasToString`.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4149015819
##########
core/src/test/java/org/apache/iceberg/TestTrackedFileStruct.java:
##########
@@ -387,6 +461,38 @@ void serializationRoundTrip(RoundTripSerializer<TrackedFileStruct> serializer) t
assertThat(deserialized.equalityIds()).containsExactly(1, 2, 3);
}
+ @ParameterizedTest
+ @MethodSource("org.apache.iceberg.TestHelpers#serializers")
+ void partitionProjectionSurvivesSerialization(RoundTripSerializer<TrackedFileStruct> serializer)
+ throws Exception {
+ Schema schema =
+ new Schema(
+ Types.NestedField.required(1, "id", Types.IntegerType.get()),
+ Types.NestedField.required(2, "category", Types.StringType.get()));
+ PartitionSpec idSpec =
+ PartitionSpec.builderFor(schema)
+ .withSpecId(0)
+ .add(1, 1000, "id", Transforms.identity())
+ .build();
+ PartitionSpec categorySpec =
+ PartitionSpec.builderFor(schema)
+ .withSpecId(1)
+ .add(2, 1001, "category", Transforms.identity())
+ .build();
+ Map<Integer, PartitionSpec> specsById =
+ ImmutableMap.of(idSpec.specId(), idSpec, categorySpec.specId(), categorySpec);
+
+ Types.StructType unionType = Partitioning.unionPartitionTypes(specsById.values());
+ PartitionData unionPartition = new PartitionData(unionType);
+ unionPartition.set(unionType.fields().indexOf(unionType.field("category")), "books");
+
+ TrackedFileStruct file = trackedFile(categorySpec.specId(), unionPartition);
+ file.setPartitionProjection(StructProjection.create(unionType, categorySpec.partitionType()));
+
+ TrackedFileStruct deserialized = serializer.apply((TrackedFileStruct) file.copy());
Review Comment:
Calling `file.copy` here compromises this test because the actual `TrackedFileStruct` doesn't produce the right data when serialized. But if you copy it first, it does.
I think this is okay behavior, especially since we are likely going to remove the partition. Let's fix this by updating the test name. Just add "AfterCopy" to the end.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4138439381
##########
core/src/main/java/org/apache/iceberg/TrackedFileStruct.java:
##########
@@ -210,14 +214,34 @@ public long fileSizeInBytes() {
return fileSizeInBytes;
}
+ void setPartitionType(Types.StructType newPartitionType) {
+ this.projectedPartition = project(partitionData, newPartitionType);
+ }
+
@Override
public Integer specId() {
return specId;
}
@Override
public StructLike partition() {
- return partitionData;
+ return projectedPartition != null ? projectedPartition : partitionData;
+ }
+
+ private static PartitionData copyOf(PartitionData partition) {
+ return partition != null ? partition.copy() : null;
+ }
+
+ private static PartitionData project(PartitionData partition, Types.StructType partitionType) {
Review Comment:
I don't think that this logic should be done for every row. There are fairly expensive operations here (comparing the partition tuple and building a projection) that don't need to be done in a tight loop because the result can be cached based on the spec ID.
It looks like part of the motivation here is to continue using `partition.getPartitionType()`, but that is only necessary if the requested projection is unknown. It will be cleaner to change the underlying partition to a `StructLike` and avoid using its partition-specific methods.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4021249214
##########
core/src/main/java/org/apache/iceberg/TrackedFileStruct.java:
##########
@@ -210,14 +216,55 @@ public long fileSizeInBytes() {
return fileSizeInBytes;
}
+ void setSpecsById(Map<Integer, PartitionSpec> newSpecsById) {
Review Comment:
I'm not a fan of needing to set specs on the class like this. I think maybe it would be cleaner to just do the work to remove `partition()`.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4138375306
##########
core/src/main/java/org/apache/iceberg/TrackedFileAdapters.java:
##########
@@ -101,7 +101,8 @@ public int specId() {
@Override
public StructLike partition() {
- return file().partition() != null ? file().partition() : PartitionData.EMPTY;
+ StructLike partition = file.partition();
+ return partition != null ? partition : PartitionData.EMPTY;
Review Comment:
This looks like a noop to me. Am I missing something?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "anoopj (via GitHub)" <gi...@apache.org>.
anoopj commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4139319256
##########
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));
+ }
+
+ return partitionProjections.get(id);
+ }
+
+ private PartitionData materializedPartition() {
Review Comment:
Looks like you recently made `StructCopy` `Serializable`. Will change this back.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4159044560
##########
core/src/main/java/org/apache/iceberg/V4ManifestReader.java:
##########
@@ -161,6 +165,19 @@ private TrackedFile applyInheritance(TrackedFile file) {
return file;
}
+ private TrackedFile projectPartition(TrackedFile file) {
+ Integer specId = file.specId();
+ StructProjection projection = specId != null ? partitionProjections.get(specId) : null;
+ TrackedFileStruct struct = (TrackedFileStruct) file;
+ if (specId != null && projection == null) {
Review Comment:
Should this check be that `projection` is not present, rather than null?
I think we are using `null` to signal to `TrackedFile` that no projection is necessary. That's why when the projection is null, we return the partition directly. So we could have a case where the spec ID was present in the map, but the value was null. In that case, we don't want to clear the partition value.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "anoopj (via GitHub)" <gi...@apache.org>.
anoopj commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4161543200
##########
core/src/main/java/org/apache/iceberg/V4ManifestReader.java:
##########
@@ -161,6 +165,19 @@ private TrackedFile applyInheritance(TrackedFile file) {
return file;
}
+ private TrackedFile projectPartition(TrackedFile file) {
+ Integer specId = file.specId();
+ StructProjection projection = specId != null ? partitionProjections.get(specId) : null;
+ TrackedFileStruct struct = (TrackedFileStruct) file;
+ if (specId != null && projection == null) {
Review Comment:
Good catch. Yes we only want to clear the partition when the spec ID isn't in the map at all. I switched to `containsKey` rather than relying on `null`.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "anoopj (via GitHub)" <gi...@apache.org>.
anoopj commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4161550752
##########
core/src/test/java/org/apache/iceberg/TestV4ManifestReader.java:
##########
@@ -1548,7 +1619,10 @@ public void partitionFilterKeepsFileWithUnknownSpec(FileFormat format) throws IO
TrackedFile actual = readOne(builder);
- assertThat(actual).usingComparator(FILE_COMPARATOR).isEqualTo(file);
+ assertThat(actual.location()).isEqualTo(file.location());
+ assertThat(actual.partition())
+ .as("unknown spec's partition cannot be projected to its output type")
+ .isNull();
Review Comment:
Done. The test now asserts the file is returned and that `partition()` throws `ValidationException` instead of returning null.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue merged PR #18108:
URL: https://github.com/apache/iceberg/pull/18108
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4148798920
##########
core/src/test/java/org/apache/iceberg/TestTrackedFileStruct.java:
##########
@@ -340,6 +342,78 @@ void projectedStructLike() {
assertThat(file.get(1, Long.class)).isEqualTo(1024L);
}
+ @Test
+ void partitionIsProjectedOntoResolvedSpec() {
+ // a table whose partitioning evolved from id to category
+ Schema schema =
+ new Schema(
+ Types.NestedField.required(1, "id", Types.IntegerType.get()),
+ Types.NestedField.required(2, "category", Types.StringType.get()));
+ PartitionSpec idSpec =
+ PartitionSpec.builderFor(schema)
+ .withSpecId(0)
+ .add(1, 1000, "id", Transforms.identity())
+ .build();
+ PartitionSpec categorySpec =
+ PartitionSpec.builderFor(schema)
+ .withSpecId(1)
+ .add(2, 1001, "category", Transforms.identity())
+ .build();
+ Map<Integer, PartitionSpec> specsById =
+ ImmutableMap.of(idSpec.specId(), idSpec, categorySpec.specId(), categorySpec);
+
+ // the manifest stores partitions in the union type, where category sits after id
+ Types.StructType unionType = Partitioning.unionPartitionTypes(specsById.values());
+ int categoryUnionPos = unionType.fields().indexOf(unionType.field("category"));
+ PartitionData unionPartition = new PartitionData(unionType);
+ unionPartition.set(categoryUnionPos, "books");
+
+ TrackedFileStruct file = trackedFile(categorySpec.specId(), unionPartition);
+ file.setPartitionProjection(StructProjection.create(unionType, categorySpec.partitionType()));
+
+ // category is at position 1 in the union but position 0 in categorySpec; reading by the spec's
+ // ordinal must return category, not id (null)
+ assertThat(file.partition().get(0, CharSequence.class)).hasToString("books");
+
+ StructLike copyPartition = file.copy().partition();
+ unionPartition.set(categoryUnionPos, "changed");
+ assertThat(copyPartition.get(0, CharSequence.class)).hasToString("books");
+ }
+
+ @Test
+ void partitionReturnedAsIsWhenNoProjection() {
+ PartitionData partition =
+ new PartitionData(
+ Types.StructType.of(
+ Types.NestedField.required(1000, "category", Types.StringType.get())));
+ partition.set(0, "music");
+
+ TrackedFileStruct file = trackedFile(1, partition);
+
+ // no projection is set, so partition() returns the stored tuple unchanged
+ assertThat(file.partition()).isSameAs(partition);
+ }
+
+ private static TrackedFileStruct trackedFile(int specId, PartitionData partition) {
Review Comment:
Helper methods are usually not defined between test cases.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "anoopj (via GitHub)" <gi...@apache.org>.
anoopj commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4018482907
##########
core/src/test/java/org/apache/iceberg/TestV4ManifestReader.java:
##########
@@ -684,6 +684,38 @@ public void filterMatchesFilesAcrossDisjointSpecs(FileFormat format) throws IOEx
}
}
+ @ParameterizedTest
+ @FieldSource("MANIFEST_FORMATS")
+ public void narrowPartitionProjectionReadsFullUnionTuple(FileFormat format) throws IOException {
+ PartitionSpec idSpec =
+ PartitionSpec.builderFor(TABLE_SCHEMA)
+ .withSpecId(0)
+ .add(1, 1000, "id", Transforms.identity())
+ .build();
+ PartitionSpec dataSpec =
+ PartitionSpec.builderFor(TABLE_SCHEMA)
+ .withSpecId(1)
+ .add(2, 1001, "data", Transforms.identity())
+ .build();
+ Map<Integer, PartitionSpec> specsById =
+ ImmutableMap.of(idSpec.specId(), idSpec, dataSpec.specId(), dataSpec);
+ Types.StructType unionType = Partitioning.unionPartitionTypes(specsById.values());
+
+ TrackedFile file =
+ dataFile("by-data.parquet", dataSpec.specId(), unionPartition(unionType, null, "x"));
+ ManifestFile manifest = writeManifest(format, unionType, ImmutableList.of(file));
+
+ // select id, which this file's spec does not use; the reader must still read the whole union
+ // tuple (including data) so partition() can project it onto the file's data spec
+ try (V4ManifestReader reader =
+ V4ManifestReader.builder(manifest, io, specsById, TABLE_LOCATION)
+ .select("partition.id")
Review Comment:
selecting `id` is intentional, btw. hopefully the comment on line 708 is clear.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "anoopj (via GitHub)" <gi...@apache.org>.
anoopj commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4048990989
##########
core/src/main/java/org/apache/iceberg/TrackedFileStruct.java:
##########
@@ -210,14 +214,27 @@ public long fileSizeInBytes() {
return fileSizeInBytes;
}
+ void setPartitionType(Types.StructType newPartitionType) {
+ this.partitionType = newPartitionType;
+ }
+
@Override
public Integer specId() {
return specId;
}
@Override
public StructLike partition() {
- return partitionData;
+ if (partitionData == null
+ || partitionType == null
+ || partitionData.getPartitionType().equals(partitionType)) {
+ return partitionData;
+ }
+
+ return new PartitionData(partitionType)
Review Comment:
Not a problem anymore: added caching.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "anoopj (via GitHub)" <gi...@apache.org>.
anoopj commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4040815289
##########
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));
+ }
+
+ return partitionProjections.get(id);
+ }
+
+ private PartitionData materializedPartition() {
Review Comment:
Actually that didn't work because `StructLikeUtil.copy(...)` returns a `StructCopy` which isn't `Serializable`. So it has to stay a serializable `PartitionData` and we need to keep `PartitionData.copy()/copyFor(...)`.
Or should we make `StructLikeUtil.copy` serializable? (felt out of scope for this PR)
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "anoopj (via GitHub)" <gi...@apache.org>.
anoopj commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4009386846
##########
core/src/main/java/org/apache/iceberg/TrackedFileAdapters.java:
##########
@@ -549,6 +565,22 @@ public ManifestFile copy() {
}
}
+ // Manifests store partitions in the union of all specs' partition types, but each file's
+ // partition must be read using its own spec's field order.
+ private static StructLike projectPartition(StructLike partition, Types.StructType specType) {
+ if (partition == null) {
+ return PartitionData.EMPTY;
+ }
+
+ Types.StructType unionType = ((PartitionData) partition).getPartitionType();
+ if (unionType.equals(specType)) {
+ return partition;
+ }
+
+ return new PartitionData(specType)
+ .copyFor(StructProjection.create(unionType, specType).wrap(partition));
Review Comment:
I don't know if it's worth optimizing also, because mixed spec manifests aren't that common. We don't do these allocations on manifests with a single spec.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "yangshangqing95 (via GitHub)" <gi...@apache.org>.
yangshangqing95 commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4020129740
##########
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() {
Review Comment:
Nit, non-blocking: could we make the `TrackedFile.partition()` contract explicit that the returned struct is shaped/ordered according to the file's resolved partition spec? This PR makes that invariant important for adapters and downstream evaluators, while the current method Javadoc only says it returns the partition.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4138471771
##########
core/src/main/java/org/apache/iceberg/V4ManifestReader.java:
##########
@@ -153,6 +154,12 @@ private TrackedFile applyInheritance(TrackedFile file) {
}
}
+ Integer specId = file.specId();
+ PartitionSpec spec = specId != null ? specsById.get(specId) : null;
+ if (file instanceof TrackedFileStruct) {
+ ((TrackedFileStruct) file).setPartitionType(spec != null ? spec.partitionType() : null);
Review Comment:
There's no need to check using `instanceof`. As the comments above state, the `InternalData` reader is configured to use `TrackingStruct` and in this case, `TrackedFileStruct` so we can assume that here.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4138390910
##########
core/src/main/java/org/apache/iceberg/TrackedFileStruct.java:
##########
@@ -142,7 +145,8 @@ private TrackedFileStruct(TrackedFileStruct toCopy, Set<Integer> statsIds) {
this.recordCount = toCopy.recordCount;
this.fileSizeInBytes = toCopy.fileSizeInBytes;
this.specId = toCopy.specId;
- this.partitionData = toCopy.partitionData != null ? toCopy.partitionData.copy() : null;
+ this.partitionData = copyOf(toCopy.partitionData);
Review Comment:
Why does the copy retain the original partition? I think this should just copy the projection.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4138463421
##########
core/src/main/java/org/apache/iceberg/V4ManifestReader.java:
##########
@@ -153,6 +154,12 @@ private TrackedFile applyInheritance(TrackedFile file) {
}
}
+ Integer specId = file.specId();
+ PartitionSpec spec = specId != null ? specsById.get(specId) : null;
+ if (file instanceof TrackedFileStruct) {
Review Comment:
This isn't related to inheritance, so I don't think this belongs in the inheritance method.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "rdblue (via GitHub)" <gi...@apache.org>.
rdblue commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4149028149
##########
core/src/main/java/org/apache/iceberg/TrackedFileStruct.java:
##########
@@ -80,14 +82,16 @@ class TrackedFileStruct extends SupportsIndexProjection implements TrackedFile,
private long[] splitOffsets = null;
private int[] equalityIds = null;
+ private transient StructProjection partitionProjection = null;
Review Comment:
I think this is okay. The best option is to copy the partition data during serialization. That's what is actually tested, and it's a good solution. Since the reader is going to copy when it returns records, this should be safe. I'm going to resolve this.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Core: Project tracked-file partitions onto the resolved spec [iceberg]
Posted by "anoopj (via GitHub)" <gi...@apache.org>.
anoopj commented on code in PR #18108:
URL: https://github.com/apache/iceberg/pull/18108#discussion_r4139994771
##########
core/src/main/java/org/apache/iceberg/V4ManifestReader.java:
##########
@@ -72,7 +70,8 @@ static Builder uncommitted(
private final Schema readSchema;
private final String tableLocation;
private final InclusiveStatsEvaluator statsFilter;
- private final Map<Integer, Pair<Evaluator, StructProjection>> partitionFilters; // by spec ID
+ private final Map<Integer, Evaluator> partitionFilters; // by spec ID
+ private final Map<Integer, PartitionSpec> specsById;
Review Comment:
Done - the reader now holds it and sets it on the struct.
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org