-
Notifications
You must be signed in to change notification settings - Fork 5
feat: Parser enhancements batch 2 - Column constraints, derived tables, aliases & CLI output #163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…, #158, #160) - Add AliasedExpression AST type to preserve AS keyword in column aliases (#160) - Support derived tables (subqueries) in FROM and JOIN clauses (#148) - Enable function calls and expressions in INSERT VALUES clause (#158) Changes: - ast.go: Added AliasedExpression type and extended TableReference with Subquery field - select.go: Updated column alias parsing and added derived table support in FROM/JOIN - dml.go: Changed VALUES parsing to use parseExpression() for full expression support - sql_formatter.go: Added formatting support for AliasedExpression and derived tables - extract.go: Added AliasedExpression handling to all collectors 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Add comprehensive support for column and table constraints in CREATE TABLE: Column constraints: - PRIMARY KEY - NOT NULL / NULL - UNIQUE - DEFAULT (literal, function call, or expression) - CHECK (expression) - REFERENCES table(column) - inline foreign key - AUTO_INCREMENT Table-level constraints: - PRIMARY KEY (column_list) - FOREIGN KEY (column_list) REFERENCES table(column_list) - UNIQUE (column_list) - CHECK (expression) - CONSTRAINT name prefix for named constraints Also supports parameterized data types: VARCHAR(100), DECIMAL(10,2), etc. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
) The -o/--output flag was accepted but not functional. Now both lint and analyze commands properly write output to the specified file. Changes: - analyze.go: Capture output to buffer when outputFile is specified, then write to file using WriteOutput helper - lint.go: Same approach for lint command, supporting both file and stdin input The WriteOutput helper (already in stdin_utils.go) handles the file writing with proper permissions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
Claude finished @ajitpratap0's task —— View job Code Review SummaryI've completed a comprehensive review of PR #163. Here's my detailed analysis: ✅ Strengths1. AST Design Excellence
2. Parser Implementation Quality
3. CLI Implementation
|
Addresses code review feedback from PR #163: ## Object Pooling - Add `aliasedExprPool` sync.Pool for AliasedExpression - Add `GetAliasedExpression()` and `PutAliasedExpression()` functions - Integrate AliasedExpression into `PutExpression()` cleanup ## Formatter Improvements - Add `formatIdentifier()` to quote identifiers with special chars - Add `needsQuoting()` to detect reserved words and special characters - Fix column constraint formatting to include DEFAULT values, CHECK expressions, and REFERENCES with ON DELETE/UPDATE ## Error Context - Improve error messages in VALUES parsing with position info ## Test Coverage - Add TestDerivedTables_Comprehensive (6 test cases) - Add TestColumnConstraints_REFERENCES (6 test cases) - Add TestColumnConstraints_CHECK (3 test cases) - Add TestInsertWithFunctionCalls (7 test cases) - Add TestAliasedExpressions (5 test cases) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
PR Review Feedback Addressed ✅I've addressed all the feedback from the code review in commit 1. Object Pooling for AliasedExpression ✅
2. AliasedExpression Formatting with Quoted Identifiers ✅
3. Column Constraint Formatting ✅
4. Improved Error Context ✅
5. Comprehensive Test Coverage ✅Added 27 new test cases:
Note on AS Keyword for Derived TablesThe AS keyword in derived tables is kept as-is since it's SQL standard compliant. Most major databases (PostgreSQL, MySQL 8+, SQL Server) accept both with and without AS, but having it explicit improves readability and portability. All tests pass with race detection. 🎉 |
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
|
Claude finished @ajitpratap0's task —— View job ✅ Comprehensive PR Review CompleteI've thoroughly reviewed PR #163 implementing parser enhancements batch 2. Here's my detailed assessment: ✅ Outstanding Work on Previous FeedbackAll claimed fixes from the previous review have been perfectly implemented:
🔍 Code Quality AssessmentExcellent Strengths:1. AST Design & Architecture ⭐⭐⭐⭐⭐
2. Parser Implementation Quality ⭐⭐⭐⭐⭐
3. CLI Output Implementation ⭐⭐⭐⭐⭐
4. Formatting & Style ⭐⭐⭐⭐⭐
5. Test Coverage ⭐⭐⭐⭐⭐
|
Summary
This PR implements the second batch of parser enhancements and CLI improvements, addressing 5 issues:
Key Changes
1. Column Aliases with AS Keyword (#160)
AliasedExpressionAST type to preserve theASkeywordAliasedExpressionexpr AS aliasinstead of justexpr alias2. Function Calls in INSERT VALUES (#158)
parseExpression()NOW(),UUID(),CONCAT(), arithmetic expressions, etc.INSERT INTO t (created) VALUES (NOW(), 100 + 50 * 2)3. Derived Tables / Subqueries in FROM (#148)
TableReferencewithSubquery *SelectStatementfield(SELECT ...) AS aliasin FROM and JOIN clauses4. CREATE TABLE with Column Constraints (#146)
5. Output File Flag for lint/analyze (#156)
-o/--outputflag was defined but not implementedFiles Changed
pkg/sql/ast/ast.goAliasedExpression, extendedTableReference.Subquerypkg/sql/parser/select.gopkg/sql/parser/dml.gocmd/gosqlx/cmd/analyze.gocmd/gosqlx/cmd/lint.gocmd/gosqlx/cmd/sql_formatter.gopkg/gosqlx/extract.gopkg/lsp/handler_test.goTest Plan
go test -race ./...)gosqlx lint -o output.txtwrites to filegosqlx analyze -o output.json -f jsonwrites to filego vetpassesExample Usage
Closes
Closes #160, #158, #148, #146, #156
🤖 Generated with Claude Code