feat(transform): dialect-aware SQL formatting#507
Conversation
Add dialect-aware formatting to the transform and formatter packages so that AST-to-SQL rendering respects dialect-specific row-limiting syntax: SQL Server emits TOP, Oracle emits FETCH FIRST, and LIMIT-based dialects remain unchanged. Key changes: - Add Dialect field to FormatOptions and formatter.Options - Render parsed TopClause (previously silently dropped) - normalizeSelectForDialect converts LIMIT to TOP/FETCH on a shallow copy - SQL Server with OFFSET uses OFFSET/FETCH NEXT syntax - Add FormatSQLWithDialect(stmt, keywords.SQLDialect) to transform pkg - Add ParseSQLWithDialect(sql, keywords.SQLDialect) to transform pkg - Thread nodeFormatter through fetchSQL for keyword casing Closes #479 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Claude finished @ajitpratap0's task —— View job Code Review CompleteI've completed a comprehensive review of this dialect-aware SQL formatting PR. Overall, this is a well-implemented feature that cleanly adds dialect-specific formatting support to the transform and formatter packages. Review Tasks
SummaryThis PR successfully implements dialect-aware SQL formatting with clean architecture, comprehensive testing, and good performance characteristics. The implementation correctly handles the dialect mapping requirements and maintains AST immutability. Code Quality ✅Architecture & Design:
Code Style & Conventions:
Performance Considerations ✅Memory Management:
Runtime Efficiency:
Security ✅Input Validation:
Test Coverage ✅ (Excellent)Comprehensive Test Suite:
Edge Case Coverage:
Issues Found 🔍Minor Issues:
Recommendations 💡Code Improvements:
Future Enhancements:
Specific Code Reviewpkg/transform/transform.go:242-246 ✅
pkg/formatter/render.go:336-378 ✅
pkg/formatter/render.go:228-242 ✅
Test Coverage ✅
Final AssessmentThis is a high-quality implementation that:
Recommendation: APPROVE 🚀 The implementation is production-ready and addresses the issue requirements comprehensively. The minor suggestions above are enhancements rather than blocking issues. |
Summary
TOP N, Oracle emitsFETCH FIRST N ROWS ONLY, PostgreSQL/MySQL/etc. keepLIMIT NTopClausewas silently dropped during formattingChanges
New APIs
transform.FormatSQLWithDialect(stmt, keywords.SQLDialect)- format with dialect-specific syntaxtransform.ParseSQLWithDialect(sql, keywords.SQLDialect)- parse with dialect-aware tokenizer/parserFormatter
FormatOptions.Dialectfield threads dialect through the rendering pipelinenormalizeSelectForDialect()convertsLIMIT/OFFSETtoTOPorFETCHon a shallow copy (original AST not mutated)fetchSQL()now respects keyword casing vianodeFormatterrenderSelect()now rendersTopClause(previously silently dropped)Dialect LIMIT Mapping
LIMIT nLIMIT n OFFSET mTOP nTOP nOFFSET 0 ROWS FETCH NEXT n ROWS ONLYOFFSET m ROWS FETCH NEXT n ROWS ONLYFETCH FIRST n ROWS ONLYOFFSET m ROWS FETCH FIRST n ROWS ONLYExample (from issue)
Test plan
-race: all packages pass, zero regressionsgo vetandgofmtcleanCloses #479
🤖 Generated with Claude Code