Skip to content

Commit

Permalink
Modify behavior and add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Fokko committed Nov 16, 2024
1 parent f2d644e commit db5c2eb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
38 changes: 20 additions & 18 deletions core/src/main/java/org/apache/iceberg/SnapshotParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,25 +132,27 @@ static Snapshot fromJson(JsonNode node) {
"Cannot parse summary from non-object value: %s",
sNode);

ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
Iterator<String> fields = sNode.fieldNames();
while (fields.hasNext()) {
String field = fields.next();
if (field.equals(OPERATION)) {
operation = JsonUtil.getString(OPERATION, sNode);
} else {
builder.put(field, JsonUtil.getString(field, sNode));
if (sNode.size() > 0) {
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
Iterator<String> fields = sNode.fieldNames();
while (fields.hasNext()) {
String field = fields.next();
if (field.equals(OPERATION)) {
operation = JsonUtil.getString(OPERATION, sNode);
} else {
builder.put(field, JsonUtil.getString(field, sNode));
}
}
summary = builder.build();

// When the operation is not found, default to overwrite
// to ensure that we can read the summary without raising an exception
if (operation == null) {
LOG.warn(
"Encountered invalid summary for snapshot {}: the field 'operation' is required but missing, setting 'operation' to overwrite",
snapshotId);
operation = DataOperations.OVERWRITE;
}
}
summary = builder.build();

// When the operation is not found, default to overwrite
// to ensure that we can read the summary without raising an exception
if (operation == null) {
LOG.warn(
"Encountered invalid summary for snapshot {}: the field 'operation' is required but missing, setting 'operation' to overwrite",
snapshotId);
operation = DataOperations.OVERWRITE;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ public void testJsonConversionEmptySummary() {
+ " \"snapshot-id\" : 2,\n"
+ " \"parent-snapshot-id\" : 1,\n"
+ " \"timestamp-ms\" : %s,\n"
+ " \"summary\" : null,\n"
+ " \"manifests\" : [ \"/tmp/manifest1.avro\", \"/tmp/manifest2.avro\" ],\n"
+ " \"schema-id\" : 3\n"
+ "}",
Expand Down

0 comments on commit db5c2eb

Please sign in to comment.