Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions tests/integration/test_sqlalchemy_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,10 +922,10 @@ def test_get_indexes_returns_empty_for_iceberg_table(run_trino):


@pytest.mark.skipif(trino_version() == 351, reason="Dynamic catalogs not supported")
def test_get_indexes_returns_partitions_for_hive_table(run_trino):
@pytest.mark.parametrize("schema_name", ["test_schema", "test-schema"])
def test_get_indexes_returns_partitions_for_hive_table(run_trino, schema_name):
host, port = run_trino
catalog_name = "test_hive"
schema_name = "test_schema"
table_name = "partitioned"

conn = trino.dbapi.connect(host=host, port=port, user="test")
Expand All @@ -938,16 +938,16 @@ def test_get_indexes_returns_partitions_for_hive_table(run_trino):
f"\"fs.native-local.enabled\" = 'true')"
)
cur.fetchall()
cur.execute(f"CREATE SCHEMA {catalog_name}.{schema_name}")
cur.execute(f"CREATE SCHEMA {catalog_name}.\"{schema_name}\"")
cur.fetchall()
cur.execute(
f"CREATE TABLE {catalog_name}.{schema_name}.{table_name} "
f"CREATE TABLE {catalog_name}.\"{schema_name}\".{table_name} "
f"(id INTEGER, name VARCHAR, region VARCHAR) "
f"WITH (partitioned_by = ARRAY['name', 'region'])"
)
cur.fetchall()
cur.execute(
f"INSERT INTO {catalog_name}.{schema_name}.{table_name} VALUES (1, 'alice', 'us-east')"
f"INSERT INTO {catalog_name}.\"{schema_name}\".{table_name} VALUES (1, 'alice', 'us-east')"
)
cur.fetchall()

Expand All @@ -962,9 +962,9 @@ def test_get_indexes_returns_partitions_for_hive_table(run_trino):
_assert_no_lingering_query(cur, f'{table_name}$partitions')
finally:
cur = conn.cursor()
cur.execute(f"DROP TABLE IF EXISTS {catalog_name}.{schema_name}.{table_name}")
cur.execute(f"DROP TABLE IF EXISTS {catalog_name}.\"{schema_name}\".{table_name}")
cur.fetchall()
cur.execute(f"DROP SCHEMA IF EXISTS {catalog_name}.{schema_name}")
cur.execute(f"DROP SCHEMA IF EXISTS {catalog_name}.\"{schema_name}\"")
cur.fetchall()
cur.execute(f"DROP CATALOG IF EXISTS {catalog_name}")
cur.fetchall()
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/sqlalchemy/test_dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,23 @@ def test_get_partitions_defaults_schema_when_not_given(self):
query = str(connection.execute.call_args[0][0])
assert "default_schema" in query

@pytest.mark.parametrize(
"schema, table_name, expected_query",
[
("some-schema", "some_table", 'SELECT * FROM "some-schema"."some_table$partitions"'),
("some_schema", 'some"table', 'SELECT * FROM "some_schema"."some""table$partitions"'),
],
)
def test_get_partitions_quotes_identifiers(self, schema, table_name, expected_query):
partition_names = ["year"]
data_types = ["integer"]
connection, _ = self._partitions_connection(partition_names, data_types)

self.dialect._get_partitions(connection, table_name, schema)

query = str(connection.execute.call_args[0][0])
assert query == expected_query


def test_trino_connection_basic_auth():
dialect = TrinoDialect()
Expand Down
3 changes: 2 additions & 1 deletion trino/sqlalchemy/dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,10 @@ def _get_partitions(
schema: str = None
) -> Optional[List[str]]:
schema = schema or self._get_default_schema_name(connection)
partitions_table = self._get_full_table(f"{table_name}$partitions", schema)
query = dedent(
f"""
SELECT * FROM {schema}."{table_name}$partitions"
SELECT * FROM {partitions_table}
"""
).strip()

Expand Down