nastra commented on code in PR #11354: URL: https://github.com/apache/iceberg/pull/11354#discussion_r1816458955
########## core/src/test/java/org/apache/iceberg/TestSnapshotJson.java: ########## @@ -35,6 +40,58 @@ public class TestSnapshotJson { public TableOperations ops = new LocalTableOperations(temp); + @Test + public void testToJsonWithoutOperation() throws IOException { + int snapshotId = 23; + Long parentId = null; + String manifestList = createManifestListWithManifestFiles(snapshotId, parentId); + + Snapshot expected = + new BaseSnapshot( + 0, snapshotId, parentId, System.currentTimeMillis(), null, null, 1, manifestList); + String json = SnapshotParser.toJson(expected); + + // Assert that summary field is not present in the JSON + assertThat(new ObjectMapper().readTree(json)).anyMatch(node -> !node.has("summary")); + } + + @Test + public void testToJsonWithOperation() throws IOException { + long parentId = 1; + long id = 2; + + String manifestList = createManifestListWithManifestFiles(id, parentId); + + Snapshot expected = + new BaseSnapshot( + 0, + id, + parentId, + System.currentTimeMillis(), + DataOperations.REPLACE, + ImmutableMap.of("files-added", "4", "files-deleted", "100"), + 3, + manifestList); + Map<String, String> expectedSummary = + ImmutableMap.<String, String>builder() + .putAll(expected.summary()) + .put("operation", expected.operation()) // operation should be part of the summary + .build(); + + String json = SnapshotParser.toJson(expected); + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode jsonNode = objectMapper.readTree(json); + + // Assert that the summary node exists + assertThat(jsonNode.get("summary")).isNotNull(); + + // Assert that the "summary" field in the JSON matches the expected summary map Review Comment: ```suggestion ``` -- 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-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org