Skip to content

Commit 98041d5

Browse files
chenjian2664ebyhr
authored andcommitted
Test time travel with schema evolution in Iceberg
1 parent b6a44f3 commit 98041d5

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/BaseIcebergConnectorTest.java

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7550,6 +7550,77 @@ public void testReadFromVersionedTableWithExpiredHistory()
75507550
assertQueryFails("SELECT * FROM " + tableName + " FOR TIMESTAMP AS OF " + timestampLiteral(v1EpochMillis, 9), "No version history table .* at or before .*");
75517551
}
75527552

7553+
@Test
7554+
public void testTimeTravelWithFilterOnRenamedColumn()
7555+
{
7556+
testTimeTravelWithFilterOnRenamedColumn(false);
7557+
testTimeTravelWithFilterOnRenamedColumn(true);
7558+
}
7559+
7560+
private void testTimeTravelWithFilterOnRenamedColumn(boolean partitioned)
7561+
{
7562+
String partition = partitioned ? "WITH (partitioning = ARRAY['part'])" : "";
7563+
try (TestTable table = newTrinoTable("time_travel_with_filter_on_rename_", "(x int, y int, part int)" + partition)) {
7564+
assertUpdate("INSERT INTO " + table.getName() + " VALUES (1, 1, 1), (1, 2, 2), (2, 2, 2)", 3);
7565+
assertThat(query("SELECT * FROM " + table.getName()))
7566+
.matches("VALUES (1, 1, 1), (1, 2, 2), (2, 2, 2)");
7567+
long firstSnapshotId = getCurrentSnapshotId(table.getName());
7568+
7569+
assertUpdate("ALTER TABLE " + table.getName() + " RENAME COLUMN x TO renamed_x");
7570+
7571+
// generate a new version
7572+
assertUpdate("INSERT INTO " + table.getName() + " VALUES (1, 2, 3)", 1);
7573+
7574+
assertThat(query("SELECT * FROM " + table.getName() + " FOR VERSION AS OF " + firstSnapshotId + " WHERE x = 1"))
7575+
.matches("VALUES (1, 1, 1), (1, 2, 2)");
7576+
}
7577+
}
7578+
7579+
@Test
7580+
public void testTimeTravelWithFilterOnDroppedColumn()
7581+
{
7582+
testTimeTravelWithFilterOnDroppedColumn(false);
7583+
testTimeTravelWithFilterOnDroppedColumn(true);
7584+
}
7585+
7586+
private void testTimeTravelWithFilterOnDroppedColumn(boolean partitioned)
7587+
{
7588+
String partition = partitioned ? "WITH (partitioning = ARRAY['part'])" : "";
7589+
try (TestTable table = newTrinoTable("time_travel_with_filter_on_drop_", "(x int, y int, part int)" + partition)) {
7590+
assertUpdate("INSERT INTO " + table.getName() + " VALUES (1, 1, 1), (1, 2, 2), (2, 2, 2)", 3);
7591+
assertThat(query("SELECT * FROM " + table.getName()))
7592+
.matches("VALUES (1, 1, 1), (1, 2, 2), (2, 2, 2)");
7593+
long firstSnapshotId = getCurrentSnapshotId(table.getName());
7594+
7595+
assertUpdate("ALTER TABLE " + table.getName() + " DROP COLUMN x");
7596+
7597+
// generate a new version
7598+
assertUpdate("INSERT INTO " + table.getName() + " VALUES (1, 2)", 1);
7599+
7600+
assertThat(query("SELECT * FROM " + table.getName() + " FOR VERSION AS OF " + firstSnapshotId + " WHERE x = 1"))
7601+
.matches("VALUES (1, 1, 1), (1, 2, 2)");
7602+
}
7603+
}
7604+
7605+
@Test
7606+
public void testTimeTravelWithFilterOnRenamedPartitionColumn()
7607+
{
7608+
try (TestTable table = newTrinoTable("time_travel_with_filter_on_drop_", "(x int, part1 int, part2 int) WITH (partitioning = ARRAY['part1', 'part2'])")) {
7609+
assertUpdate("INSERT INTO " + table.getName() + " VALUES (1, 1, 1), (1, 1, 2), (2, 2, 2)", 3);
7610+
assertThat(query("SELECT * FROM " + table.getName()))
7611+
.matches("VALUES (1, 1, 1), (1, 1, 2), (2, 2, 2)");
7612+
long firstSnapshotId = getCurrentSnapshotId(table.getName());
7613+
7614+
assertUpdate("ALTER TABLE " + table.getName() + " RENAME COLUMN part1 TO renamed_part");
7615+
7616+
// generate a new version
7617+
assertUpdate("INSERT INTO " + table.getName() + " VALUES (1, 1, 3)", 1);
7618+
7619+
assertThat(query("SELECT * FROM " + table.getName() + " FOR VERSION AS OF " + firstSnapshotId + " WHERE part1 = 1"))
7620+
.matches("VALUES (1, 1, 1), (1, 1, 2)");
7621+
}
7622+
}
7623+
75537624
@Test
75547625
public void testDeleteRetainsTableHistory()
75557626
{

0 commit comments

Comments
 (0)