Skip to content

Fix: alias after a multi-word expression is ignored#32

Merged
tiagolauer merged 1 commit into
masterfrom
fix-multiword-alias
Jul 19, 2026
Merged

Fix: alias after a multi-word expression is ignored#32
tiagolauer merged 1 commit into
masterfrom
fix-multiword-alias

Conversation

@tiagolauer

Copy link
Copy Markdown
Owner

Fixes #18.

What

ParseColumnEntry matched a column entry against `${Expression} ${Middle} ${Alias}`, which splits at the first two spaces. For price * 2 as total that binds Expression="price", Middle="*", sees Middle isn't as, and gives up - the whole entry becomes the raw column key instead of total.

Fix

Replaced the fixed-position split with FindTopLevelAsKeyword, a paren-depth-aware word scan (reuses the ApplyParenDelta counter already used elsewhere in parse.ts) that finds the top-level as, so cast(price as int) as p isn't confused by the as inside the cast.

Bonus fix

As a side effect this also fixes the alias for extract(year from created_at) as y - previously fell back to the raw entry text as its key, called out as a known non-goal in #17's PR (#27). Updated tests/paren-boundary.test-d.ts to lock the corrected key instead of the old fallback.

Single-word aliases, function-call aliases (count(*) as total), and bare no-AS aliases (price total) are unchanged - all three still resolve through their existing paths, locked by new regression tests.

Test plan

  • npm test (types + runtime) green, 53/53
  • New tests/multiword-alias.test-d.ts: multi-word arithmetic alias, cast-with-as-inside not confused, and three unchanged-behavior regression locks
  • Updated tests/paren-boundary.test-d.ts's extract() case to the corrected key

ParseColumnEntry matched a column entry against
`${Expression} ${Middle} ${Alias}`, which splits at the first two
spaces. For "price * 2 as total" that binds Expression="price",
Middle="*", sees Middle isn't "as", and gives up - the whole entry
becomes the column key instead of "total".

Replaced that fixed-position split with FindTopLevelAsKeyword, a
paren-depth-aware word scan (same ApplyParenDelta counter used
elsewhere in this file) that finds the last top-level "as", so
"cast(price as int) as p" isn't confused by the "as" inside the cast.

As a side effect this also fixes the alias for
"extract(year from created_at) as y" (previously fell back to the
raw entry text as its key, called out as a known non-goal in #17's
PR) - updated tests/paren-boundary.test-d.ts to lock the corrected
key instead of the old fallback.

Single-word aliases, function-call aliases, and bare (no-AS)
aliases are unchanged - all three still resolve through their
existing paths.
@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@tiagolauer, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 41 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 741c00d4-9114-4925-b57f-90c9c9ee7de2

📥 Commits

Reviewing files that changed from the base of the PR and between c6207f8 and 45b58da.

📒 Files selected for processing (3)
  • src/parse.ts
  • tests/multiword-alias.test-d.ts
  • tests/paren-boundary.test-d.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-multiword-alias

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@tiagolauer
tiagolauer merged commit 37dbe76 into master Jul 19, 2026
4 of 6 checks passed
@tiagolauer
tiagolauer deleted the fix-multiword-alias branch July 19, 2026 05:38
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.

Alias after a multi-word expression is ignored (select price * 2 as total)

1 participant