Skip to content

Commit

Permalink
Core: Handle null current-snapshot-id
Browse files Browse the repository at this point in the history
We expect this field to be set, but is actually optional in the spec.
  • Loading branch information
Fokko committed Jul 12, 2023
1 parent 6cafd70 commit 59f9480
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions core/src/main/java/org/apache/iceberg/TableMetadataParser.java
Expand Up @@ -433,13 +433,19 @@ public static TableMetadata fromJson(String metadataLocation, JsonNode node) {

// parse properties map
Map<String, String> properties = JsonUtil.getStringMap(PROPERTIES, node);
long currentSnapshotId = JsonUtil.getLong(CURRENT_SNAPSHOT_ID, node);

Long currentSnapshotId = JsonUtil.getLongOrNull(CURRENT_SNAPSHOT_ID, node);
if (currentSnapshotId == null) {
// This field is optional, but internally we set this to -1 when not set
currentSnapshotId = -1L;
}

long lastUpdatedMillis = JsonUtil.getLong(LAST_UPDATED_MILLIS, node);

Map<String, SnapshotRef> refs;
if (node.has(REFS)) {
refs = refsFromJson(node.get(REFS));
} else if (currentSnapshotId != -1) {
} else if (currentSnapshotId != -1L) {
// initialize the main branch if there are no refs
refs =
ImmutableMap.of(
Expand Down

0 comments on commit 59f9480

Please sign in to comment.