Skip to content

feat(parser): Snowflake USE/DESCRIBE top-level statements (#483)#491

Merged
ajitpratap0 merged 3 commits intomainfrom
feat/snowflake-top-level-stmts-483
Apr 8, 2026
Merged

feat(parser): Snowflake USE/DESCRIBE top-level statements (#483)#491
ajitpratap0 merged 3 commits intomainfrom
feat/snowflake-top-level-stmts-483

Conversation

@ajitpratap0
Copy link
Copy Markdown
Owner

Summary

Three top-level statement gaps from the Snowflake QA sweep (#483).

  • `USE [WAREHOUSE|DATABASE|SCHEMA|ROLE] ` — Snowflake session-context switches. USE tokenizes as an identifier (no keyword type), so detected by value in the identifier branch of the statement dispatcher. Parse-only; stashed in a DescribeStatement placeholder until a dedicated node is introduced.
  • `DESCRIBE TABLE|VIEW|DATABASE|SCHEMA|STAGE|STREAM|TASK|PIPE|FUNCTION|PROCEDURE|WAREHOUSE ` — extends `parseDescribeStatement` to consume an optional object-kind keyword before the name. Previously `DESCRIBE TABLE users` failed at `users`.
  • `DESC` is now a DESCRIBE synonym at statement position. It has its own token type (`TokenTypeDesc`) because it is also the ORDER BY sort-direction keyword.

Test plan

  • `TestSnowflakeUseAndDescribe`: 11 shapes — all USE variants, DESCRIBE with object kinds, DESC synonym
  • `go test -race ./pkg/sql/parser/ ./pkg/sql/ast/ ./pkg/gosqlx/` green
  • No regression to ORDER BY … DESC (still parses via the expression path)

Out of scope

  • Dedicated `UseStatement` AST node (placeholder reuses DescribeStatement for now)
  • `CREATE STAGE/FILE FORMAT/STREAM/TASK/PIPE` — separate PR
  • `COPY INTO` / `PUT` / `GET` / `LIST` — separate PR

Part of #483.

🤖 Generated with Claude Code

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 8, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
gosqlx-website Ready Ready Preview, Comment Apr 8, 2026 7:31am

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

Claude finished @ajitpratap0's task —— View job


Code Review: Snowflake USE/DESCRIBE Statements

Todo List

  • Read and analyze changed files
  • Review parser.go changes for USE/DESCRIBE logic
  • Review mysql.go changes (unusual for Snowflake feature)
  • Review test coverage and quality
  • Check for adherence to project patterns
  • Provide comprehensive feedback

Overall Assessment: Good Implementation

This PR successfully implements Snowflake USE and enhanced DESCRIBE statements with clean code and good test coverage.

Strengths

🏗️ Architecture & Design

  • Smart token handling: DESC gets separate TokenTypeDesc to avoid conflicts with ORDER BY DESC
  • Correct dialect scoping: USE statement parsing only enabled for Snowflake dialect
  • Reasonable placeholder approach: Using DescribeStatement as temporary container until dedicated UseStatement node is added

🔧 Code Quality

  • Consistent patterns: Follows project conventions with p.advance(), error handling
  • Good error messages: p.expectedError("name after USE") provides clear context
  • Proper case handling: Uses strings.EqualFold() for case-insensitive keyword matching

🧪 Test Coverage

  • Comprehensive test cases: 11 scenarios covering all USE variants and DESCRIBE enhancements
  • Good test structure: Uses table-driven tests with gosqlx.ParseWithDialect()
  • Dialect-specific testing: Correctly tests with keywords.DialectSnowflake

Issues & Recommendations

⚠️ Architecture Concerns

1. Placeholder Anti-pattern (parser.go:1027)

stmt := ast.GetDescribeStatement()
stmt.TableName = "USE " + name

Issue: Storing USE statements in DescribeStatement with string prefix is a code smell
Recommendation: Consider adding a TODO comment or issue to track creating proper UseStatement AST node

2. File Organization (mysql.go:148-191)
Issue: parseDescribeStatement() in mysql.go handles Snowflake-specific object kinds
Recommendation: Consider moving Snowflake-specific parsing logic to dedicated file or make function dialect-agnostic in main parser

🔍 Minor Issues

3. Inconsistent Comments (parser.go:1013-1014)

// USE is not tokenized as a keyword; dispatch by value in the Snowflake dialect.

Clarification needed: Why isn't USE tokenized as keyword? Document this design decision.

4. Magic String Construction (parser.go:1027)

stmt.TableName = "USE " + name

Risk: String concatenation could cause parsing issues if name contains special characters
Suggestion: Consider using structured representation or validation

Security & Performance

✅ Security

  • No SQL injection risks (proper parsing, no dynamic query construction)
  • Appropriate input validation via parseQualifiedName()

✅ Performance

  • Uses object pooling: ast.GetDescribeStatement() (proper pattern)
  • Minimal performance impact: Simple string operations and early dialect check

Test Coverage Assessment

✅ Good Coverage

  • All USE statement variants: USE WAREHOUSE, USE DATABASE, USE SCHEMA, USE ROLE
  • Enhanced DESCRIBE: DESCRIBE TABLE, DESCRIBE VIEW, DESCRIBE STAGE
  • DESC synonym: DESC TABLE users, DESC users

🔄 Potential Test Gaps

Consider adding tests for:

  • Error cases: USE without name, invalid object kinds
  • Edge cases: Quoted names, schema-qualified names
  • Regression: ORDER BY DESC still works (mentioned in PR but not tested)

Recommendations

  1. Add TODO comment for USE statement AST node
  2. Consider file reorganization for Snowflake-specific logic
  3. Add error case tests for robustness
  4. Document USE keyword decision in code comments

✅ Approval Recommendation

This is a solid implementation that follows project patterns and adds useful Snowflake functionality. The placeholder approach is reasonable for MVP, and test coverage is good. Minor organizational improvements suggested but no blocking issues.


Job Run

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

Claude finished @ajitpratap0's task —— View job


Code Review: Snowflake USE/DESCRIBE Statements

Todo List

  • Read and analyze changed files
  • Review parser.go changes for USE/DESCRIBE logic
  • Review mysql.go changes (unusual for Snowflake feature)
  • Review test coverage and quality
  • Check for adherence to project patterns
  • Provide comprehensive feedback

Overall Assessment: Good Implementation

This PR successfully implements Snowflake USE and enhanced DESCRIBE statements with clean code and good test coverage.

Strengths

🏗️ Architecture & Design

  • Smart token handling: DESC gets separate TokenTypeDesc to avoid conflicts with ORDER BY DESC
  • Correct dialect scoping: USE statement parsing only enabled for Snowflake dialect
  • Reasonable placeholder approach: Using DescribeStatement as temporary container until dedicated UseStatement node is added

🔧 Code Quality

  • Consistent patterns: Follows project conventions with p.advance(), error handling
  • Good error messages: p.expectedError("name after USE") provides clear context
  • Proper case handling: Uses strings.EqualFold() for case-insensitive keyword matching

🧪 Test Coverage

  • Comprehensive test cases: 11 scenarios covering all USE variants and DESCRIBE enhancements
  • Good test structure: Uses table-driven tests with gosqlx.ParseWithDialect()
  • Dialect-specific testing: Correctly tests with keywords.DialectSnowflake

Issues & Recommendations

⚠️ Architecture Concerns

1. Placeholder Anti-pattern (parser.go:1027)

stmt := ast.GetDescribeStatement()
stmt.TableName = "USE " + name

Issue: Storing USE statements in DescribeStatement with string prefix is a code smell
Recommendation: Consider adding a TODO comment or issue to track creating proper UseStatement AST node

2. File Organization (mysql.go:148-191)
Issue: parseDescribeStatement() in mysql.go handles Snowflake-specific object kinds
Recommendation: Consider moving Snowflake-specific parsing logic to dedicated file or make function dialect-agnostic in main parser

🔍 Minor Issues

3. Inconsistent Comments (parser.go:1013-1014)

// USE is not tokenized as a keyword; dispatch by value in the Snowflake dialect.

Clarification needed: Why isn't USE tokenized as keyword? Document this design decision.

4. Magic String Construction (parser.go:1027)

stmt.TableName = "USE " + name

Risk: String concatenation could cause parsing issues if name contains special characters
Suggestion: Consider using structured representation or validation

Security & Performance

✅ Security

  • No SQL injection risks (proper parsing, no dynamic query construction)
  • Appropriate input validation via parseQualifiedName()

✅ Performance

  • Uses object pooling: ast.GetDescribeStatement() (proper pattern)
  • Minimal performance impact: Simple string operations and early dialect check

Test Coverage Assessment

✅ Good Coverage

  • All USE statement variants: USE WAREHOUSE, USE DATABASE, USE SCHEMA, USE ROLE
  • Enhanced DESCRIBE: DESCRIBE TABLE, DESCRIBE VIEW, DESCRIBE STAGE
  • DESC synonym: DESC TABLE users, DESC users

🔄 Potential Test Gaps

Consider adding tests for:

  • Error cases: USE without name, invalid object kinds
  • Edge cases: Quoted names, schema-qualified names
  • Regression: ORDER BY DESC still works (mentioned in PR but not tested)

Recommendations

  1. Add TODO comment for USE statement AST node
  2. Consider file reorganization for Snowflake-specific logic
  3. Add error case tests for robustness
  4. Document USE keyword decision in code comments

✅ Approval Recommendation

This is a solid implementation that follows project patterns and adds useful Snowflake functionality. The placeholder approach is reasonable for MVP, and test coverage is good. Minor organizational improvements suggested but no blocking issues.


@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

Claude finished @ajitpratap0's task —— View job


Code Review: Snowflake USE/DESCRIBE Statements

Todo List

  • Read and analyze changed files
  • Review parser.go changes for USE/DESCRIBE logic
  • Review mysql.go changes (unusual for Snowflake feature)
  • Review test coverage and quality
  • Check for adherence to project patterns
  • Provide comprehensive feedback

Overall Assessment: Good Implementation

This PR successfully implements Snowflake USE and enhanced DESCRIBE statements with clean code and good test coverage.

Strengths

🏗️ Architecture & Design

  • Smart token handling: DESC gets separate TokenTypeDesc to avoid conflicts with ORDER BY DESC
  • Correct dialect scoping: USE statement parsing only enabled for Snowflake dialect
  • Reasonable placeholder approach: Using DescribeStatement as temporary container until dedicated UseStatement node is added

🔧 Code Quality

  • Consistent patterns: Follows project conventions with p.advance(), error handling
  • Good error messages: p.expectedError("name after USE") provides clear context
  • Proper case handling: Uses strings.EqualFold() for case-insensitive keyword matching

🧪 Test Coverage

  • Comprehensive test cases: 11 scenarios covering all USE variants and DESCRIBE enhancements
  • Good test structure: Uses table-driven tests with gosqlx.ParseWithDialect()
  • Dialect-specific testing: Correctly tests with keywords.DialectSnowflake

Issues & Recommendations

⚠️ Architecture Concerns

1. Placeholder Anti-pattern (parser.go:1027)

stmt := ast.GetDescribeStatement()
stmt.TableName = "USE " + name

Issue: Storing USE statements in DescribeStatement with string prefix is a code smell
Recommendation: Consider adding a TODO comment or issue to track creating proper UseStatement AST node

2. File Organization (mysql.go:148-191)
Issue: parseDescribeStatement() in mysql.go handles Snowflake-specific object kinds
Recommendation: Consider moving Snowflake-specific parsing logic to dedicated file or make function dialect-agnostic in main parser

🔍 Minor Issues

3. Inconsistent Comments (parser.go:1013-1014)

// USE is not tokenized as a keyword; dispatch by value in the Snowflake dialect.

Clarification needed: Why isn't USE tokenized as keyword? Document this design decision.

4. Magic String Construction (parser.go:1027)

stmt.TableName = "USE " + name

Risk: String concatenation could cause parsing issues if name contains special characters
Suggestion: Consider using structured representation or validation

Security & Performance

✅ Security

  • No SQL injection risks (proper parsing, no dynamic query construction)
  • Appropriate input validation via parseQualifiedName()

✅ Performance

  • Uses object pooling: ast.GetDescribeStatement() (proper pattern)
  • Minimal performance impact: Simple string operations and early dialect check

Test Coverage Assessment

✅ Good Coverage

  • All USE statement variants: USE WAREHOUSE, USE DATABASE, USE SCHEMA, USE ROLE
  • Enhanced DESCRIBE: DESCRIBE TABLE, DESCRIBE VIEW, DESCRIBE STAGE
  • DESC synonym: DESC TABLE users, DESC users

🔄 Potential Test Gaps

Consider adding tests for:

  • Error cases: USE without name, invalid object kinds
  • Edge cases: Quoted names, schema-qualified names
  • Regression: ORDER BY DESC still works (mentioned in PR but not tested)

Recommendations

  1. Add TODO comment for USE statement AST node
  2. Consider file reorganization for Snowflake-specific logic
  3. Add error case tests for robustness
  4. Document USE keyword decision in code comments

✅ Approval Recommendation

This is a solid implementation that follows project patterns and adds useful Snowflake functionality. The placeholder approach is reasonable for MVP, and test coverage is good. Minor organizational improvements suggested but no blocking issues.


Job Run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant