@@ -6393,43 +6393,42 @@ public void testFileModifiedTimeHiddenColumn()
6393
6393
public void testOptimizeWithFileModifiedTimeColumn()
6394
6394
throws Exception
6395
6395
{
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();
6406
6398
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 );
6414
6406
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();
6417
6414
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);
6426
6417
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) + "')");
6431
6426
6432
- assertUpdate("DROP TABLE " + tableName);
6427
+ List<String> updatedFiles = getActiveFiles(tableName);
6428
+ assertThat(updatedFiles)
6429
+ .hasSize(2)
6430
+ .doesNotContainAnyElementsOf(initialFiles);
6431
+ }
6433
6432
}
6434
6433
6435
6434
@Test
0 commit comments