Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
laserkaplan committed Aug 11, 2022
1 parent fa980dd commit 7cb46a4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
7 changes: 3 additions & 4 deletions tests/unit/sqlalchemy/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
table = Table(
'table',
metadata,
Column('id', Integer, primary_key=True),
Column('id', Integer),
Column('name', String),
)
table_with_catalog = Table(
'table',
metadata,
Column('id', Integer, primary_key=True),
Column('id', Integer),
schema='default',
trino_catalog='other'
)
Expand Down Expand Up @@ -86,7 +86,6 @@ def test_catalogs_create_table(dialect):
assert str(query) == \
'\n'\
'CREATE TABLE "other".default."table" (\n'\
'\tid INTEGER NOT NULL, \n'\
'\tPRIMARY KEY (id)\n'\
'\tid INTEGER\n'\
')\n'\
'\n'
7 changes: 4 additions & 3 deletions trino/sqlalchemy/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
Subquery,
)
except ImportError:
# For SQLAlchemy versions < 1.4, the CTE and Subquery classes did not explicitly exist
from sqlalchemy.sql.expression import Alias
CTE = type(None)
Subquery = type(None)
Expand Down Expand Up @@ -129,12 +130,12 @@ def add_catalog(sql, table):

if (
'trino' not in table.dialect_options
or 'catalog' not in table.dialect_options['trino']._non_defaults
or 'catalog' not in table.dialect_options['trino']
):
return sql

catalog = table.dialect_options['trino']._non_defaults['catalog']
sql = '"{catalog}".{sql}'.format(catalog=catalog, sql=sql)
catalog = table.dialect_options['trino']['catalog']
sql = f'"{catalog}".{sql}'
return sql


Expand Down

0 comments on commit 7cb46a4

Please sign in to comment.