Quote pushdown identifiers and stabilize MSSQL projection aliases - #18
Merged
Conversation
apply_polars_io_source_exprs wraps the source query in a subquery and adds the outer projection/predicate for column and predicate pushdown. When the source projection used unquoted reserved words, mixed-case names, or names with special characters, the generated outer references could fail to resolve or bind to the wrong column depending on the target dialect. - Quote outer projection identifiers for dialects SQLGlot recognizes. - Quote the leaf identifiers of pushed-down predicate columns. - For MSSQL, stabilize the output-defining SELECT: quote explicit aliases and give simple columns an explicit quoted alias, following only the leftmost output branch of set operations / parenthesized queries and leaving CTE bodies untouched. Adds _is_known_dialect, _quote_column_leaf_identifier, _leftmost_output_select, and _stabilize_mssql_projection_aliases, plus tests covering the quoting matrix across dialects and the MSSQL stabilization edge cases. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Pascal Tomecek <40371786+ptomecek@users.noreply.github.com>
Contributor
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.
When
apply_polars_io_source_exprswraps a source query in a subquery and adds the outer projection/predicate for column and predicate pushdown, unquoted identifiers could fail to resolve or bind to the wrong column — reserved words (e.g.group), mixed-case names, or names with special characters, depending on the target dialect.Changes
New helpers:
_is_known_dialect,_quote_column_leaf_identifier,_leftmost_output_select,_stabilize_mssql_projection_aliases.apply_polars_io_source_exprsis shared byscan_dbandscan_clickhouse, so both benefit.Tests: quoting matrix across dialects (postgres/oracle/snowflake), metadata-name round-trips through duckdb, predicate-leaf quoting scope, and MSSQL stabilization edge cases (idempotency, CTE bodies, parenthesized set operations, projection order). Full
test_lazy_sql_reader(108) andtest_lazy_clickhouse_reader(10) pass; ruff clean.