Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 12, 2025

This PR adds support for parsing SHOW and DESC/DESCRIBE statements in the ClickHouse SQL parser, resolving the "unexpected token" errors when using these common database commands.

Problem

The parser was throwing "unexpected token" errors for valid ClickHouse SQL statements like:

SHOW CREATE TABLE `rs-package-hub`
DESC `rs-package-hub`

This was because the parseStmt function didn't include cases for the SHOW and DESC keywords, despite these keywords being defined in the lexer.

Solution

Added comprehensive support for SHOW and DESC/DESCRIBE statements by:

  1. Created new AST node types:

    • ShowStmt - handles various SHOW commands
    • DescribeStmt - handles DESC/DESCRIBE table commands
  2. Extended the visitor pattern:

    • Added VisitShowExpr and VisitDescribeExpr methods to the ASTVisitor interface
    • Implemented default visitor methods
  3. Added parsing logic:

    • parseShowStmt - supports SHOW CREATE TABLE, SHOW DATABASES, SHOW TABLES
    • parseDescribeStmt - supports both DESC and DESCRIBE keywords
    • Added cases to the main parseStmt function

Features Supported

  • SHOW CREATE TABLE table_name - Shows CREATE TABLE statement
  • SHOW DATABASES - Lists databases
  • SHOW TABLES - Lists tables
  • DESC table_name - Describes table structure
  • DESCRIBE table_name - Describes table structure (synonym for DESC)
  • Qualified table names (database.table)
  • Quoted identifiers with backticks

Testing

Added comprehensive test cases covering all supported statement types and edge cases. All existing tests continue to pass, ensuring no regressions were introduced.

Example usage:

./clickhouse-sql-parser "SHOW CREATE TABLE my_table"
./clickhouse-sql-parser "DESC `table-with-dashes`"  
./clickhouse-sql-parser -format "SHOW DATABASES"

Fixes #179.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copy link
Contributor Author

Copilot AI commented Aug 12, 2025

@git-hulk 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

@coveralls
Copy link

coveralls commented Aug 12, 2025

Pull Request Test Coverage Report for Build 16897702829

Details

  • 73 of 128 (57.03%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.07%) to 50.259%

Changes Missing Coverage Covered Lines Changed/Added Lines %
parser/walk.go 4 8 50.0%
parser/ast_visitor.go 0 10 0.0%
parser/parser_table.go 54 66 81.82%
parser/ast.go 15 44 34.09%
Totals Coverage Status
Change from base Build 16875624131: 0.07%
Covered Lines: 7278
Relevant Lines: 14481

💛 - Coveralls

@Copilot Copilot AI changed the title [WIP] can not know desc or show command Add support for SHOW and DESC/DESCRIBE statements Aug 12, 2025
@Copilot Copilot AI requested a review from git-hulk August 12, 2025 02:29
Copilot finished work on behalf of git-hulk August 12, 2025 02:29
@git-hulk
Copy link
Member

@copilot Fix the lint error.

Copy link
Contributor Author

Copilot AI commented Aug 12, 2025

@copilot Fix the lint error.

Fixed the lint error. The issue was an ineffectual assignment to the statementEnd variable in the parseShowStmt function - it was being assigned to pos but then immediately overwritten in the conditional block. Removed the unnecessary initial assignment. (42f91be)

Copilot finished work on behalf of git-hulk August 12, 2025 02:41
@git-hulk git-hulk marked this pull request as ready for review August 12, 2025 02:46
@git-hulk git-hulk marked this pull request as draft August 12, 2025 02:47
@git-hulk
Copy link
Member

@copilot Please add the new expr into Walk funciton.

Copy link
Contributor Author

Copilot AI commented Aug 12, 2025

@copilot Please add the new expr into Walk funciton.

Added ShowStmt and DescribeStmt cases to the Walk function. The Walk function now properly traverses these new AST node types and their child nodes (Target field). (337f210)

Copilot finished work on behalf of git-hulk August 12, 2025 02:57
@git-hulk git-hulk marked this pull request as ready for review August 12, 2025 03:17
@git-hulk git-hulk merged commit 17e7864 into master Aug 12, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SHOW/DESC syntax is not supported
3 participants