|
19 | 19 | import io.trino.Session; |
20 | 20 | import io.trino.connector.MockConnectorFactory; |
21 | 21 | import io.trino.connector.MockConnectorPlugin; |
22 | | -import io.trino.filesystem.FileEntry; |
23 | | -import io.trino.filesystem.FileIterator; |
24 | 22 | import io.trino.filesystem.Location; |
25 | 23 | import io.trino.filesystem.TrinoFileSystem; |
26 | 24 | import io.trino.plugin.iceberg.fileio.ForwardingFileIo; |
|
53 | 51 | import org.junit.jupiter.api.BeforeAll; |
54 | 52 | import org.junit.jupiter.api.Test; |
55 | 53 |
|
56 | | -import java.io.IOException; |
57 | 54 | import java.time.ZonedDateTime; |
58 | 55 | import java.util.List; |
59 | 56 | import java.util.Map; |
@@ -1111,99 +1108,6 @@ public void testRefreshWithCompaction() |
1111 | 1108 | assertUpdate("DROP TABLE %s".formatted(sourceTableName)); |
1112 | 1109 | } |
1113 | 1110 |
|
1114 | | - @Test |
1115 | | - void testPreviousSnapshotCleanupDuringRefresh() |
1116 | | - throws IOException |
1117 | | - { |
1118 | | - String sourceTableName = "source_table" + randomNameSuffix(); |
1119 | | - String materializedViewName = "test_materialized_view" + randomNameSuffix(); |
1120 | | - |
1121 | | - // create source table and an MV |
1122 | | - assertUpdate("CREATE TABLE " + sourceTableName + " (a int, b varchar)"); |
1123 | | - assertUpdate("INSERT INTO " + sourceTableName + " VALUES (1, 'abc'), (2, 'def')", 2); |
1124 | | - assertUpdate("CREATE MATERIALIZED VIEW " + materializedViewName + " AS SELECT a, b FROM " + sourceTableName + " WHERE a < 3 OR a > 5"); |
1125 | | - // Until first MV refresh no data files are created hence perform first MV refresh to get data files created for the MV |
1126 | | - assertUpdate("REFRESH MATERIALIZED VIEW " + materializedViewName, 2); |
1127 | | - |
1128 | | - TrinoFileSystem fileSystemFactory = getFileSystemFactory(getQueryRunner()).create(ConnectorIdentity.ofUser("test")); |
1129 | | - |
1130 | | - // Identify different types of files containing in an MV |
1131 | | - Location metadataLocation = Location.of(getStorageMetadataLocation(materializedViewName)); |
1132 | | - FileIterator tableFiles = fileSystemFactory.listFiles(Location.of(metadataLocation.toString().substring(0, metadataLocation.toString().indexOf("/metadata")))); |
1133 | | - ImmutableSet.Builder<FileEntry> previousDataFiles = ImmutableSet.builder(); |
1134 | | - ImmutableSet.Builder<FileEntry> previousMetadataFiles = ImmutableSet.builder(); |
1135 | | - ImmutableSet.Builder<FileEntry> previousManifestsFiles = ImmutableSet.builder(); |
1136 | | - while (tableFiles.hasNext()) { |
1137 | | - FileEntry file = tableFiles.next(); |
1138 | | - String location = file.location().toString(); |
1139 | | - if (location.contains("/data/")) { |
1140 | | - previousDataFiles.add(file); |
1141 | | - } |
1142 | | - else if (location.contains("/metadata/") && location.endsWith(".json")) { |
1143 | | - previousMetadataFiles.add(file); |
1144 | | - } |
1145 | | - else if (location.contains("/metadata") && !location.contains("snap-") && location.endsWith(".avro")) { |
1146 | | - previousManifestsFiles.add(file); |
1147 | | - } |
1148 | | - } |
1149 | | - |
1150 | | - // Execute MV refresh after deleting existing records and inserting new records in source table |
1151 | | - assertUpdate("DELETE FROM " + sourceTableName + " WHERE a = 1 OR a = 2", 2); |
1152 | | - assertQueryReturnsEmptyResult("SELECT * FROM " + sourceTableName); |
1153 | | - assertUpdate("INSERT INTO " + sourceTableName + " VALUES (7, 'pqr'), (8, 'xyz')", 2); |
1154 | | - assertUpdate("REFRESH MATERIALIZED VIEW " + materializedViewName, 2); |
1155 | | - assertThat(query("SELECT * FROM " + materializedViewName)) |
1156 | | - .matches("VALUES (7, VARCHAR 'pqr'), (8, VARCHAR 'xyz')"); |
1157 | | - |
1158 | | - // Identify different types of files containing in an MV after MV refresh |
1159 | | - Location latestMetadataLocation = Location.of(getStorageMetadataLocation(materializedViewName)); |
1160 | | - FileIterator latestTableFiles = fileSystemFactory.listFiles(Location.of(latestMetadataLocation.toString().substring(0, latestMetadataLocation.toString().indexOf("/metadata")))); |
1161 | | - ImmutableSet.Builder<FileEntry> currentDataFiles = ImmutableSet.builder(); |
1162 | | - ImmutableSet.Builder<FileEntry> currentMetadataFiles = ImmutableSet.builder(); |
1163 | | - ImmutableSet.Builder<FileEntry> currentManifestsFiles = ImmutableSet.builder(); |
1164 | | - while (latestTableFiles.hasNext()) { |
1165 | | - FileEntry file = latestTableFiles.next(); |
1166 | | - String location = file.location().toString(); |
1167 | | - if (location.contains("/data/")) { |
1168 | | - currentDataFiles.add(file); |
1169 | | - } |
1170 | | - else if (location.contains("/metadata/") && location.endsWith(".json")) { |
1171 | | - currentMetadataFiles.add(file); |
1172 | | - } |
1173 | | - else if (location.contains("/metadata") && !location.contains("snap-") && location.endsWith(".avro")) { |
1174 | | - currentManifestsFiles.add(file); |
1175 | | - } |
1176 | | - } |
1177 | | - |
1178 | | - // data files from previous snapshot are absent in latest MV snapshot as those are cleaned up after MV refresh |
1179 | | - assertThat(previousDataFiles.build()) |
1180 | | - .isNotEmpty() |
1181 | | - .satisfies(dataFilesBeforeMvRefresh -> |
1182 | | - assertThat(currentDataFiles.build()) |
1183 | | - .isNotEmpty() |
1184 | | - .doesNotContainAnyElementsOf(dataFilesBeforeMvRefresh)); |
1185 | | - |
1186 | | - // metadata files from previous snapshot are still present in latest MV snapshot as those are not cleaned up after MV refresh |
1187 | | - assertThat(previousMetadataFiles.build()) |
1188 | | - .isNotEmpty() |
1189 | | - .satisfies(metadataFilesBeforeMvRefresh -> |
1190 | | - assertThat(currentMetadataFiles.build()) |
1191 | | - .isNotEmpty() |
1192 | | - .containsAll(metadataFilesBeforeMvRefresh)); |
1193 | | - |
1194 | | - // manifests files from previous snapshot are absent in latest MV snapshot as those are cleaned up after MV refresh |
1195 | | - assertThat(previousManifestsFiles.build()) |
1196 | | - .isNotEmpty() |
1197 | | - .satisfies(manifestsBeforeMvRefresh -> |
1198 | | - assertThat(currentManifestsFiles.build()) |
1199 | | - .isNotEmpty() |
1200 | | - .doesNotContainAnyElementsOf(manifestsBeforeMvRefresh)); |
1201 | | - |
1202 | | - // cleanup |
1203 | | - assertUpdate("DROP MATERIALIZED VIEW " + materializedViewName); |
1204 | | - assertUpdate("DROP TABLE " + sourceTableName); |
1205 | | - } |
1206 | | - |
1207 | 1111 | protected String getColumnComment(String tableName, String columnName) |
1208 | 1112 | { |
1209 | 1113 | return (String) computeScalar("SELECT comment FROM information_schema.columns WHERE table_schema = '" + getSession().getSchema().orElseThrow() + "' AND table_name = '" + tableName + "' AND column_name = '" + columnName + "'"); |
|
0 commit comments