Skip to content

Commit

Permalink
Serialize statistics inside Table Metadata
Browse files Browse the repository at this point in the history
`TableMetadataParser.toJson` now serializes table statistics. This
completes the read path from JSON.
  • Loading branch information
findepi committed Sep 19, 2022
1 parent 2977289 commit fca6101
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
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);
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

0 comments on commit fca6101

Please sign in to comment.