Skip to content

Exclude literal-only aliases from columns_dict - #714

Open
mmporong wants to merge 1 commit into
macbre:masterfrom
mmporong:fix/literal-alias-columns-dict
Open

mmporong wants to merge 1 commit into
macbre:masterfrom
mmporong:fix/literal-alias-columns-dict

Conversation

@mmporong

Copy link
Copy Markdown
Contributor

Aliases for literal values are currently copied into columns_dict even though they have no source column:

Parser("SELECT 1 AS label, actual FROM data").columns
# ["actual"]

Parser("SELECT 1 AS label, actual FROM data").columns_dict
# before: {"select": ["actual", "label"]}
# after:  {"select": ["actual"]}

columns_dict now skips aliases whose AST source is a basic number, string, NULL, or boolean literal and which have no real column mapping. Aliases backed by real columns continue to resolve to those columns even when a nested query reuses the same alias name, and scalar subquery aliases retain their existing behavior.

Tests

  • Added regression coverage for numeric, string, NULL, and boolean literal aliases, plus a nested same-name alias scope case.
  • Full suite: 293 passed, 100% coverage.
  • Ruff: passed for sql_metadata.
  • Mypy: passed for sql_metadata.

@mmporong
mmporong force-pushed the fix/literal-alias-columns-dict branch from 44bfc6a to 3e954dd Compare November 4, 2026 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant