Skip to content

Fix explicit AS aliases for current date and time scalars - #939

Open
LJimmy007 wants to merge 1 commit into
andialbrecht:masterfrom
LJimmy007:fix-current-date-as-alias-550
Open

LJimmy007 wants to merge 1 commit into
andialbrecht:masterfrom
LJimmy007:fix-current-date-as-alias-550

Conversation

@LJimmy007

Copy link
Copy Markdown

Fixes #550.

With reindent=True, a date scalar with an explicit alias splits the SELECT
projection list. For example,
SELECT 'value 1' AS VALUE_1, CURRENT_DATE AS CREATED_AT, 'testing' AS VALUE_2, 'testing2' AS VALUE_3 FROM TABLE_1
indents the last two columns by 23 spaces instead of 7.

Allow CURRENT_DATE, CURRENT_TIME, and CURRENT_TIMESTAMP in the existing
explicit-AS grouping rule, alongside NULL. This keeps each scalar with its
alias, restores column alignment, and makes get_alias() return CREATED_AT.
Other keyword handling and implicit aliases are unchanged.

Tests cover all three scalars in upper/lower/mixed case, ordinary-column and
NULL controls, exact parsing round trips including whitespace, projection
boundaries, alias discovery, and repeated formatting. The reported trailing
comma is covered separately for preservation; the main regression uses valid SQL.

Validation on Windows / Python 3.11.17:

  • The same 25 regression/control cases: 19 failed, 6 passed on the original
    implementation; all 25 pass with this change.
  • uv run --group dev --python 3.11 pytest tests/test_grouping.py tests/test_format.py:
    190 passed, 2 xfailed.
  • uv run --group dev --python 3.11 pytest tests/:
    531 passed, 2 xfailed, 1 xpassed. The xfail/xpass outcomes match unchanged
    upstream (506 passed, 2 xfailed, 1 xpassed).
  • uv run --group dev ruff check sqlparse/ and git diff --check pass.

Developed with AI assistance and independently reviewed by another agent, which
also reran the checks above. Other Python versions/platforms were not tested
locally for the complete suite.

  • ran the tests (pytest)
  • all style issues addressed (ruff)
  • changes covered by tests
  • changelog updated

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.

Formatting After Function Column Fill Does Not Align

2 participants