@@ -1999,7 +1999,8 @@ public void testOptimizeWithPartitionedTable()
19991999 Set <String > initialFiles = getActiveFiles (tableName );
20002000 assertThat (initialFiles ).hasSize (9 );
20012001
2002- computeActual (withSingleWriterPerTask (getSession ()), "ALTER TABLE " + tableName + " EXECUTE OPTIMIZE" );
2002+ assertUpdate (withSingleWriterPerTask (getSession ()), "ALTER TABLE " + tableName + " EXECUTE OPTIMIZE" ,
2003+ "VALUES ('rewritten_data_files_count', 3), ('removed_delete_files_count', 0), ('added_data_files_count', 1)" );
20032004
20042005 assertThat (query ("SELECT sum(key), listagg(value, ' ') WITHIN GROUP (ORDER BY value) FROM " + tableName ))
20052006 .matches ("VALUES (BIGINT '508', VARCHAR 'ONE Three four one one one tHrEe three two')" );
@@ -2014,6 +2015,58 @@ public void testOptimizeWithPartitionedTable()
20142015 }
20152016 }
20162017
2018+ @ Test
2019+ public void testOptimizeWithDeletionVectors ()
2020+ {
2021+ String tableName = "test_optimize_partitioned_table_" + randomNameSuffix ();
2022+ String tableLocation = getLocationForTable (bucketName , tableName );
2023+ assertQuerySucceeds (withSingleWriterPerTask (getSession ()), "CREATE TABLE " + tableName + " WITH (deletion_vectors_enabled = true, location = '" + tableLocation + "') AS SELECT * FROM tpch.tiny.nation" );
2024+ try {
2025+ assertQuerySucceeds (withSingleWriterPerTask (getSession ()), "INSERT INTO " + tableName + " SELECT * FROM tpch.tiny.nation" );
2026+ assertQuerySucceeds (withSingleWriterPerTask (getSession ()), "INSERT INTO " + tableName + " SELECT * FROM tpch.tiny.nation" );
2027+ assertQuerySucceeds (withSingleWriterPerTask (getSession ()), "INSERT INTO " + tableName + " SELECT * FROM tpch.tiny.nation" );
2028+ assertQuerySucceeds (withSingleWriterPerTask (getSession ()), "INSERT INTO " + tableName + " SELECT * FROM tpch.tiny.nation" );
2029+ assertQuerySucceeds (withSingleWriterPerTask (getSession ()), "INSERT INTO " + tableName + " SELECT * FROM tpch.tiny.nation" );
2030+ Set <String > initFile = getActiveFiles (tableName );
2031+ assertThat (initFile ).hasSize (6 );
2032+ assertQuerySucceeds ("DELETE FROM " + tableName + " WHERE nationkey < 5" );
2033+ assertUpdate (withSingleWriterPerTask (getSession ()),"ALTER TABLE " + tableName + " EXECUTE optimize" ,
2034+ "VALUES ('rewritten_data_files_count', 6), ('removed_delete_files_count', 6), ('added_data_files_count', 1)" );
2035+ assertThat (getActiveFiles (tableName )).hasSize (1 );
2036+ }
2037+ finally {
2038+ assertUpdate ("DROP TABLE " + tableName );
2039+ }
2040+ }
2041+
2042+ @ Test
2043+ public void testOptimizeWithPartitionedTableAndDeleteVector ()
2044+ {
2045+ String tableName = "test_optimize_partitioned_table_" + randomNameSuffix ();
2046+ String tableLocation = getLocationForTable (bucketName , tableName );
2047+ assertQuerySucceeds (withSingleWriterPerTask (getSession ()), "CREATE TABLE " + tableName + " WITH (deletion_vectors_enabled = true, partitioned_by = ARRAY['regionkey'], location = '" + tableLocation + "') AS SELECT nationkey, regionkey FROM tpch.tiny.nation" );
2048+ try {
2049+ assertQuerySucceeds (withSingleWriterPerTask (getSession ()), "INSERT INTO " + tableName + " SELECT nationkey, regionkey FROM tpch.tiny.nation" );
2050+ assertQuerySucceeds (withSingleWriterPerTask (getSession ()), "INSERT INTO " + tableName + " SELECT nationkey, regionkey FROM tpch.tiny.nation" );
2051+ assertQuerySucceeds (withSingleWriterPerTask (getSession ()), "INSERT INTO " + tableName + " SELECT nationkey, regionkey FROM tpch.tiny.nation" );
2052+ assertQuerySucceeds (withSingleWriterPerTask (getSession ()), "INSERT INTO " + tableName + " SELECT nationkey, regionkey FROM tpch.tiny.nation" );
2053+ assertQuerySucceeds (withSingleWriterPerTask (getSession ()), "INSERT INTO " + tableName + " SELECT nationkey, regionkey FROM tpch.tiny.nation" );
2054+
2055+ Set <String > initialFiles = getActiveFiles (tableName );
2056+ assertThat (initialFiles ).hasSize (30 );
2057+ assertQuerySucceeds ("DELETE FROM " + tableName + " WHERE nationkey < 5" );
2058+
2059+ assertUpdate (withSingleWriterPerTask (getSession ()), "ALTER TABLE " + tableName + " EXECUTE OPTIMIZE" ,
2060+ "VALUES ('rewritten_data_files_count', 30), ('removed_delete_files_count', 18), ('added_data_files_count', 5)" );
2061+ Set <String > updatedFiles = getActiveFiles (tableName );
2062+ assertThat (updatedFiles )
2063+ .hasSize (5 );
2064+ }
2065+ finally {
2066+ assertUpdate ("DROP TABLE " + tableName );
2067+ }
2068+ }
2069+
20172070 @ Test
20182071 public void testOptimizeWithEnforcedRepartitioning ()
20192072 {
0 commit comments