Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion core/src/main/java/org/apache/iceberg/SerializableTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class SerializableTable implements Table, HasTableOperations, Serializabl
private final int defaultSpecId;
private final Map<Integer, String> specAsJsonMap;
private final String sortOrderAsJson;
private final int defaultSortOrderId;
private final Map<Integer, String> sortOrderAsJsonMap;
private final FileIO io;
private final EncryptionManager encryption;
Expand All @@ -83,6 +84,7 @@ protected SerializableTable(Table table) {
Map<Integer, PartitionSpec> specs = table.specs();
specs.forEach((specId, spec) -> specAsJsonMap.put(specId, PartitionSpecParser.toJson(spec)));
this.sortOrderAsJson = SortOrderParser.toJson(table.sortOrder());
this.defaultSortOrderId = table.sortOrder().orderId();
this.sortOrderAsJsonMap = Maps.newHashMap();
table
.sortOrders()
Expand Down Expand Up @@ -253,7 +255,8 @@ public Map<Integer, SortOrder> sortOrders() {
ImmutableMap.Builder<Integer, SortOrder> sortOrders =
ImmutableMap.builderWithExpectedSize(sortOrderAsJsonMap.size());
sortOrderAsJsonMap.forEach(
(id, json) -> sortOrders.put(id, SortOrderParser.fromJson(schema(), json)));
(id, json) ->
sortOrders.put(id, SortOrderParser.fromJson(schema(), json, defaultSortOrderId)));
this.lazySortOrders = sortOrders.build();
} else if (lazySortOrders == null) {
this.lazySortOrders = lazyTable.sortOrders();
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/org/apache/iceberg/SortOrderParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ public static SortOrder fromJson(Schema schema, String json) {
return fromJson(json).bind(schema);
}

public static SortOrder fromJson(Schema schema, String json, int defaultSortOrderId) {
return JsonUtil.parse(json, node -> fromJson(schema, node, defaultSortOrderId));
}

public static SortOrder fromJson(Schema schema, JsonNode json, int defaultSortOrderId) {
UnboundSortOrder unboundSortOrder = fromJson(json);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ public void testSerializableTable() throws IOException, ClassNotFoundException {
.isEqualTo(TableUtil.metadataFileLocation(table));
}

@Test
public void testSerializableTableSortOrdersWithDroppedColumn()
throws IOException, ClassNotFoundException {
table.updateSchema().addColumn("ts", Types.LongType.get()).commit();
table.replaceSortOrder().asc("id").asc("ts").commit();

// historical sort order 1 still references "ts" after the column is dropped
table.replaceSortOrder().asc("id").commit();
table.updateSchema().deleteColumn("ts").commit();

TestHelpers.assertSerializedAndLoadedMetadata(table, TestHelpers.roundTripSerialize(table));
Table serializableTable = SerializableTable.copyOf(table);
TestHelpers.assertSerializedAndLoadedMetadata(
serializableTable, TestHelpers.KryoHelpers.roundTripSerialize(serializableTable));
}

@Test
public void testSerializableTableWithSnapshot() throws IOException, ClassNotFoundException {
table.newAppend().appendFile(FILE_A).commit();
Expand Down