Skip to content

Commit 8c62da3

Browse files
chenjian2664ebyhr
authored andcommitted
Use TestTable in Iceberg test testOptimizeWithFileModifiedTimeColumn
1 parent ef6b15f commit 8c62da3

File tree

1 file changed

+31
-32
lines changed

1 file changed

+31
-32
lines changed

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

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6393,43 +6393,42 @@ public void testFileModifiedTimeHiddenColumn()
63936393
public void testOptimizeWithFileModifiedTimeColumn()
63946394
throws Exception
63956395
{
6396-
String tableName = "test_optimize_with_file_modified_time_" + randomNameSuffix();
6397-
assertUpdate("CREATE TABLE " + tableName + " (id integer)");
6398-
6399-
assertUpdate("INSERT INTO " + tableName + " VALUES (1)", 1);
6400-
storageTimePrecision.sleep(1);
6401-
assertUpdate("INSERT INTO " + tableName + " VALUES (2)", 1);
6402-
storageTimePrecision.sleep(1);
6403-
assertUpdate("INSERT INTO " + tableName + " VALUES (3)", 1);
6404-
storageTimePrecision.sleep(1);
6405-
assertUpdate("INSERT INTO " + tableName + " VALUES (4)", 1);
6396+
try (TestTable table = newTrinoTable("test_optimize_with_file_modified_time_", "(id INT)")) {
6397+
String tableName = table.getName();
64066398

6407-
ZonedDateTime firstFileModifiedTime = (ZonedDateTime) computeScalar("SELECT \"$file_modified_time\" FROM " + tableName + " WHERE id = 1");
6408-
ZonedDateTime secondFileModifiedTime = (ZonedDateTime) computeScalar("SELECT \"$file_modified_time\" FROM " + tableName + " WHERE id = 2");
6409-
ZonedDateTime thirdFileModifiedTime = (ZonedDateTime) computeScalar("SELECT \"$file_modified_time\" FROM " + tableName + " WHERE id = 3");
6410-
ZonedDateTime fourthFileModifiedTime = (ZonedDateTime) computeScalar("SELECT \"$file_modified_time\" FROM " + tableName + " WHERE id = 4");
6411-
// Sanity check
6412-
assertThat(List.of(firstFileModifiedTime, secondFileModifiedTime, thirdFileModifiedTime, fourthFileModifiedTime))
6413-
.doesNotHaveDuplicates();
6399+
assertUpdate("INSERT INTO " + tableName + " VALUES (1)", 1);
6400+
storageTimePrecision.sleep(1);
6401+
assertUpdate("INSERT INTO " + tableName + " VALUES (2)", 1);
6402+
storageTimePrecision.sleep(1);
6403+
assertUpdate("INSERT INTO " + tableName + " VALUES (3)", 1);
6404+
storageTimePrecision.sleep(1);
6405+
assertUpdate("INSERT INTO " + tableName + " VALUES (4)", 1);
64146406

6415-
List<String> initialFiles = getActiveFiles(tableName);
6416-
assertThat(initialFiles).hasSize(4);
6407+
ZonedDateTime firstFileModifiedTime = (ZonedDateTime) computeScalar("SELECT \"$file_modified_time\" FROM " + tableName + " WHERE id = 1");
6408+
ZonedDateTime secondFileModifiedTime = (ZonedDateTime) computeScalar("SELECT \"$file_modified_time\" FROM " + tableName + " WHERE id = 2");
6409+
ZonedDateTime thirdFileModifiedTime = (ZonedDateTime) computeScalar("SELECT \"$file_modified_time\" FROM " + tableName + " WHERE id = 3");
6410+
ZonedDateTime fourthFileModifiedTime = (ZonedDateTime) computeScalar("SELECT \"$file_modified_time\" FROM " + tableName + " WHERE id = 4");
6411+
// Sanity check
6412+
assertThat(List.of(firstFileModifiedTime, secondFileModifiedTime, thirdFileModifiedTime, fourthFileModifiedTime))
6413+
.doesNotHaveDuplicates();
64176414

6418-
storageTimePrecision.sleep(1);
6419-
// For optimize we need to set task_min_writer_count to 1, otherwise it will create more than one file.
6420-
assertQuerySucceeds(withSingleWriterPerTask(getSession()), "ALTER TABLE " + tableName + " EXECUTE OPTIMIZE WHERE " +
6421-
"\"$file_modified_time\" = from_iso8601_timestamp('" + firstFileModifiedTime.format(ISO_OFFSET_DATE_TIME) + "') OR " +
6422-
"\"$file_modified_time\" = from_iso8601_timestamp('" + secondFileModifiedTime.format(ISO_OFFSET_DATE_TIME) + "')");
6423-
assertQuerySucceeds(withSingleWriterPerTask(getSession()), "ALTER TABLE " + tableName + " EXECUTE OPTIMIZE WHERE " +
6424-
"\"$file_modified_time\" = from_iso8601_timestamp('" + thirdFileModifiedTime.format(ISO_OFFSET_DATE_TIME) + "') OR " +
6425-
"\"$file_modified_time\" = from_iso8601_timestamp('" + fourthFileModifiedTime.format(ISO_OFFSET_DATE_TIME) + "')");
6415+
List<String> initialFiles = getActiveFiles(tableName);
6416+
assertThat(initialFiles).hasSize(4);
64266417

6427-
List<String> updatedFiles = getActiveFiles(tableName);
6428-
assertThat(updatedFiles)
6429-
.hasSize(2)
6430-
.doesNotContainAnyElementsOf(initialFiles);
6418+
storageTimePrecision.sleep(1);
6419+
// For optimize we need to set task_min_writer_count to 1, otherwise it will create more than one file.
6420+
assertQuerySucceeds(withSingleWriterPerTask(getSession()), "ALTER TABLE " + tableName + " EXECUTE OPTIMIZE WHERE " +
6421+
"\"$file_modified_time\" = from_iso8601_timestamp('" + firstFileModifiedTime.format(ISO_OFFSET_DATE_TIME) + "') OR " +
6422+
"\"$file_modified_time\" = from_iso8601_timestamp('" + secondFileModifiedTime.format(ISO_OFFSET_DATE_TIME) + "')");
6423+
assertQuerySucceeds(withSingleWriterPerTask(getSession()), "ALTER TABLE " + tableName + " EXECUTE OPTIMIZE WHERE " +
6424+
"\"$file_modified_time\" = from_iso8601_timestamp('" + thirdFileModifiedTime.format(ISO_OFFSET_DATE_TIME) + "') OR " +
6425+
"\"$file_modified_time\" = from_iso8601_timestamp('" + fourthFileModifiedTime.format(ISO_OFFSET_DATE_TIME) + "')");
64316426

6432-
assertUpdate("DROP TABLE " + tableName);
6427+
List<String> updatedFiles = getActiveFiles(tableName);
6428+
assertThat(updatedFiles)
6429+
.hasSize(2)
6430+
.doesNotContainAnyElementsOf(initialFiles);
6431+
}
64336432
}
64346433

64356434
@Test

0 commit comments

Comments
 (0)