From 59f94804af2f0552c40de9731c7e40fa11659315 Mon Sep 17 00:00:00 2001 From: Fokko Driesprong Date: Wed, 12 Jul 2023 20:04:39 +0200 Subject: [PATCH] Core: Handle null current-snapshot-id We expect this field to be set, but is actually optional in the spec. --- .../java/org/apache/iceberg/TableMetadataParser.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/apache/iceberg/TableMetadataParser.java b/core/src/main/java/org/apache/iceberg/TableMetadataParser.java index 601aff55169d..1093e4e7c989 100644 --- a/core/src/main/java/org/apache/iceberg/TableMetadataParser.java +++ b/core/src/main/java/org/apache/iceberg/TableMetadataParser.java @@ -433,13 +433,19 @@ public static TableMetadata fromJson(String metadataLocation, JsonNode node) { // parse properties map Map 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 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(