Skip to content

Commit ed9ac00

Browse files
committed
run delta test successfully
1 parent 95b532d commit ed9ac00

10 files changed

Lines changed: 142 additions & 5008 deletions

tests/spark/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
This application produces data used by the delta kuttl test.
1+
This application was used to produce the `delta-table` for the delta kuttl test.
22

33
It cannot be placed in the delta test folder because beku tries to recurse into it and fails.
44

5+
To run it, you need a S3 (minio) available. Update the variables below as needed:
6+
57
S3_ENDPOINT=https://localhost:9000 \
68
S3_ACCESS_KEY=minioAccessKey \
79
S3_SECRET_KEY=minioSecretKey \

tests/templates/kuttl/delta/04-prepare-bucket.yaml.j2

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ commands:
55
# give minio enough time to start
66
- command: sleep 5
77
- script: |
8-
POD=$(kubectl -n $NAMESPACE get pod -l app.kubernetes.io/instance=minio -o name | head -n 1 | sed -e 's#pod/##')
9-
kubectl cp -n $NAMESPACE yellow_tripdata_2021-07.csv $POD:/tmp
10-
kubectl -n $NAMESPACE exec $POD -- mc cp /tmp/yellow_tripdata_2021-07.csv local/trino/taxi-data/
8+
POD=$(kubectl -n $NAMESPACE get pod -l app.kubernetes.io/instance=minio -o name | head -n1 | sed 's#pod/##')
9+
kubectl -n $NAMESPACE cp delta-table "$POD:/tmp/delta-table"
10+
kubectl -n $NAMESPACE exec "$POD" -- mc rm -r --force local/trino/delta-table || true
11+
kubectl -n $NAMESPACE exec "$POD" -- mc mirror --overwrite /tmp/delta-table local/trino/delta-table

