Skip to content

Commit bf8d25f

Browse files
authored
Core: Serialize null when there is no current snapshot (apache#11560)
1 parent 97542ab commit bf8d25f

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

core/src/main/java/org/apache/iceberg/TableMetadataParser.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,11 @@ public static void toJson(TableMetadata metadata, JsonGenerator generator) throw
214214
// write properties map
215215
JsonUtil.writeStringMap(PROPERTIES, metadata.properties(), generator);
216216

217-
generator.writeNumberField(
218-
CURRENT_SNAPSHOT_ID,
219-
metadata.currentSnapshot() != null ? metadata.currentSnapshot().snapshotId() : -1);
217+
if (metadata.currentSnapshot() != null) {
218+
generator.writeNumberField(CURRENT_SNAPSHOT_ID, metadata.currentSnapshot().snapshotId());
219+
} else {
220+
generator.writeNullField(CURRENT_SNAPSHOT_ID);
221+
}
220222

221223
toJson(metadata.refs(), generator);
222224

core/src/test/java/org/apache/iceberg/rest/responses/TestLoadTableResponseParser.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public void roundTripSerde() {
107107
+ " \"fields\" : [ ]\n"
108108
+ " } ],\n"
109109
+ " \"properties\" : { },\n"
110-
+ " \"current-snapshot-id\" : -1,\n"
110+
+ " \"current-snapshot-id\" : null,\n"
111111
+ " \"refs\" : { },\n"
112112
+ " \"snapshots\" : [ ],\n"
113113
+ " \"statistics\" : [ ],\n"
@@ -180,7 +180,7 @@ public void roundTripSerdeWithConfig() {
180180
+ " \"fields\" : [ ]\n"
181181
+ " } ],\n"
182182
+ " \"properties\" : { },\n"
183-
+ " \"current-snapshot-id\" : -1,\n"
183+
+ " \"current-snapshot-id\" : null,\n"
184184
+ " \"refs\" : { },\n"
185185
+ " \"snapshots\" : [ ],\n"
186186
+ " \"statistics\" : [ ],\n"
@@ -283,7 +283,7 @@ public void roundTripSerdeWithCredentials() {
283283
+ " \"fields\" : [ ]\n"
284284
+ " } ],\n"
285285
+ " \"properties\" : { },\n"
286-
+ " \"current-snapshot-id\" : -1,\n"
286+
+ " \"current-snapshot-id\" : null,\n"
287287
+ " \"refs\" : { },\n"
288288
+ " \"snapshots\" : [ ],\n"
289289
+ " \"statistics\" : [ ],\n"

0 commit comments

Comments
 (0)