Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ public static String toJson(TableMetadata metadata) {
}
}

@SuppressWarnings("checkstyle:CyclomaticComplexity")
public static void toJson(TableMetadata metadata, JsonGenerator generator) throws IOException {
generator.writeStartObject();

Expand Down Expand Up @@ -225,6 +226,12 @@ public static void toJson(TableMetadata metadata, JsonGenerator generator) throw
}
generator.writeEndArray();

generator.writeArrayFieldStart(STATISTICS);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add deserialization? Generally when we update a parser we want to update both.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deserialization already exists.

statisticsFiles = statisticsFilesFromJson(node.get(STATISTICS));

Was added in #5450

The fact serialization was not covered was an omission.

for (StatisticsFile statisticsFile : metadata.statisticsFiles()) {
StatisticsFileParser.toJson(statisticsFile, generator);
}
generator.writeEndArray();

generator.writeArrayFieldStart(SNAPSHOT_LOG);
for (HistoryEntry logEntry : metadata.snapshotLog()) {
generator.writeStartObject();
Expand Down
15 changes: 14 additions & 1 deletion core/src/test/java/org/apache/iceberg/TestTableMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ public void testJsonConversion() throws Exception {
"previous", SnapshotRef.tagBuilder(previousSnapshotId).build(),
"test", SnapshotRef.branchBuilder(previousSnapshotId).build());

List<StatisticsFile> statisticsFiles =
ImmutableList.of(
new GenericStatisticsFile(
11L,
"/some/stats/file.puffin",
100,
42,
ImmutableList.of(
new GenericBlobMetadata(
"some-stats", 11L, 2, ImmutableList.of(4), ImmutableMap.of()))));

TableMetadata expected =
new TableMetadata(
null,
Expand All @@ -155,7 +166,7 @@ public void testJsonConversion() throws Exception {
snapshotLog,
ImmutableList.of(),
refs,
ImmutableList.of(),
statisticsFiles,
ImmutableList.of());

String asJson = TableMetadataParser.toJson(expected);
Expand Down Expand Up @@ -220,6 +231,8 @@ public void testJsonConversion() throws Exception {
Assert.assertNull(
"Previous snapshot's schema ID should be null",
metadata.snapshot(previousSnapshotId).schemaId());
Assert.assertEquals(
"Statistics files should match", statisticsFiles, metadata.statisticsFiles());
Assert.assertEquals("Refs map should match", refs, metadata.refs());
}

Expand Down