Skip to content

Commit 94d9c9b

Browse files
committed
Add TestDeltaLakeFileOperations#testDeletionVectors
1 parent 970405d commit 94d9c9b

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/TestDeltaLakeFileOperations.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import java.io.File;
3333
import java.net.URI;
34+
import java.net.URL;
3435
import java.nio.file.Files;
3536
import java.nio.file.Path;
3637
import java.util.Arrays;
@@ -45,6 +46,7 @@
4546
import static io.trino.plugin.deltalake.TestDeltaLakeFileOperations.FileType.CDF_DATA;
4647
import static io.trino.plugin.deltalake.TestDeltaLakeFileOperations.FileType.CHECKPOINT;
4748
import static io.trino.plugin.deltalake.TestDeltaLakeFileOperations.FileType.DATA;
49+
import static io.trino.plugin.deltalake.TestDeltaLakeFileOperations.FileType.DELETION_VECTOR;
4850
import static io.trino.plugin.deltalake.TestDeltaLakeFileOperations.FileType.LAST_CHECKPOINT;
4951
import static io.trino.plugin.deltalake.TestDeltaLakeFileOperations.FileType.STARBURST_EXTENDED_STATS_JSON;
5052
import static io.trino.plugin.deltalake.TestDeltaLakeFileOperations.FileType.TRANSACTION_LOG_JSON;
@@ -53,6 +55,7 @@
5355
import static io.trino.testing.MultisetAssertions.assertMultisetsEqual;
5456
import static io.trino.testing.TestingNames.randomNameSuffix;
5557
import static java.lang.Math.toIntExact;
58+
import static java.lang.String.format;
5659
import static java.util.Objects.requireNonNull;
5760
import static java.util.stream.Collectors.toCollection;
5861

@@ -924,6 +927,40 @@ public void testV2CheckpointParquet()
924927
assertUpdate("DROP TABLE " + tableName);
925928
}
926929

930+
@Test
931+
public void testDeletionVectors()
932+
{
933+
String tableName = "test_deletion_vectors_" + randomNameSuffix();
934+
registerTable(tableName, "databricks122/deletion_vectors");
935+
assertUpdate("CALL system.flush_metadata_cache(schema_name => CURRENT_SCHEMA, table_name => '%s')".formatted(tableName));
936+
assertFileSystemAccesses(
937+
"SELECT * FROM " + tableName,
938+
ImmutableMultiset.<FileOperation>builder()
939+
.add(new FileOperation(TRANSACTION_LOG_JSON, "00000000000000000000.json", "InputFile.newStream"))
940+
.add(new FileOperation(TRANSACTION_LOG_JSON, "00000000000000000001.json", "InputFile.newStream"))
941+
.add(new FileOperation(TRANSACTION_LOG_JSON, "00000000000000000002.json", "InputFile.newStream"))
942+
.add(new FileOperation(TRANSACTION_LOG_JSON, "00000000000000000003.json", "InputFile.newStream"))
943+
.add(new FileOperation(LAST_CHECKPOINT, "_last_checkpoint", "InputFile.newStream"))
944+
.add(new FileOperation(DELETION_VECTOR, "deletion_vector_a52eda8c-0a57-4636-814b-9c165388f7ca.bin", "InputFile.newStream"))
945+
.add(new FileOperation(DATA, "no partition", "InputFile.newInput"))
946+
.build());
947+
assertFileSystemAccesses(
948+
"EXPLAIN ANALYZE SELECT * FROM " + tableName,
949+
ImmutableMultiset.<FileOperation>builder()
950+
.add(new FileOperation(TRANSACTION_LOG_JSON, "00000000000000000000.json", "InputFile.newStream"))
951+
.add(new FileOperation(TRANSACTION_LOG_JSON, "00000000000000000001.json", "InputFile.newStream"))
952+
.add(new FileOperation(TRANSACTION_LOG_JSON, "00000000000000000002.json", "InputFile.newStream"))
953+
.add(new FileOperation(TRANSACTION_LOG_JSON, "00000000000000000003.json", "InputFile.newStream"))
954+
.add(new FileOperation(STARBURST_EXTENDED_STATS_JSON, "extendeded_stats.json", "InputFile.newStream"))
955+
.add(new FileOperation(TRINO_EXTENDED_STATS_JSON, "extended_stats.json", "InputFile.newStream"))
956+
.add(new FileOperation(LAST_CHECKPOINT, "_last_checkpoint", "InputFile.newStream"))
957+
.add(new FileOperation(DELETION_VECTOR, "deletion_vector_a52eda8c-0a57-4636-814b-9c165388f7ca.bin", "InputFile.newStream"))
958+
.add(new FileOperation(DATA, "no partition", "InputFile.newInput"))
959+
.build());
960+
961+
assertUpdate("DROP TABLE " + tableName);
962+
}
963+
927964
private int countCdfFilesForKey(String partitionValue)
928965
{
929966
String path = (String) computeScalar("SELECT \"$path\" FROM table_changes_file_system_access WHERE key = '" + partitionValue + "'");
@@ -979,6 +1016,9 @@ public static FileOperation create(String path, String operationType)
9791016
if (path.matches(".*/_delta_log/_starburst_meta/extendeded_stats.json")) {
9801017
return new FileOperation(STARBURST_EXTENDED_STATS_JSON, fileName, operationType);
9811018
}
1019+
if (path.contains("/deletion_vector_")) {
1020+
return new FileOperation(DELETION_VECTOR, fileName, operationType);
1021+
}
9821022
Pattern dataFilePattern = Pattern.compile(".*?/(?<partition>key=[^/]*/)?[^/]+");
9831023
if (path.matches(".*/_change_data/.*")) {
9841024
Matcher matcher = dataFilePattern.matcher(path);
@@ -1012,6 +1052,18 @@ enum FileType
10121052
STARBURST_EXTENDED_STATS_JSON,
10131053
DATA,
10141054
CDF_DATA,
1055+
DELETION_VECTOR,
10151056
/**/;
10161057
}
1058+
1059+
private void registerTable(String name, String resourcePath)
1060+
{
1061+
String dataPath = getResourceLocation(resourcePath).toExternalForm();
1062+
getQueryRunner().execute(format("CALL system.register_table(CURRENT_SCHEMA, '%s', '%s')", name, dataPath));
1063+
}
1064+
1065+
private URL getResourceLocation(String resourcePath)
1066+
{
1067+
return getClass().getClassLoader().getResource(resourcePath);
1068+
}
10171069
}

0 commit comments

Comments
 (0)