@@ -17,49 +17,56 @@ def test_sql_execution_chunked(ws, disposition):
17
17
assert total == 1999999000000
18
18
19
19
20
- def test_sql_execution (ws , env_or_skip ):
21
- results = []
20
+ NYC_TAXI_LIMITED_TRIPS = """
21
+ WITH zipcodes AS (
22
+ SELECT DISTINCT pickup_zip, dropoff_zip
23
+ FROM samples.nyctaxi.trips
24
+ WHERE pickup_zip = 10282 AND dropoff_zip <= 10005
25
+ )
26
+
27
+ SELECT
28
+ trips.pickup_zip,
29
+ trips.dropoff_zip,
30
+ trips.tpep_pickup_datetime,
31
+ trips.tpep_dropoff_datetime
32
+ FROM
33
+ zipcodes
34
+ JOIN
35
+ samples.nyctaxi.trips AS trips
36
+ ON zipcodes.pickup_zip = trips.pickup_zip AND zipcodes.dropoff_zip = trips.dropoff_zip
37
+ ORDER BY trips.dropoff_zip, trips.tpep_pickup_datetime, trips.tpep_dropoff_datetime
38
+ """
39
+
40
+
41
+ def test_sql_execution (ws , env_or_skip ) -> None :
42
+ results = set ()
22
43
see = StatementExecutionExt (ws , warehouse_id = env_or_skip ("TEST_DEFAULT_WAREHOUSE_ID" ))
23
- for pickup_zip , dropoff_zip in see .fetch_all (
24
- "SELECT pickup_zip, dropoff_zip FROM nyctaxi.trips LIMIT 10" , catalog = "samples"
25
- ):
26
- results .append ((pickup_zip , dropoff_zip ))
27
- assert results == [
28
- (10282 , 10171 ),
29
- (10110 , 10110 ),
30
- (10103 , 10023 ),
31
- (10022 , 10017 ),
32
- (10110 , 10282 ),
33
- (10009 , 10065 ),
34
- (10153 , 10199 ),
35
- (10112 , 10069 ),
36
- (10023 , 10153 ),
37
- (10012 , 10003 ),
38
- ]
39
-
40
-
41
- def test_sql_execution_partial (ws , env_or_skip ):
42
- results = []
44
+ for pickup_zip , dropoff_zip , * _ in see .fetch_all (NYC_TAXI_LIMITED_TRIPS , catalog = "samples" ):
45
+ results .add ((pickup_zip , dropoff_zip ))
46
+ assert results == {
47
+ (10282 , 7114 ),
48
+ (10282 , 10001 ),
49
+ (10282 , 10002 ),
50
+ (10282 , 10003 ),
51
+ (10282 , 10005 ),
52
+ }
53
+
54
+
55
+ def test_sql_execution_partial (ws , env_or_skip ) -> None :
56
+ results = set ()
43
57
see = StatementExecutionExt (ws , warehouse_id = env_or_skip ("TEST_DEFAULT_WAREHOUSE_ID" ), catalog = "samples" )
44
- for row in see ("SELECT * FROM nyctaxi.trips LIMIT 10" ):
45
- pickup_time , dropoff_time = row [0 ], row [1 ]
46
- pickup_zip = row .pickup_zip
47
- dropoff_zip = row ["dropoff_zip" ]
58
+ for row in see (NYC_TAXI_LIMITED_TRIPS ):
59
+ pickup_zip , dropoff_zip , pickup_time , dropoff_time = row [0 ], row [1 ], row [2 ], row [3 ]
48
60
all_fields = row .asDict ()
49
61
logger .info (f"{ pickup_zip } @{ pickup_time } -> { dropoff_zip } @{ dropoff_time } : { all_fields } " )
50
- results .append ((pickup_zip , dropoff_zip ))
51
- assert results == [
52
- (10282 , 10171 ),
53
- (10110 , 10110 ),
54
- (10103 , 10023 ),
55
- (10022 , 10017 ),
56
- (10110 , 10282 ),
57
- (10009 , 10065 ),
58
- (10153 , 10199 ),
59
- (10112 , 10069 ),
60
- (10023 , 10153 ),
61
- (10012 , 10003 ),
62
- ]
62
+ results .add ((pickup_zip , dropoff_zip ))
63
+ assert results == {
64
+ (10282 , 7114 ),
65
+ (10282 , 10001 ),
66
+ (10282 , 10002 ),
67
+ (10282 , 10003 ),
68
+ (10282 , 10005 ),
69
+ }
63
70
64
71
65
72
def test_fetch_one (ws ):
@@ -73,9 +80,9 @@ def test_fetch_one_fails_if_limit_is_bigger(ws):
73
80
see .fetch_one ("SELECT * FROM samples.nyctaxi.trips LIMIT 100" )
74
81
75
82
76
- def test_fetch_one_works (ws ):
83
+ def test_fetch_one_works (ws ) -> None :
77
84
see = StatementExecutionExt (ws )
78
- row = see .fetch_one ("SELECT * FROM samples.nyctaxi.trips LIMIT 1" )
85
+ row = see .fetch_one ("SELECT * FROM samples.nyctaxi.trips WHERE pickup_zip == 10282 LIMIT 1" )
79
86
assert row .pickup_zip == 10282
80
87
81
88
0 commit comments