Skip to content

Commit f198b32

Browse files
committed
Test reading liquid clustering tables in Delta Lake
1 parent 86c41ea commit f198b32

File tree

9 files changed

+47
-0
lines changed

9 files changed

+47
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public class TestDeltaLakeBasic
9797
new ResourceTable("stats_with_minmax_nulls", "deltalake/stats_with_minmax_nulls"),
9898
new ResourceTable("no_column_stats", "databricks73/no_column_stats"),
9999
new ResourceTable("deletion_vectors", "databricks122/deletion_vectors"),
100+
new ResourceTable("liquid_clustering", "deltalake/liquid_clustering"),
100101
new ResourceTable("timestamp_ntz", "databricks131/timestamp_ntz"),
101102
new ResourceTable("timestamp_ntz_partition", "databricks131/timestamp_ntz_partition"));
102103

@@ -940,6 +941,24 @@ public void testDeletionVectors()
940941
assertQuery("SELECT * FROM deletion_vectors", "VALUES (1, 11)");
941942
}
942943

944+
/**
945+
* @see deltalake.liquid_clustering
946+
*/
947+
@Test
948+
public void testLiquidClustering()
949+
{
950+
assertQuery("SELECT * FROM liquid_clustering", "VALUES ('test 1', 2024, 1), ('test 2', 2024, 2)");
951+
assertQuery("SELECT data FROM liquid_clustering WHERE year = 2024 AND month = 1", "VALUES 'test 1'");
952+
assertQuery("SELECT data FROM liquid_clustering WHERE year = 2024 AND month = 2", "VALUES 'test 2'");
953+
954+
assertQueryReturnsEmptyResult("SELECT * FROM liquid_clustering FOR VERSION AS OF 0");
955+
assertQuery("SELECT * FROM liquid_clustering FOR VERSION AS OF 1", "VALUES ('test 1', 2024, 1)");
956+
assertQuery("SELECT * FROM liquid_clustering FOR VERSION AS OF 2", "VALUES ('test 1', 2024, 1), ('test 2', 2024, 2)");
957+
assertQuery("SELECT * FROM liquid_clustering FOR VERSION AS OF 3", "VALUES ('test 1', 2024, 1), ('test 2', 2024, 2)");
958+
959+
assertQueryFails("INSERT INTO liquid_clustering VALUES ('test 3', 2024, 3)", "Unsupported writer features: .*");
960+
}
961+
943962
@Test
944963
public void testCorruptedManagedTableLocation()
945964
throws Exception
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Data generated using OSS Delta Lake 3.2.0.
2+
At least two columns are required for Hilbert clustering.
3+
4+
```sql
5+
CREATE TABLE test_liquid
6+
(data string, year int, month int)
7+
USING delta
8+
CLUSTER BY (year, month)
9+
LOCATION ?;
10+
11+
INSERT INTO test_liquid VALUES ('test 1', 2024, 1);
12+
13+
INSERT INTO test_liquid VALUES ('test 2', 2024, 2);
14+
15+
OPTIMIZE test_liquid;
16+
```
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{"commitInfo":{"timestamp":1717803968268,"operation":"CREATE TABLE","operationParameters":{"partitionBy":"[]","clusterBy":"[\"year\",\"month\"]","description":null,"isManaged":"false","properties":"{}"},"isolationLevel":"Serializable","isBlindAppend":true,"operationMetrics":{},"engineInfo":"Apache-Spark/3.5.0 Delta-Lake/3.2.0","txnId":"f324a7bf-37b9-4561-9345-6ba50a89eee4"}}
2+
{"metaData":{"id":"89e6e7c2-d77a-4deb-af28-9209972fb56d","format":{"provider":"parquet","options":{}},"schemaString":"{\"type\":\"struct\",\"fields\":[{\"name\":\"data\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}},{\"name\":\"year\",\"type\":\"integer\",\"nullable\":true,\"metadata\":{}},{\"name\":\"month\",\"type\":\"integer\",\"nullable\":true,\"metadata\":{}}]}","partitionColumns":[],"configuration":{},"createdTime":1717803968252}}
3+
{"protocol":{"minReaderVersion":1,"minWriterVersion":7,"writerFeatures":["domainMetadata","clustering"]}}
4+
{"domainMetadata":{"domain":"delta.clustering","configuration":"{\"clusteringColumns\":[[\"year\"],[\"month\"]],\"domainName\":\"delta.clustering\"}","removed":false}}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{"commitInfo":{"timestamp":1717803973164,"operation":"WRITE","operationParameters":{"mode":"Append","partitionBy":"[]"},"readVersion":0,"isolationLevel":"Serializable","isBlindAppend":true,"operationMetrics":{"numFiles":"1","numOutputRows":"1","numOutputBytes":"934"},"engineInfo":"Apache-Spark/3.5.0 Delta-Lake/3.2.0","txnId":"38cd1832-75ea-4acd-920b-d9d1ce89c913"}}
2+
{"add":{"path":"part-00000-be853604-1a95-499c-8bd3-0817e117e934-c000.snappy.parquet","partitionValues":{},"size":934,"modificationTime":1717803973000,"dataChange":true,"stats":"{\"numRecords\":1,\"minValues\":{\"data\":\"test 1\",\"year\":2024,\"month\":1},\"maxValues\":{\"data\":\"test 1\",\"year\":2024,\"month\":1},\"nullCount\":{\"data\":0,\"year\":0,\"month\":0}}"}}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{"commitInfo":{"timestamp":1717803973452,"operation":"WRITE","operationParameters":{"mode":"Append","partitionBy":"[]"},"readVersion":1,"isolationLevel":"Serializable","isBlindAppend":true,"operationMetrics":{"numFiles":"1","numOutputRows":"1","numOutputBytes":"934"},"engineInfo":"Apache-Spark/3.5.0 Delta-Lake/3.2.0","txnId":"69693df0-524f-44e8-9048-1ac8ffa3b07d"}}
2+
{"add":{"path":"part-00000-dbbc308b-0878-4d8e-a814-d0b55ec894d4-c000.snappy.parquet","partitionValues":{},"size":934,"modificationTime":1717803973000,"dataChange":true,"stats":"{\"numRecords\":1,\"minValues\":{\"data\":\"test 2\",\"year\":2024,\"month\":2},\"maxValues\":{\"data\":\"test 2\",\"year\":2024,\"month\":2},\"nullCount\":{\"data\":0,\"year\":0,\"month\":0}}"}}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{"commitInfo":{"timestamp":1717803979381,"operation":"OPTIMIZE","operationParameters":{"predicate":"[]","zOrderBy":"[]","clusterBy":"[\"year\",\"month\"]","auto":false},"readVersion":2,"isolationLevel":"SnapshotIsolation","isBlindAppend":false,"operationMetrics":{"numRemovedFiles":"2","numRemovedBytes":"1868","p25FileSize":"966","numDeletionVectorsRemoved":"0","minFileSize":"966","numAddedFiles":"1","maxFileSize":"966","p75FileSize":"966","p50FileSize":"966","numAddedBytes":"966"},"engineInfo":"Apache-Spark/3.5.0 Delta-Lake/3.2.0","txnId":"2c6d1d35-dd91-40df-b507-0683a3fe650f"}}
2+
{"add":{"path":"part-00000-ba4afeda-e581-4193-879d-12f07682e4d1-c000.snappy.parquet","partitionValues":{},"size":966,"modificationTime":1717803979000,"dataChange":false,"stats":"{\"numRecords\":2,\"minValues\":{\"data\":\"test 1\",\"year\":2024,\"month\":1},\"maxValues\":{\"data\":\"test 2\",\"year\":2024,\"month\":2},\"nullCount\":{\"data\":0,\"year\":0,\"month\":0}}","tags":{"ZCUBE_ID":"8d97f1d1-6b6d-44da-9cba-f961c89869bd","ZCUBE_ZORDER_BY":"[\"year\",\"month\"]"},"clusteringProvider":"liquid"}}
3+
{"remove":{"path":"part-00000-dbbc308b-0878-4d8e-a814-d0b55ec894d4-c000.snappy.parquet","deletionTimestamp":1717803978631,"dataChange":false,"extendedFileMetadata":true,"partitionValues":{},"size":934,"stats":"{\"numRecords\":1}"}}
4+
{"remove":{"path":"part-00000-be853604-1a95-499c-8bd3-0817e117e934-c000.snappy.parquet","deletionTimestamp":1717803978631,"dataChange":false,"extendedFileMetadata":true,"partitionValues":{},"size":934,"stats":"{\"numRecords\":1}"}}

0 commit comments

Comments
 (0)