11#!/usr/bin/env python
22import trino
33import argparse
4+ import urllib3
45
56
67def get_connection (coordinator ):
@@ -17,6 +18,8 @@ def get_connection(coordinator):
1718
1819
1920if __name__ == "__main__" :
21+ urllib3 .disable_warnings (urllib3 .exceptions .InsecureRequestWarning )
22+
2023 # Construct an argument parser
2124 all_args = argparse .ArgumentParser ()
2225
@@ -35,42 +38,25 @@ def get_connection(coordinator):
3538 try :
3639 cursor = conn .cursor ()
3740
38- # Test that TPCH connector is working
39- cursor .execute ("SELECT COUNT(*) FROM tpch.tiny.nation" )
40- result = cursor .fetchone ()
41- if result [0 ] != 25 : # TPCH tiny.nation has 25 rows
42- print (f"TPCH test failed: expected 25 nations, got { result [0 ]} " )
43- exit (- 1 )
44-
45- print ("TPCH connector test passed" )
41+ print ("🚜 fetching many rows from Trino to trigger spooling..." )
4642
47- # Test a more complex query
48- cursor .execute ("""
49- SELECT
50- nation.name,
51- COUNT(*) AS num_cust
52- FROM
53- tpch.tiny.customer
54- JOIN
55- tpch.tiny.nation ON customer.nationkey = nation.nationkey
56- GROUP BY
57- nation.name
58- ORDER BY
59- num_cust DESC
60- """ )
61- results = cursor .fetchall ()
62- if len (results ) == 0 :
63- print ("Complex query returned no results" )
64- exit (- 1 )
43+ cursor .execute ("SELECT * FROM tpch.sf100.customer" )
44+ customer_count = 0
45+ batch = 10
46+ while batch > 0 :
47+ print (f"⏳ fetching batch { batch } of 1000 rows..." )
48+ cursor .fetchmany (1_000 )
49+ customer_count += 1_000
50+ batch = batch - 1
51+ # assert customer_count == 15_000_000, f"TPCH test failed: expected 15 mil customers, got {customer_count}"
6552
66- print ("Complex query test passed " )
53+ print ("🎉 major success! " )
6754
6855 cursor .close ()
69- conn .close ()
7056
7157 except Exception as e :
72- print (f"Test failed with error : { e } " )
73- import traceback
58+ print (f"💀 oh noes! cannot fetch customers from Trino : { e } " )
59+ raise e
7460
75- traceback . print_exc ()
76- exit ( - 1 )
61+ finally :
62+ conn . close ( )
0 commit comments