nastra commented on code in PR #14573:
URL: https://github.com/apache/iceberg/pull/14573#discussion_r2522055590


##########
core/src/test/java/org/apache/iceberg/rest/responses/TestPlanTableScanResponseParser.java:
##########
@@ -265,6 +269,81 @@ public void 
roundTripSerdeWithValidStatusAndFileScanTasks() {
     
assertThat(PlanTableScanResponseParser.toJson(copyResponse)).isEqualTo(expectedToJson);
   }
 
+  @Test
+  public void multipleTasksWithDifferentDeleteFilesDontAccumulateReferences() {
+    ResidualEvaluator residualEvaluator =
+        ResidualEvaluator.of(SPEC, Expressions.alwaysTrue(), true);
+
+    // Create three tasks, each with its own distinct delete file
+    FileScanTask taskA =
+        new BaseFileScanTask(
+            FILE_A,
+            new DeleteFile[] {FILE_A_DELETES},
+            SchemaParser.toJson(SCHEMA),
+            PartitionSpecParser.toJson(SPEC),
+            residualEvaluator);
+
+    FileScanTask taskB =
+        new BaseFileScanTask(
+            FILE_B,
+            new DeleteFile[] {FILE_B_DELETES},
+            SchemaParser.toJson(SCHEMA),
+            PartitionSpecParser.toJson(SPEC),
+            residualEvaluator);
+
+    FileScanTask taskC =
+        new BaseFileScanTask(
+            FILE_C,
+            new DeleteFile[] {FILE_C2_DELETES},
+            SchemaParser.toJson(SCHEMA),
+            PartitionSpecParser.toJson(SPEC),
+            residualEvaluator);
+
+    PlanTableScanResponse response =
+        PlanTableScanResponse.builder()
+            .withPlanStatus(PlanStatus.COMPLETED)
+            .withFileScanTasks(List.of(taskA, taskB, taskC))
+            .withDeleteFiles(List.of(FILE_A_DELETES, FILE_B_DELETES, 
FILE_C2_DELETES))
+            .withSpecsById(PARTITION_SPECS_BY_ID)
+            .build();
+
+    String json = PlanTableScanResponseParser.toJson(response);
+
+    // Verify each task only references its own delete file
+    // Task A should reference index 0 (fileADeletes)
+    // Task B should reference index 1 (fileBDeletes)
+    // Task C should reference index 2 (fileCDeletes)
+    assertThat(json).contains("\"delete-file-references\":[0]");
+    assertThat(json).contains("\"delete-file-references\":[1]");
+    assertThat(json).contains("\"delete-file-references\":[2]");
+
+    // Verify that no task has accumulated references (e.g., [0,1] or [0,1,2])
+    assertThat(json).doesNotContain("\"delete-file-references\":[0,1]");

Review Comment:
   maybe just having a comparison against the full JSON is enough?
   
   ```
   String expectedJson =
           "{\n"
               + "  \"plan-status\" : \"completed\",\n"
               + "  \"delete-files\" : [ {\n"
               + "    \"spec-id\" : 0,\n"
               + "    \"content\" : \"POSITION_DELETES\",\n"
               + "    \"file-path\" : \"/path/to/data-a-deletes.parquet\",\n"
               + "    \"file-format\" : \"PARQUET\",\n"
               + "    \"partition\" : {\n"
               + "      \"1000\" : 0\n"
               + "    },\n"
               + "    \"file-size-in-bytes\" : 10,\n"
               + "    \"record-count\" : 1\n"
               + "  }, {\n"
               + "    \"spec-id\" : 0,\n"
               + "    \"content\" : \"POSITION_DELETES\",\n"
               + "    \"file-path\" : \"/path/to/data-b-deletes.parquet\",\n"
               + "    \"file-format\" : \"PARQUET\",\n"
               + "    \"partition\" : {\n"
               + "      \"1000\" : 1\n"
               + "    },\n"
               + "    \"file-size-in-bytes\" : 10,\n"
               + "    \"record-count\" : 1\n"
               + "  }, {\n"
               + "    \"spec-id\" : 0,\n"
               + "    \"content\" : \"EQUALITY_DELETES\",\n"
               + "    \"file-path\" : \"/path/to/data-c-deletes.parquet\",\n"
               + "    \"file-format\" : \"PARQUET\",\n"
               + "    \"partition\" : {\n"
               + "      \"1000\" : 2\n"
               + "    },\n"
               + "    \"file-size-in-bytes\" : 10,\n"
               + "    \"record-count\" : 1,\n"
               + "    \"equality-ids\" : [ 1 ],\n"
               + "    \"sort-order-id\" : 0\n"
               + "  } ],\n"
               + "  \"file-scan-tasks\" : [ {\n"
               + "    \"data-file\" : {\n"
               + "      \"spec-id\" : 0,\n"
               + "      \"content\" : \"DATA\",\n"
               + "      \"file-path\" : \"/path/to/data-a.parquet\",\n"
               + "      \"file-format\" : \"PARQUET\",\n"
               + "      \"partition\" : {\n"
               + "        \"1000\" : 0\n"
               + "      },\n"
               + "      \"file-size-in-bytes\" : 10,\n"
               + "      \"record-count\" : 1,\n"
               + "      \"sort-order-id\" : 0\n"
               + "    },\n"
               + "    \"delete-file-references\" : [ 0 ],\n"
               + "    \"residual-filter\" : true\n"
               + "  }, {\n"
               + "    \"data-file\" : {\n"
               + "      \"spec-id\" : 0,\n"
               + "      \"content\" : \"DATA\",\n"
               + "      \"file-path\" : \"/path/to/data-b.parquet\",\n"
               + "      \"file-format\" : \"PARQUET\",\n"
               + "      \"partition\" : {\n"
               + "        \"1000\" : 1\n"
               + "      },\n"
               + "      \"file-size-in-bytes\" : 10,\n"
               + "      \"record-count\" : 1,\n"
               + "      \"split-offsets\" : [ 1 ],\n"
               + "      \"sort-order-id\" : 0\n"
               + "    },\n"
               + "    \"delete-file-references\" : [ 1 ],\n"
               + "    \"residual-filter\" : true\n"
               + "  }, {\n"
               + "    \"data-file\" : {\n"
               + "      \"spec-id\" : 0,\n"
               + "      \"content\" : \"DATA\",\n"
               + "      \"file-path\" : \"/path/to/data-c.parquet\",\n"
               + "      \"file-format\" : \"PARQUET\",\n"
               + "      \"partition\" : {\n"
               + "        \"1000\" : 2\n"
               + "      },\n"
               + "      \"file-size-in-bytes\" : 10,\n"
               + "      \"record-count\" : 1,\n"
               + "      \"split-offsets\" : [ 2, 8 ],\n"
               + "      \"sort-order-id\" : 0\n"
               + "    },\n"
               + "    \"delete-file-references\" : [ 2 ],\n"
               + "    \"residual-filter\" : true\n"
               + "  } ]\n"
               + "}";
       String json = PlanTableScanResponseParser.toJson(response, true);
       assertThat(json).isEqualTo(expectedJson);
   ```



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