Fix: alias after a multi-word expression is ignored#32
Conversation
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.
|
Warning Review limit reached
Next review available in: 41 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Fixes #18.
What
ParseColumnEntrymatched a column entry against`${Expression} ${Middle} ${Alias}`, which splits at the first two spaces. Forprice * 2 as totalthat bindsExpression="price",Middle="*", seesMiddleisn'tas, and gives up - the whole entry becomes the raw column key instead oftotal.Fix
Replaced the fixed-position split with
FindTopLevelAsKeyword, a paren-depth-aware word scan (reuses theApplyParenDeltacounter already used elsewhere inparse.ts) that finds the top-levelas, socast(price as int) as pisn't confused by theasinside 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). Updatedtests/paren-boundary.test-d.tsto lock the corrected key instead of the old fallback.Single-word aliases, function-call aliases (
count(*) as total), and bare no-ASaliases (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/53tests/multiword-alias.test-d.ts: multi-word arithmetic alias, cast-with-as-inside not confused, and three unchanged-behavior regression lockstests/paren-boundary.test-d.ts'sextract()case to the corrected key