Skip to content

Commit e9669c2

Browse files
committed
Merge remote-tracking branch 'origin/main' into feat/trino-listener-integration
2 parents 7921ba0 + 6b83a29 commit e9669c2

6 files changed

Lines changed: 309 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ All notable changes to this project will be documented in this file.
3232
- The defaults from the docker images itself will now apply, which will be different from 1000/0 going forward
3333
- This is marked as breaking because tools and policies might exist, which require these fields to be set
3434
- Deprecate Trino 470 ([#755]).
35+
- test: support custom versions ([#760]).
3536

3637
### Fixed
3738

@@ -54,6 +55,7 @@ All notable changes to this project will be documented in this file.
5455
[#752]: https://github.com/stackabletech/trino-operator/pull/752
5556
[#753]: https://github.com/stackabletech/trino-operator/pull/753
5657
[#755]: https://github.com/stackabletech/trino-operator/pull/755
58+
[#760]: https://github.com/stackabletech/trino-operator/pull/760
5759

5860
## [25.3.0] - 2025-03-21
5961

tests/templates/kuttl/commons/check-s3.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import trino
33
import argparse
44
import sys
5+
import re
56

67
if not sys.warnoptions:
78
import warnings
@@ -58,8 +59,11 @@ def run_query(connection, query):
5859
)[0][0]
5960
print(f'[INFO] Testing against Trino version "{trino_version}"')
6061

61-
assert len(trino_version) >= 3
62-
assert trino_version.isnumeric()
62+
# Strip SDP release suffix from the version string
63+
trino_product_version = re.split(r"-stackable", trino_version, maxsplit=1)[0]
64+
65+
assert len(trino_product_version) >= 3
66+
assert trino_product_version.isnumeric()
6367
assert trino_version == run_query(connection, "select version()")[0][0]
6468

6569
run_query(
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
apiVersion: kuttl.dev/v1beta1
33
kind: TestAssert
4-
timeout: 300
4+
timeout: 600
55
commands:
6-
- script: kubectl -n $NAMESPACE rollout status daemonset opa-server-default --timeout 300s
6+
- script: kubectl -n $NAMESPACE rollout status daemonset opa-server-default --timeout 600s
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
apiVersion: kuttl.dev/v1beta1
33
kind: TestAssert
4-
timeout: 300
4+
timeout: 600
55
commands:
6-
- script: kubectl -n $NAMESPACE rollout status daemonset opa-server-default --timeout 300s
6+
- script: kubectl -n $NAMESPACE rollout status daemonset opa-server-default --timeout 600s
Lines changed: 295 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,295 @@
1+
#!/usr/bin/env python
2+
import trino
3+
import argparse
4+
import sys
5+
import re
6+
7+
if not sys.warnoptions:
8+
import warnings
9+
warnings.simplefilter("ignore")
10+
11+
12+
def get_connection(username, password, namespace):
13+
host = (
14+
"trino-coordinator-default-0.trino-coordinator-default."
15+
+ namespace
16+
+ ".svc.cluster.local"
17+
)
18+
# If you want to debug this locally use
19+
# kubectl -n kuttl-test-XXX port-forward svc/trino-coordinator-default 8443
20+
# host = '127.0.0.1'
21+
22+
conn = trino.dbapi.connect(
23+
host=host,
24+
port=8443,
25+
user=username,
26+
http_scheme="https",
27+
auth=trino.auth.BasicAuthentication(username, password),
28+
session_properties={"query_max_execution_time": "60s"},
29+
)
30+
conn._http_session.verify = False
31+
return conn
32+
33+
34+
def run_query(connection, query):
35+
print(f"[DEBUG] Executing query {query}")
36+
cursor = connection.cursor()
37+
cursor.execute(query)
38+
return cursor.fetchall()
39+
40+
41+
if __name__ == "__main__":
42+
# Construct an argument parser
43+
all_args = argparse.ArgumentParser()
44+
# Add arguments to the parser
45+
all_args.add_argument(
46+
"-n", "--namespace", required=True, help="Namespace the test is running in"
47+
)
48+
49+
args = vars(all_args.parse_args())
50+
namespace = args["namespace"]
51+
52+
print("Starting S3 tests...")
53+
connection = get_connection("admin", "admin", namespace)
54+
55+
trino_version = run_query(
56+
connection,
57+
"select node_version from system.runtime.nodes where coordinator = true and state = 'active'",
58+
)[0][0]
59+
print(f'[INFO] Testing against Trino version "{trino_version}"')
60+
61+
# Strip SDP release suffix from the version string
62+
trino_product_version = re.split(r"-stackable", trino_version, maxsplit=1)[0]
63+
64+
assert len(trino_product_version) >= 3
65+
assert trino_product_version.isnumeric()
66+
assert trino_version == run_query(connection, "select version()")[0][0]
67+
68+
run_query(
69+
connection,
70+
"CREATE SCHEMA IF NOT EXISTS hive.minio WITH (location = 's3a://trino/')",
71+
)
72+
73+
run_query(connection, "DROP TABLE IF EXISTS hive.minio.taxi_data")
74+
run_query(connection, "DROP TABLE IF EXISTS hive.minio.taxi_data_copy")
75+
run_query(connection, "DROP TABLE IF EXISTS hive.minio.taxi_data_transformed")
76+
run_query(connection, "DROP TABLE IF EXISTS hive.hdfs.taxi_data_copy")
77+
run_query(connection, "DROP TABLE IF EXISTS iceberg.minio.taxi_data_copy_iceberg")
78+
79+
run_query(
80+
connection,
81+
"""
82+
CREATE TABLE IF NOT EXISTS hive.minio.taxi_data (
83+
vendor_id VARCHAR,
84+
tpep_pickup_datetime VARCHAR,
85+
tpep_dropoff_datetime VARCHAR,
86+
passenger_count VARCHAR,
87+
trip_distance VARCHAR,
88+
ratecode_id VARCHAR
89+
) WITH (
90+
external_location = 's3a://trino/taxi-data/',
91+
format = 'csv',
92+
skip_header_line_count = 1
93+
)
94+
""",
95+
)
96+
assert (
97+
run_query(connection, "SELECT COUNT(*) FROM hive.minio.taxi_data")[0][0] == 5000
98+
)
99+
rows_written = run_query(
100+
connection,
101+
"CREATE TABLE IF NOT EXISTS hive.minio.taxi_data_copy AS SELECT * FROM hive.minio.taxi_data",
102+
)[0][0]
103+
assert rows_written == 5000 or rows_written == 0
104+
assert (
105+
run_query(connection, "SELECT COUNT(*) FROM hive.minio.taxi_data_copy")[0][0]
106+
== 5000
107+
)
108+
109+
rows_written = run_query(
110+
connection,
111+
"""
112+
CREATE TABLE IF NOT EXISTS hive.minio.taxi_data_transformed AS
113+
SELECT
114+
CAST(vendor_id as BIGINT) as vendor_id,
115+
tpep_pickup_datetime,
116+
tpep_dropoff_datetime,
117+
CAST(passenger_count as BIGINT) as passenger_count,
118+
CAST(trip_distance as DOUBLE) as trip_distance,
119+
CAST(ratecode_id as BIGINT) as ratecode_id
120+
FROM hive.minio.taxi_data
121+
""",
122+
)[0][0]
123+
assert rows_written == 5000 or rows_written == 0
124+
assert (
125+
run_query(connection, "SELECT COUNT(*) FROM hive.minio.taxi_data_transformed")[
126+
0
127+
][0]
128+
== 5000
129+
)
130+
131+
print("[INFO] Testing HDFS")
132+
133+
run_query(
134+
connection,
135+
"CREATE SCHEMA IF NOT EXISTS hive.hdfs WITH (location = 'hdfs://hdfs/trino/')",
136+
)
137+
rows_written = run_query(
138+
connection,
139+
"CREATE TABLE IF NOT EXISTS hive.hdfs.taxi_data_copy AS SELECT * FROM hive.minio.taxi_data",
140+
)[0][0]
141+
assert rows_written == 5000 or rows_written == 0
142+
assert (
143+
run_query(connection, "SELECT COUNT(*) FROM hive.hdfs.taxi_data_copy")[0][0]
144+
== 5000
145+
)
146+
147+
print("[INFO] Testing Iceberg")
148+
run_query(
149+
connection, "DROP TABLE IF EXISTS iceberg.minio.taxi_data_copy_iceberg"
150+
) # Clean up table to don't fail an second run
151+
assert (
152+
run_query(
153+
connection,
154+
"""
155+
CREATE TABLE IF NOT EXISTS iceberg.minio.taxi_data_copy_iceberg
156+
WITH (partitioning = ARRAY['vendor_id', 'passenger_count'], format = 'parquet')
157+
AS SELECT * FROM hive.minio.taxi_data
158+
""",
159+
)[0][0]
160+
== 5000
161+
)
162+
# Check current count
163+
assert (
164+
run_query(
165+
connection, "SELECT COUNT(*) FROM iceberg.minio.taxi_data_copy_iceberg"
166+
)[0][0]
167+
== 5000
168+
)
169+
assert (
170+
run_query(
171+
connection,
172+
'SELECT COUNT(*) FROM iceberg.minio."taxi_data_copy_iceberg$snapshots"',
173+
)[0][0]
174+
== 1
175+
)
176+
assert (
177+
run_query(
178+
connection,
179+
'SELECT COUNT(*) FROM iceberg.minio."taxi_data_copy_iceberg$partitions"',
180+
)[0][0]
181+
== 12
182+
)
183+
assert (
184+
run_query(
185+
connection,
186+
'SELECT COUNT(*) FROM iceberg.minio."taxi_data_copy_iceberg$files"',
187+
)[0][0]
188+
== 12
189+
)
190+
191+
assert (
192+
run_query(
193+
connection,
194+
"INSERT INTO iceberg.minio.taxi_data_copy_iceberg SELECT * FROM hive.minio.taxi_data",
195+
)[0][0]
196+
== 5000
197+
)
198+
199+
# Check current count
200+
assert (
201+
run_query(
202+
connection, "SELECT COUNT(*) FROM iceberg.minio.taxi_data_copy_iceberg"
203+
)[0][0]
204+
== 10000
205+
)
206+
assert (
207+
run_query(
208+
connection,
209+
'SELECT COUNT(*) FROM iceberg.minio."taxi_data_copy_iceberg$snapshots"',
210+
)[0][0]
211+
== 2
212+
)
213+
assert (
214+
run_query(
215+
connection,
216+
'SELECT COUNT(*) FROM iceberg.minio."taxi_data_copy_iceberg$partitions"',
217+
)[0][0]
218+
== 12
219+
)
220+
assert (
221+
run_query(
222+
connection,
223+
'SELECT COUNT(*) FROM iceberg.minio."taxi_data_copy_iceberg$files"',
224+
)[0][0]
225+
== 24
226+
)
227+
228+
if trino_version == "377":
229+
# io.trino.spi.TrinoException: This connector [iceberg] does not support versioned tables
230+
print(
231+
"[INFO] Skipping the Iceberg tests reading versioned tables for trino version 377 as it does not support versioned tables"
232+
)
233+
else:
234+
# Check count for first snapshot
235+
first_snapshot = run_query(
236+
connection,
237+
'select snapshot_id from iceberg.minio."taxi_data_copy_iceberg$snapshots" order by committed_at limit 1',
238+
)[0][0]
239+
assert (
240+
run_query(
241+
connection,
242+
f"SELECT COUNT(*) FROM iceberg.minio.taxi_data_copy_iceberg FOR VERSION AS OF {first_snapshot}",
243+
)[0][0]
244+
== 5000
245+
)
246+
247+
# Compact files
248+
run_query(
249+
connection, "ALTER TABLE iceberg.minio.taxi_data_copy_iceberg EXECUTE optimize"
250+
)
251+
252+
# Check current count
253+
assert (
254+
run_query(
255+
connection, "SELECT COUNT(*) FROM iceberg.minio.taxi_data_copy_iceberg"
256+
)[0][0]
257+
== 10000
258+
)
259+
assert (
260+
run_query(
261+
connection,
262+
'SELECT COUNT(*) FROM iceberg.minio."taxi_data_copy_iceberg$snapshots"',
263+
)[0][0]
264+
== 3
265+
)
266+
assert (
267+
run_query(
268+
connection,
269+
'SELECT COUNT(*) FROM iceberg.minio."taxi_data_copy_iceberg$partitions"',
270+
)[0][0]
271+
== 12
272+
)
273+
assert (
274+
run_query(
275+
connection,
276+
'SELECT COUNT(*) FROM iceberg.minio."taxi_data_copy_iceberg$files"',
277+
)[0][0]
278+
== 12
279+
) # Compaction yeah :)
280+
281+
# Test could be improved by also testing update and deletes
282+
283+
# Test postgres connection
284+
run_query(connection, "SHOW SCHEMAS IN postgresgeneric")
285+
run_query(connection, "CREATE SCHEMA IF NOT EXISTS postgresgeneric.tpch")
286+
run_query(
287+
connection,
288+
"CREATE TABLE IF NOT EXISTS postgresgeneric.tpch.nation AS SELECT * FROM tpch.tiny.nation",
289+
)
290+
assert (
291+
run_query(connection, "SELECT COUNT(*) FROM postgresgeneric.tpch.nation")[0][0]
292+
== 25
293+
)
294+
295+
print("[SUCCESS] All tests in check-s3.py succeeded!")
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
apiVersion: kuttl.dev/v1beta1
33
kind: TestAssert
4-
timeout: 300
4+
timeout: 600
55
commands:
6-
- script: kubectl -n $NAMESPACE rollout status daemonset opa-server-default --timeout 300s
6+
- script: kubectl -n $NAMESPACE rollout status daemonset opa-server-default --timeout 600s

0 commit comments

Comments
 (0)