Skip to content

Commit

Permalink
test: DH-18259: Add empty-table test for Iceberg (#6678)
Browse files Browse the repository at this point in the history
  • Loading branch information
robbcamera authored Mar 3, 2025
1 parent 8233af3 commit 5ae5e35
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
class Pyiceberg2Test {
private static final Namespace NAMESPACE = Namespace.of("trading");
private static final TableIdentifier TRADING_DATA = TableIdentifier.of(NAMESPACE, "data");
private static final TableIdentifier EMPTY_DATA = TableIdentifier.of(NAMESPACE, "data_empty");

// This will need to be updated if the data is regenerated
private static final long SNAPSHOT_1_ID = 2806418501596315192L;
Expand All @@ -55,7 +56,7 @@ void setUp() throws URISyntaxException {
@Test
void catalogInfo() {
assertThat(catalogAdapter.listNamespaces()).containsExactly(NAMESPACE);
assertThat(catalogAdapter.listTables(NAMESPACE)).containsExactly(TRADING_DATA);
assertThat(catalogAdapter.listTables(NAMESPACE)).containsExactly(TRADING_DATA, EMPTY_DATA);

final IcebergTableAdapter tableAdapter = catalogAdapter.loadTable(TRADING_DATA);
final List<Snapshot> snapshots = tableAdapter.listSnapshots();
Expand Down Expand Up @@ -105,4 +106,17 @@ void testData() {
TstUtils.assertTableEquals(expectedData.sort("datetime", "symbol"),
fromIceberg.sort("datetime", "symbol"));
}

@Test
void testEmpty() {
final IcebergTableAdapter tableAdapter = catalogAdapter.loadTable(EMPTY_DATA);
final Table fromIceberg = tableAdapter.table();
assertThat(fromIceberg.size()).isEqualTo(0);
final Table expectedData = TableTools.newTable(TABLE_DEFINITION,
TableTools.col("datetime", new LocalDateTime[0]),
TableTools.stringCol("symbol"),
TableTools.doubleCol("bid"),
TableTools.doubleCol("ask"));
TstUtils.assertTableEquals(expectedData, fromIceberg);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"location":"catalogs/pyiceberg-2/trading.db/data_empty","table-uuid":"c6d40ecb-6228-4ce8-b5a9-b7d27c965fb2","last-updated-ms":1740686637766,"last-column-id":4,"schemas":[{"type":"struct","fields":[{"id":1,"name":"datetime","type":"timestamp","required":false},{"id":2,"name":"symbol","type":"string","required":false},{"id":3,"name":"bid","type":"double","required":false},{"id":4,"name":"ask","type":"double","required":false}],"schema-id":0,"identifier-field-ids":[]}],"current-schema-id":0,"partition-specs":[{"spec-id":0,"fields":[{"source-id":1,"field-id":1000,"transform":"day","name":"datetime_day"},{"source-id":2,"field-id":1001,"transform":"identity","name":"symbol"}]}],"default-spec-id":0,"last-partition-id":1001,"properties":{},"snapshots":[],"snapshot-log":[],"metadata-log":[],"sort-orders":[{"order-id":0,"fields":[]}],"default-sort-order-id":0,"refs":{},"format-version":2,"last-sequence-number":0}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,11 @@

# Append the table to the Iceberg table
tbl.append(table)

######## Empty table testing ########

tbl_empty = catalog.create_table(
identifier="trading.data_empty",
schema=schema,
partition_spec=partition_spec,
)

0 comments on commit 5ae5e35

Please sign in to comment.