findepi commented on code in PR #4741:
URL: https://github.com/apache/iceberg/pull/4741#discussion_r872154321


##########
core/src/main/java/org/apache/iceberg/SnapshotParser.java:
##########
@@ -147,21 +185,69 @@ static Snapshot fromJson(FileIO io, JsonNode node) {
 
     Integer schemaId = JsonUtil.getIntOrNull(SCHEMA_ID, node);
 
+    List<StatisticsFile> statistics = null;
+    if (node.has(STATISTICS)) {
+      JsonNode statisticsNode = node.get(STATISTICS);
+      Preconditions.checkArgument(statisticsNode != null && 
!statisticsNode.isNull() && statisticsNode.isArray(),
+          "Cannot parse statistics from non-array value: %s", statisticsNode);
+      ImmutableList.Builder<StatisticsFile> builder = 
ImmutableList.builderWithExpectedSize(statisticsNode.size());
+      statisticsNode.elements().forEachRemaining(element -> 
builder.add(statisticsFileFromJson(element)));
+      statistics = builder.build();
+    }
+
     if (node.has(MANIFEST_LIST)) {
       // the manifest list is stored in a manifest list file
       String manifestList = JsonUtil.getString(MANIFEST_LIST, node);
       return new BaseSnapshot(
-          io, sequenceNumber, snapshotId, parentId, timestamp, operation, 
summary, schemaId, manifestList);
-
+          io, sequenceNumber, snapshotId, parentId, timestamp, operation, 
summary, schemaId, manifestList, statistics);
     } else {
       // fall back to an embedded manifest list. pass in the manifest's 
InputFile so length can be
       // loaded lazily, if it is needed
       List<ManifestFile> manifests = 
Lists.transform(JsonUtil.getStringList(MANIFESTS, node),
           location -> new GenericManifestFile(io.newInputFile(location), 0));
-      return new BaseSnapshot(io, snapshotId, parentId, timestamp, operation, 
summary, schemaId, manifests);
+      return new BaseSnapshot(io, snapshotId, parentId, timestamp, operation, 
summary, schemaId, manifests, statistics);
     }
   }
 
+  private static StatisticsFile statisticsFileFromJson(JsonNode json) {
+    Preconditions.checkArgument(json != null && !json.isNull() && 
json.isObject(),
+        "Cannot parse statistics from non-object value: %s", json);
+
+    String location = JsonUtil.getString(LOCATION, json);
+    long fileSizeInBytes = JsonUtil.getLong(FILE_SIZE_IN_BYTES, json);
+    long fileFooterSizeInBytes = JsonUtil.getLong(FILE_FOOTER_SIZE_IN_BYTES, 
json);
+    long sequenceNumber = JsonUtil.getLong(SEQUENCE_NUMBER, json);
+    JsonNode statisticsNode = json.get(STATISTICS);
+    Preconditions.checkArgument(statisticsNode != null && 
!statisticsNode.isNull() && statisticsNode.isObject(),

Review Comment:
   Yes, Iceberg doesn't use annotation-based JSON parsing/generation. a project 
design decision



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