5
5
6
6
import pytest
7
7
import sqlglot as sg
8
+ import sqlglot .expressions as sge
8
9
from pytest import param
9
10
10
11
import ibis
24
25
25
26
_NAMES = {
26
27
"bigquery" : f"ibis_gbq_testing_{ getpass .getuser ()} _{ PYTHON_SHORT_VERSION } .functional_alltypes" ,
27
- "exasol" : '"functional_alltypes"' ,
28
28
}
29
29
30
30
31
- @pytest .mark .notyet (["oracle" ], reason = "table quoting behavior" )
31
+ @pytest .fixture (scope = "module" )
32
+ def ftname_raw (con ):
33
+ return _NAMES .get (con .name , "functional_alltypes" )
34
+
35
+
36
+ @pytest .fixture (scope = "module" )
37
+ def ftname (con , ftname_raw ):
38
+ table = sg .parse_one (ftname_raw , into = sge .Table )
39
+ table = sg .table (table .name , db = table .db , catalog = table .catalog , quoted = True )
40
+ return table .sql (con .dialect )
41
+
42
+
32
43
@dot_sql_never
33
44
@pytest .mark .parametrize (
34
45
"schema" ,
37
48
param ({"s" : "string" , "new_col" : "double" }, id = "explicit_schema" ),
38
49
],
39
50
)
40
- def test_con_dot_sql (backend , con , schema ):
51
+ def test_con_dot_sql (backend , con , schema , ftname ):
41
52
alltypes = backend .functional_alltypes
42
53
# pull out the quoted name
43
- name = _NAMES .get (con .name , "functional_alltypes" )
44
54
quoted = True
45
55
cols = [
46
56
sg .column ("string_col" , quoted = quoted ).as_ ("s" , quoted = quoted ).sql (con .dialect ),
@@ -50,7 +60,7 @@ def test_con_dot_sql(backend, con, schema):
50
60
]
51
61
t = (
52
62
con .sql (
53
- f"SELECT { ', ' .join (cols )} FROM { name } " ,
63
+ f"SELECT { ', ' .join (cols )} FROM { ftname } " ,
54
64
schema = schema ,
55
65
)
56
66
.group_by ("s" ) # group by a column from SQL
@@ -325,9 +335,16 @@ def test_cte(alltypes, df):
325
335
326
336
327
337
@dot_sql_never
328
- def test_bare_minimum (con , alltypes , df ):
338
+ def test_bare_minimum (alltypes , df , ftname_raw ):
329
339
"""Test that a backend that supports dot sql can do the most basic thing."""
330
340
331
- name = _NAMES .get (con .name , "functional_alltypes" ).replace ('"' , "" )
332
- expr = alltypes .sql (f'SELECT COUNT(*) AS "n" FROM "{ name } "' , dialect = "duckdb" )
341
+ expr = alltypes .sql (f'SELECT COUNT(*) AS "n" FROM "{ ftname_raw } "' , dialect = "duckdb" )
333
342
assert expr .to_pandas ().iat [0 , 0 ] == len (df )
343
+
344
+
345
+ @dot_sql_never
346
+ def test_embedded_cte (alltypes , ftname_raw ):
347
+ sql = f'WITH "x" AS (SELECT * FROM "{ ftname_raw } ") SELECT * FROM "x"'
348
+ expr = alltypes .sql (sql , dialect = "duckdb" )
349
+ result = expr .head (1 ).execute ()
350
+ assert len (result ) == 1
0 commit comments