harshilv17 commented on code in PR #2521:
URL: https://github.com/apache/iceberg-go/pull/2521#discussion_r4695605969


##########
table/row_delta.go:
##########
@@ -465,6 +469,77 @@ func (rd *RowDelta) validateAddedDeletionVectors() error {
        return nil
 }
 
+// validateDeletesMatchDataFiles rejects an added position delete file
+// that names its data file in referenced_data_file, a deletion vector or a
+// v2 file-scoped position delete, when its partition spec or partition
+// differs from that data file's. The spec requires them to match. Scans
+// match deletion vectors by path alone, so a mismatched DV would otherwise
+// commit and be applied, and a mismatched v2 position delete would commit
+// a table whose scans fail. A reference to a data file that is neither
+// added here nor live in the current snapshot is left to the conflict
+// checks.
+func (rd *RowDelta) validateDeletesMatchDataFiles(ctx context.Context, fs 
iceio.IO, meta *MetadataBuilder) error {
+       byRef := make(map[string][]iceberg.DataFile)
+       for _, f := range rd.delFiles {
+               if f.ContentType() != iceberg.EntryContentPosDeletes {
+                       continue
+               }
+               if ref := explicitReferencedDataFile(f); ref != "" {
+                       byRef[ref] = append(byRef[ref], f)
+               }
+       }
+       if len(byRef) == 0 {
+               return nil
+       }
+
+       check := func(data iceberg.DataFile) error {
+               dels, ok := byRef[data.FilePath()]
+               if !ok {
+                       return nil
+               }
+               delete(byRef, data.FilePath())
+               for _, del := range dels {
+                       if del.SpecID() != data.SpecID() {
+                               return fmt.Errorf("delete file %s uses 
partition spec %d, but its referenced data file %s uses partition spec %d; 
write the delete file with the data file's spec",
+                                       del.FilePath(), del.SpecID(), 
data.FilePath(), data.SpecID())
+                       }
+                       if !partitionsMatch(dataFilePartition(data), 
dataFilePartition(del)) {
+                               return fmt.Errorf("delete file %s partition 
does not match its referenced data file %s",
+                                       del.FilePath(), data.FilePath())
+                       }

Review Comment:
   Good catch. Switched to `canonicalPartitionKey` for both sides, so an int32 
day vs `iceberg.Date` now matches, and dropped the `DecimalLiteral` case from 
`ComparablePartitionKey` since the canonical key already covers it. Added 
`TestRowDeltaDVDatePartitionComparedByValue`.



##########
table/row_delta.go:
##########
@@ -465,6 +469,77 @@ func (rd *RowDelta) validateAddedDeletionVectors() error {
        return nil
 }
 
+// validateDeletesMatchDataFiles rejects an added position delete file
+// that names its data file in referenced_data_file, a deletion vector or a
+// v2 file-scoped position delete, when its partition spec or partition
+// differs from that data file's. The spec requires them to match. Scans
+// match deletion vectors by path alone, so a mismatched DV would otherwise
+// commit and be applied, and a mismatched v2 position delete would commit
+// a table whose scans fail. A reference to a data file that is neither
+// added here nor live in the current snapshot is left to the conflict
+// checks.
+func (rd *RowDelta) validateDeletesMatchDataFiles(ctx context.Context, fs 
iceio.IO, meta *MetadataBuilder) error {
+       byRef := make(map[string][]iceberg.DataFile)
+       for _, f := range rd.delFiles {
+               if f.ContentType() != iceberg.EntryContentPosDeletes {
+                       continue
+               }
+               if ref := explicitReferencedDataFile(f); ref != "" {
+                       byRef[ref] = append(byRef[ref], f)
+               }

Review Comment:
   Now resolved with `referencedDataFilePath`, so a v2 pos-delete with equal 
`file_path` bounds is checked too, and the doc comment says so. Added 
`TestRowDeltaV2PosDeleteScopedByBoundsMustMatchDataFile`.



##########
table/dynamic_partition_overwrite_test.go:
##########
@@ -595,10 +595,10 @@ func 
TestDynamicPartitionOverwriteKeepsDeleteForSurvivingOldSpecData(t *testing.
        require.NotZero(t, fieldID)
        nullPartition := map[int]any{fieldID: nil}
 
-       // A v2 position delete can target an old-spec data file even if its
-       // manifest stores it under a new partition tuple with a null value.
-       posDelete := newTestPosDeleteFileForSpec(t, currentSpec, 
"file://old-spec-delete.parquet",
-               nullPartition, oldData.FilePath())
+       // A v2 position delete for an old-spec data file carries that file's
+       // spec and partition; overwriting the new spec's partitions must keep 
it.
+       posDelete := newTestPosDeleteFileForSpec(t, oldSpec, 
"file://old-spec-delete.parquet",
+               map[int]any{1000: int32(1)}, oldData.FilePath())

Review Comment:
   Agreed, my fixture change made those checks pointless. Both tests are back 
on the original layout (current spec, null field), committed through the 
fast-append producer via a small `commitLegacyPosDelete` helper, since RowDelta 
now rejects that layout.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to