Skip to content

Commit

Permalink
Core: Add sort_order_id to SCAN_COLUMNS to address null sort order ID…
Browse files Browse the repository at this point in the history
… after planned data files (apache#8873)
  • Loading branch information
rice668 authored Oct 20, 2023
1 parent 7a60b00 commit 0cc74f1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/src/main/java/org/apache/iceberg/BaseScan.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ abstract class BaseScan<ThisT, T extends ScanTask, G extends ScanTaskGroup<T>>
"record_count",
"partition",
"key_metadata",
"split_offsets");
"split_offsets",
"sort_order_id");

private static final List<String> STATS_COLUMNS =
ImmutableList.of(
Expand Down
30 changes: 30 additions & 0 deletions core/src/test/java/org/apache/iceberg/ScanTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,34 @@ public void testReAddingPartitionField() throws Exception {
}
}
}

@Test
public void testDataFileSorted() throws Exception {
Schema schema =
new Schema(
required(1, "a", Types.IntegerType.get()), required(2, "b", Types.StringType.get()));
File dir = temp.newFolder();
dir.delete();
this.table =
TestTables.create(
dir, "test_data_file_sorted", schema, PartitionSpec.unpartitioned(), formatVersion);
table
.newFastAppend()
.appendFile(
DataFiles.builder(PartitionSpec.unpartitioned())
.withPath("/path/to/data/a.parquet")
.withFileSizeInBytes(10)
.withRecordCount(1)
.withSortOrder(
SortOrder.builderFor(table.schema()).asc("a", NullOrder.NULLS_FIRST).build())
.build())
.commit();

TableScan scan = table.newScan();
try (CloseableIterable<FileScanTask> tasks = scan.planFiles()) {
for (FileScanTask fileScanTask : tasks) {
Assertions.assertThat(fileScanTask.file().sortOrderId()).isEqualTo(1);
}
}
}
}

0 comments on commit 0cc74f1

Please sign in to comment.