Repository navigation
fix(py): quote column names in SQLAlchemySource statistics queries - #332
Open
pcbeingused333 wants to merge 2 commits into
Open
pcbeingused333 wants to merge 2 commits into
pcbeingused333 wants to merge 2 commits into
Conversation
The min/max/nunique and categorical-value queries interpolated column names unquoted, so a name with a space, capitals, a reserved word or an apostrophe made the query fail; the broad except then dropped the statistics for the whole table. Quote with the engine's identifier preparer, as the DuckDB path does with quote_identifier. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SQLAlchemySourcebuilds its per-column statistics queries by interpolating column names unquoted:MIN(unit price) as unit price__min,COUNT(DISTINCT Group) ..., and the categorical-valuesUNION ALLquery. For a column whose name has a space, capital letters, a reserved word or an apostrophe the query is invalid, and the broadexcept Exceptionthen drops the statistics for the whole table:get_schema()lists the columns but no ranges and no categorical values, so the LLM gets less context with no warning. The DuckDB-backed sources already quote these names (quote_identifier).What changed: the column names and the
__min/__max/__nuniquealiases are quoted with the engine's ownidentifier_preparer, which only quotes where the dialect needs it and so leaves the SQL for plain names unchanged. The column name used as a string literal in the categorical query has its single quotes doubled.table_nameis left as it was.Tests. A SQLite table with columns
unit price,Groupandit'sis checked for its range and categorical values inget_schema(). The test fails on main and passes here, as do the other tests intest_datasource.pyandtest_deferred_datasource.py(45 passed). No LLM or database service was used.This change was made with Claude Code.
🤖 Generated with Claude Code