tests/templates/kuttl/delta/08-install-hive.yaml.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
name: hive
66
spec:
77
image:
8-
productVersion: "{{ test_scenario['values']['hive'] }}"
8+
productVersion: "{{ test_scenario['values']['hive-latest'] }}"
99
pullPolicy: IfNotPresent
1010
clusterConfig:
1111
database:
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
apiVersion: kuttl.dev/v1beta1
3+
kind: TestAssert
4+
timeout: 300
5+
---
6+
apiVersion: batch/v1
7+
kind: Job
8+
metadata:
9+
name: delta-check
10+
status:
11+
succeeded: 1
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
---
2+
apiVersion: v1
3+
kind: ConfigMap
4+
metadata:
5+
name: delta-check-script
6+
data:
7+
check-delta.py: |
8+
#!/usr/bin/env python
9+
#
10+
# This script is used to run a series of SQL statements against the Trino cluster to verify that the Delta Lake connector is working correctly.
11+
#
12+
# It assumes that data is already present in the S3 location and that the Trino cluster is configured to access it. The script will:
13+
# 1. Register the Delta table using the system.register_table procedure.
14+
# 2. Run a SELECT query to verify that the expected data is present.
15+
# 3. Run a DELETE query to remove some data.
16+
# 4. Run another SELECT query to verify that the data was deleted.
17+
#
18+
import argparse
19+
import sys
20+
21+
import trino
22+
23+
if not sys.warnoptions:
24+
import warnings
25+
26+
warnings.simplefilter("ignore")
27+
28+
def get_connection(username, password, coordinator):
29+
conn = trino.dbapi.connect(
30+
host=coordinator,
31+
port=8443,
32+
user=username,
33+
http_scheme="https",
34+
auth=trino.auth.BasicAuthentication(username, password),
35+
session_properties={"query_max_execution_time": "60s"},
36+
)
37+
conn._http_session.verify = False
38+
return conn
39+
40+
41+
def run_query(connection, query):
42+
print(f"[DEBUG] Executing query {query}")
43+
cursor = connection.cursor()
44+
cursor.execute(query)
45+
return cursor.fetchall()
46+
47+
48+
if __name__ == "__main__":
49+
all_args = argparse.ArgumentParser()
50+
all_args.add_argument(
51+
"-c",
52+
"--coordinator",
53+
required=True,
54+
help="Trino Coordinator Host to connect to",
55+
)
56+
args = vars(all_args.parse_args())
57+
58+
coordinator = args["coordinator"]
59+
60+
print("[INFO] Running Delta SQL commands")
61+
connection = get_connection("admin", "admin", coordinator)
62+
63+
statement = "DROP TABLE IF EXISTS delta.default.delta_table"
64+
run_query(connection, statement)
65+
66+
# Must use the register_table procedure to create the table because data is already present in the S3 location
67+
# and Trino's CREATE TABLE AS doesn't support that.
68+
statement = "CALL delta.system.register_table(schema_name => 'default', table_name => 'delta_table', table_location => 's3a://trino/delta-table')"
69+
run_query(connection, statement)
70+
71+
statement = "select count(*) from delta.default.delta_table where text='text5'"
72+
result = run_query(connection, statement)
73+
assert result[0][0] == 5000, (
74+
f"Expected 5000 rows, got {result}\nQuery: {statement}"
75+
)
76+
77+
statement = "delete from delta.default.delta_table where text = 'text5'"
78+
run_query(connection, statement)
79+
80+
statement = "select count(*) from delta.default.delta_table where text='text5'"
81+
result = run_query(connection, statement)
82+
assert result[0][0] == 0, (
83+
f"Expected 0 rows, got {result}\nQuery: {statement}"
84+
)
85+
86+
print("[SUCCESS] Delta checks succeeded.")
87+
---
88+
apiVersion: batch/v1
89+
kind: Job
90+
metadata:
91+
name: delta-check
92+
spec:
93+
backoffLimit: 0
94+
template:
95+
spec:
96+
serviceAccountName: integration-tests-sa
97+
restartPolicy: Never
98+
containers:
99+
- name: trino-test-helper
100+
image: oci.stackable.tech/sdp/testing-tools:0.2.0-stackable0.0.0-dev
101+
command: ["python", "/tmp/check-delta.py", "-c", "trino-coordinator"]
102+
resources:
103+
requests:
104+
cpu: "250m"
105+
memory: "64Mi"
106+
limits:
107+
cpu: "500m"
108+
memory: "64Mi"
109+
volumeMounts:
110+
- name: delta-check-script
111+
mountPath: /tmp/check-delta.py
112+
subPath: check-delta.py
113+
volumes:
114+
- name: delta-check-script
115+
configMap:
116+
name: delta-check-script
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"txnId":"5bec127e-ea8a-4eef-ba09-3e549a66fc0c","tableSizeBytes":702,"numFiles":1,"numMetadata":1,"numProtocol":1,"setTransactions":[],"domainMetadata":[],"metadata":{"id":"0e582e3d-6324-4194-bab0-4b3039c761bc","format":{"provider":"parquet","options":{}},"schemaString":"{\"type\":\"struct\",\"fields\":[{\"name\":\"year\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}},{\"name\":\"id_mandant\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}},{\"name\":\"text\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}}]}","partitionColumns":["year","id_mandant"],"configuration":{},"createdTime":1774618197458},"protocol":{"minReaderVersion":1,"minWriterVersion":2},"allFiles":[{"path":"year=2026/id_mandant=0157/part-00000-45386c31-ae84-4fab-9d03-a074a8bae1a2.c000.snappy.parquet","partitionValues":{"year":"2026","id_mandant":"0157"},"size":702,"modificationTime":1774618199000,"dataChange":false,"stats":"{\"numRecords\":50000,\"minValues\":{\"text\":\"text0\"},\"maxValues\":{\"text\":\"text9\"},\"nullCount\":{\"text\":0}}"}]}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{"commitInfo":{"timestamp":1774618199441,"operation":"WRITE","operationParameters":{"mode":"Append","partitionBy":"[\"year\",\"id_mandant\"]"},"isolationLevel":"Serializable","isBlindAppend":true,"operationMetrics":{"numFiles":"1","numOutputRows":"50000","numOutputBytes":"702"},"engineInfo":"Apache-Spark/3.5.5 Delta-Lake/3.3.2","txnId":"5bec127e-ea8a-4eef-ba09-3e549a66fc0c"}}
2+
{"metaData":{"id":"0e582e3d-6324-4194-bab0-4b3039c761bc","format":{"provider":"parquet","options":{}},"schemaString":"{\"type\":\"struct\",\"fields\":[{\"name\":\"year\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}},{\"name\":\"id_mandant\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}},{\"name\":\"text\",\"type\":\"string\",\"nullable\":true,\"metadata\":{}}]}","partitionColumns":["year","id_mandant"],"configuration":{},"createdTime":1774618197458}}
3+
{"protocol":{"minReaderVersion":1,"minWriterVersion":2}}
4+
{"add":{"path":"year=2026/id_mandant=0157/part-00000-45386c31-ae84-4fab-9d03-a074a8bae1a2.c000.snappy.parquet","partitionValues":{"year":"2026","id_mandant":"0157"},"size":702,"modificationTime":1774618199000,"dataChange":true,"stats":"{\"numRecords\":50000,\"minValues\":{\"text\":\"text0\"},\"maxValues\":{\"text\":\"text9\"},\"nullCount\":{\"text\":0}}"}}

0 commit comments

Comments
 (0)