@@ -108,13 +108,13 @@ def test_basic(self):
108108
109109 t = table ("point" )
110110 t2 = t .select (x = this .x + 1 , y = t ["y" ] + this .x )
111- assert c .compile (t2 ) == "SELECT (x + 1) AS x, (y + x) AS y FROM point"
111+ assert c .dialect . compile (c , t2 ) == "SELECT (x + 1) AS x, (y + x) AS y FROM point"
112112
113113 t = table ("point" ).where (this .x == 1 , this .y == 2 )
114- assert c .compile (t ) == "SELECT * FROM point WHERE (x = 1) AND (y = 2)"
114+ assert c .dialect . compile (c , t ) == "SELECT * FROM point WHERE (x = 1) AND (y = 2)"
115115
116116 t = table ("person" ).where (this .name == "Albert" )
117- self .assertEqual (c .compile (t ), "SELECT * FROM person WHERE (name = 'Albert')" )
117+ self .assertEqual (c .dialect . compile (c , t ), "SELECT * FROM person WHERE (name = 'Albert')" )
118118
119119 def test_outerjoin (self ):
120120 c = Compiler (MockDatabase ())
@@ -127,7 +127,8 @@ def test_outerjoin(self):
127127 j = outerjoin (a , b ).on (a [k ] == b [k ] for k in keys )
128128
129129 self .assertEqual (
130- c .compile (j ), "SELECT * FROM a tmp1 FULL OUTER JOIN b tmp2 ON (tmp1.x = tmp2.x) AND (tmp1.y = tmp2.y)"
130+ c .dialect .compile (c , j ),
131+ "SELECT * FROM a tmp1 FULL OUTER JOIN b tmp2 ON (tmp1.x = tmp2.x) AND (tmp1.y = tmp2.y)" ,
131132 )
132133
133134 def test_schema (self ):
@@ -137,7 +138,7 @@ def test_schema(self):
137138 # test table
138139 t = table ("a" , schema = CaseInsensitiveDict (schema ))
139140 q = t .select (this .Id , t ["COMMENT" ])
140- assert c .compile (q ) == "SELECT id, comment FROM a"
141+ assert c .dialect . compile (c , q ) == "SELECT id, comment FROM a"
141142
142143 t = table ("a" , schema = CaseSensitiveDict (schema ))
143144 self .assertRaises (KeyError , t .__getitem__ , "Id" )
@@ -174,67 +175,67 @@ def test_cte(self):
174175 t3 = t2 .select (this .x )
175176
176177 expected = "WITH tmp1 AS (SELECT x FROM a) SELECT x FROM tmp1"
177- assert normalize_spaces (c .compile (t3 )) == expected
178+ assert normalize_spaces (c .dialect . compile (c , t3 )) == expected
178179
179180 # nested cte
180181 c = Compiler (MockDatabase ())
181182 t4 = cte (t3 ).select (this .x )
182183
183184 expected = "WITH tmp1 AS (SELECT x FROM a), tmp2 AS (SELECT x FROM tmp1) SELECT x FROM tmp2"
184- assert normalize_spaces (c .compile (t4 )) == expected
185+ assert normalize_spaces (c .dialect . compile (c , t4 )) == expected
185186
186187 # parameterized cte
187188 c = Compiler (MockDatabase ())
188189 t2 = cte (t .select (this .x ), params = ["y" ])
189190 t3 = t2 .select (this .y )
190191
191192 expected = "WITH tmp1(y) AS (SELECT x FROM a) SELECT y FROM tmp1"
192- assert normalize_spaces (c .compile (t3 )) == expected
193+ assert normalize_spaces (c .dialect . compile (c , t3 )) == expected
193194
194195 def test_funcs (self ):
195196 c = Compiler (MockDatabase ())
196197 t = table ("a" )
197198
198- q = c .compile (t .order_by (Random ()).limit (10 ))
199+ q = c .dialect . compile (c , t .order_by (Random ()).limit (10 ))
199200 self .assertEqual (q , "SELECT * FROM (SELECT * FROM a ORDER BY random()) AS LIMITED_SELECT LIMIT 10" )
200201
201- q = c .compile (t .select (coalesce (this .a , this .b )))
202+ q = c .dialect . compile (c , t .select (coalesce (this .a , this .b )))
202203 self .assertEqual (q , "SELECT COALESCE(a, b) FROM a" )
203204
204205 def test_select_distinct (self ):
205206 c = Compiler (MockDatabase ())
206207 t = table ("a" )
207208
208- q = c .compile (t .select (this .b , distinct = True ))
209+ q = c .dialect . compile (c , t .select (this .b , distinct = True ))
209210 assert q == "SELECT DISTINCT b FROM a"
210211
211212 # selects merge
212- q = c .compile (t .where (this .b > 10 ).select (this .b , distinct = True ))
213+ q = c .dialect . compile (c , t .where (this .b > 10 ).select (this .b , distinct = True ))
213214 self .assertEqual (q , "SELECT DISTINCT b FROM a WHERE (b > 10)" )
214215
215216 # selects stay apart
216- q = c .compile (t .limit (10 ).select (this .b , distinct = True ))
217+ q = c .dialect . compile (c , t .limit (10 ).select (this .b , distinct = True ))
217218 self .assertEqual (q , "SELECT DISTINCT b FROM (SELECT * FROM (SELECT * FROM a) AS LIMITED_SELECT LIMIT 10) tmp1" )
218219
219- q = c .compile (t .select (this .b , distinct = True ).select (distinct = False ))
220+ q = c .dialect . compile (c , t .select (this .b , distinct = True ).select (distinct = False ))
220221 self .assertEqual (q , "SELECT * FROM (SELECT DISTINCT b FROM a) tmp2" )
221222
222223 def test_select_with_optimizer_hints (self ):
223224 c = Compiler (MockDatabase ())
224225 t = table ("a" )
225226
226- q = c .compile (t .select (this .b , optimizer_hints = "PARALLEL(a 16)" ))
227+ q = c .dialect . compile (c , t .select (this .b , optimizer_hints = "PARALLEL(a 16)" ))
227228 assert q == "SELECT /*+ PARALLEL(a 16) */ b FROM a"
228229
229- q = c .compile (t .where (this .b > 10 ).select (this .b , optimizer_hints = "PARALLEL(a 16)" ))
230+ q = c .dialect . compile (c , t .where (this .b > 10 ).select (this .b , optimizer_hints = "PARALLEL(a 16)" ))
230231 self .assertEqual (q , "SELECT /*+ PARALLEL(a 16) */ b FROM a WHERE (b > 10)" )
231232
232- q = c .compile (t .limit (10 ).select (this .b , optimizer_hints = "PARALLEL(a 16)" ))
233+ q = c .dialect . compile (c , t .limit (10 ).select (this .b , optimizer_hints = "PARALLEL(a 16)" ))
233234 self .assertEqual (
234235 q , "SELECT /*+ PARALLEL(a 16) */ b FROM (SELECT * FROM (SELECT * FROM a) AS LIMITED_SELECT LIMIT 10) tmp1"
235236 )
236237
237- q = c .compile (t .select (this .a ).group_by (this .b ).agg (this .c ).select (optimizer_hints = "PARALLEL(a 16)" ))
238+ q = c .dialect . compile (c , t .select (this .a ).group_by (this .b ).agg (this .c ).select (optimizer_hints = "PARALLEL(a 16)" ))
238239 self .assertEqual (
239240 q , "SELECT /*+ PARALLEL(a 16) */ * FROM (SELECT b, c FROM (SELECT a FROM a) tmp2 GROUP BY 1) tmp3"
240241 )
@@ -244,85 +245,86 @@ def test_table_ops(self):
244245 a = table ("a" ).select (this .x )
245246 b = table ("b" ).select (this .y )
246247
247- q = c .compile (a .union (b ))
248+ q = c .dialect . compile (c , a .union (b ))
248249 assert q == "SELECT x FROM a UNION SELECT y FROM b"
249250
250- q = c .compile (a .union_all (b ))
251+ q = c .dialect . compile (c , a .union_all (b ))
251252 assert q == "SELECT x FROM a UNION ALL SELECT y FROM b"
252253
253- q = c .compile (a .minus (b ))
254+ q = c .dialect . compile (c , a .minus (b ))
254255 assert q == "SELECT x FROM a EXCEPT SELECT y FROM b"
255256
256- q = c .compile (a .intersect (b ))
257+ q = c .dialect . compile (c , a .intersect (b ))
257258 assert q == "SELECT x FROM a INTERSECT SELECT y FROM b"
258259
259260 def test_ops (self ):
260261 c = Compiler (MockDatabase ())
261262 t = table ("a" )
262263
263- q = c .compile (t .select (this .b + this .c ))
264+ q = c .dialect . compile (c , t .select (this .b + this .c ))
264265 self .assertEqual (q , "SELECT (b + c) FROM a" )
265266
266- q = c .compile (t .select (this .b .like (this .c )))
267+ q = c .dialect . compile (c , t .select (this .b .like (this .c )))
267268 self .assertEqual (q , "SELECT (b LIKE c) FROM a" )
268269
269- q = c .compile (t .select (- this .b .sum ()))
270+ q = c .dialect . compile (c , t .select (- this .b .sum ()))
270271 self .assertEqual (q , "SELECT (-SUM(b)) FROM a" )
271272
272273 def test_group_by (self ):
273274 c = Compiler (MockDatabase ())
274275 t = table ("a" )
275276
276- q = c .compile (t .group_by (this .b ).agg (this .c ))
277+ q = c .dialect . compile (c , t .group_by (this .b ).agg (this .c ))
277278 self .assertEqual (q , "SELECT b, c FROM a GROUP BY 1" )
278279
279- q = c .compile (t .where (this .b > 1 ).group_by (this .b ).agg (this .c ))
280+ q = c .dialect . compile (c , t .where (this .b > 1 ).group_by (this .b ).agg (this .c ))
280281 self .assertEqual (q , "SELECT b, c FROM a WHERE (b > 1) GROUP BY 1" )
281282
282- self .assertRaises (CompileError , c .compile , t .select (this .b ).group_by (this .b ))
283+ self .assertRaises (CompileError , c .dialect . compile , c , t .select (this .b ).group_by (this .b ))
283284
284- q = c .compile (t .select (this .b ).group_by (this .b ).agg ())
285+ q = c .dialect . compile (c , t .select (this .b ).group_by (this .b ).agg ())
285286 self .assertEqual (q , "SELECT b FROM (SELECT b FROM a) tmp1 GROUP BY 1" )
286287
287- q = c .compile (t .group_by (this .b , this .c ).agg (this .d , this .e ))
288+ q = c .dialect . compile (c , t .group_by (this .b , this .c ).agg (this .d , this .e ))
288289 self .assertEqual (q , "SELECT b, c, d, e FROM a GROUP BY 1, 2" )
289290
290291 # Having
291- q = c .compile (t .group_by (this .b ).agg (this .c ).having (this .b > 1 ))
292+ q = c .dialect . compile (c , t .group_by (this .b ).agg (this .c ).having (this .b > 1 ))
292293 self .assertEqual (q , "SELECT b, c FROM a GROUP BY 1 HAVING (b > 1)" )
293294
294- q = c .compile (t .group_by (this .b ).having (this .b > 1 ).agg (this .c ))
295+ q = c .dialect . compile (c , t .group_by (this .b ).having (this .b > 1 ).agg (this .c ))
295296 self .assertEqual (q , "SELECT b, c FROM a GROUP BY 1 HAVING (b > 1)" )
296297
297- q = c .compile (t .select (this .b ).group_by (this .b ).agg ().having (this .b > 1 ))
298+ q = c .dialect . compile (c , t .select (this .b ).group_by (this .b ).agg ().having (this .b > 1 ))
298299 self .assertEqual (q , "SELECT b FROM (SELECT b FROM a) tmp2 GROUP BY 1 HAVING (b > 1)" )
299300
300301 # Having sum
301- q = c .compile (t .group_by (this .b ).agg (this .c , this .d ).having (this .b .sum () > 1 ))
302+ q = c .dialect . compile (c , t .group_by (this .b ).agg (this .c , this .d ).having (this .b .sum () > 1 ))
302303 self .assertEqual (q , "SELECT b, c, d FROM a GROUP BY 1 HAVING (SUM(b) > 1)" )
303304
304305 # Select interaction
305- q = c .compile (t .select (this .a ).group_by (this .b ).agg (this .c ).select (this .c + 1 ))
306+ q = c .dialect . compile (c , t .select (this .a ).group_by (this .b ).agg (this .c ).select (this .c + 1 ))
306307 self .assertEqual (q , "SELECT (c + 1) FROM (SELECT b, c FROM (SELECT a FROM a) tmp3 GROUP BY 1) tmp4" )
307308
308309 def test_case_when (self ):
309310 c = Compiler (MockDatabase ())
310311 t = table ("a" )
311312
312- q = c .compile (t .select (when (this .b ).then (this .c )))
313+ q = c .dialect . compile (c , t .select (when (this .b ).then (this .c )))
313314 self .assertEqual (q , "SELECT CASE WHEN b THEN c END FROM a" )
314315
315- q = c .compile (t .select (when (this .b ).then (this .c ).else_ (this .d )))
316+ q = c .dialect . compile (c , t .select (when (this .b ).then (this .c ).else_ (this .d )))
316317 self .assertEqual (q , "SELECT CASE WHEN b THEN c ELSE d END FROM a" )
317318
318- q = c .compile (
319+ q = c .dialect .compile (
320+ c ,
319321 t .select (
320322 when (this .type == "text" )
321323 .then (this .text )
322324 .when (this .type == "number" )
323325 .then (this .number )
324326 .else_ ("unknown type" )
325- )
327+ ),
326328 )
327329 self .assertEqual (
328330 q ,
@@ -333,13 +335,13 @@ def test_code(self):
333335 c = Compiler (MockDatabase ())
334336 t = table ("a" )
335337
336- q = c .compile (t .select (this .b , code ("<x>" )).where (code ("<y>" )))
338+ q = c .dialect . compile (c , t .select (this .b , code ("<x>" )).where (code ("<y>" )))
337339 self .assertEqual (q , "SELECT b, <x> FROM a WHERE <y>" )
338340
339341 def tablesample (t , size ):
340342 return code ("{t} TABLESAMPLE BERNOULLI ({size})" , t = t , size = size )
341343
342344 nonzero = table ("points" ).where (this .x > 0 , this .y > 0 )
343345
344- q = c .compile (tablesample (nonzero , 10 ))
346+ q = c .dialect . compile (c , tablesample (nonzero , 10 ))
345347 self .assertEqual (q , "SELECT * FROM points WHERE (x > 0) AND (y > 0) TABLESAMPLE BERNOULLI (10)" )
0 commit comments