fix: keep spaces around - operator in dialects with dashed identifiers#953
Conversation
In BigQuery (and any dialect allowing dashes inside identifiers) the denseOperators option turned "a - b" into "a-b", which then re-parses as a single dashed identifier - corrupting the query. Skip densing the "-" operator for those dialects so the output round-trips.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThe PR adds support for dialect-specific handling of the minus operator to prevent accidental merging of ChangesIdentifier dashes operator spacing
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install timed out. The project may have too many dependencies for the sandbox. 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 |
With
denseOperators: trueon BigQuery, a subtraction likea - bcomes out asa-b. That's not just ugly: BigQuery allows dashes inside identifiers, so the densed output re-parses as a single identifiera-b, andformat(format(sql))no longer matchesformat(sql).a - foo(y)is worse — it becomesa-foo (y), turning the expression into an identifier followed by a call.The fix is to leave the
-operator spaced in dialects that allow dashed identifiers (currently just BigQuery). I derived that flag from the existingidentChars.dashestokenizer option so there's a single source of truth. Numeric cases like1 - 2were already safe (the-is parsed into the literal), so this only affects the identifier case.The shared dense-operator test in
operators.tswas actually asserting the brokenfoo-baroutput for BigQuery; I scoped that to the dashed-identifier dialects and added a BigQuery regression test.Summary by CodeRabbit
Release Notes
-operator in dialects that support dashes in identifiers, such as BigQuery. When dense operator formatting is enabled, spaces around the-operator are now properly preserved to prevent expressions from being incorrectly merged into dashed identifiers.