Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,12 +623,13 @@ func (a *AttachQuery) statementNode() {}

// DescribeQuery represents a DESCRIBE statement.
type DescribeQuery struct {
Position token.Position `json:"-"`
Database string `json:"database,omitempty"`
Table string `json:"table,omitempty"`
TableFunction *FunctionCall `json:"table_function,omitempty"`
Settings []*SettingExpr `json:"settings,omitempty"`
Format string `json:"format,omitempty"`
Position token.Position `json:"-"`
Database string `json:"database,omitempty"`
Table string `json:"table,omitempty"`
TableFunction *FunctionCall `json:"table_function,omitempty"`
TableExpr *TableExpression `json:"table_expr,omitempty"` // For DESCRIBE (SELECT ...)
Settings []*SettingExpr `json:"settings,omitempty"`
Format string `json:"format,omitempty"`
}

func (d *DescribeQuery) Pos() token.Position { return d.Position }
Expand Down
2 changes: 1 addition & 1 deletion internal/explain/explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func Node(sb *strings.Builder, node interface{}, depth int) {
case *ast.UseQuery:
explainUseQuery(sb, n, indent)
case *ast.DescribeQuery:
explainDescribeQuery(sb, n, indent)
explainDescribeQuery(sb, n, indent, depth)
case *ast.ExistsQuery:
explainExistsTableQuery(sb, n, indent)
case *ast.DetachQuery:
Expand Down
15 changes: 13 additions & 2 deletions internal/explain/statements.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,19 @@ func explainUseQuery(sb *strings.Builder, n *ast.UseQuery, indent string) {
fmt.Fprintf(sb, "%s Identifier %s\n", indent, n.Database)
}

func explainDescribeQuery(sb *strings.Builder, n *ast.DescribeQuery, indent string) {
if n.TableFunction != nil {
func explainDescribeQuery(sb *strings.Builder, n *ast.DescribeQuery, indent string, depth int) {
if n.TableExpr != nil {
// DESCRIBE on a subquery - TableExpr contains a TableExpression with a Subquery
children := 1
if len(n.Settings) > 0 {
children++
}
fmt.Fprintf(sb, "%sDescribeQuery (children %d)\n", indent, children)
Node(sb, n.TableExpr, depth+1)
if len(n.Settings) > 0 {
fmt.Fprintf(sb, "%s Set\n", indent)
}
} else if n.TableFunction != nil {
// DESCRIBE on a table function - wrap in TableExpression
children := 1
if len(n.Settings) > 0 {
Expand Down
9 changes: 6 additions & 3 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -3253,9 +3253,12 @@ func (p *Parser) parseDescribe() *ast.DescribeQuery {
p.nextToken()
}

// Parse table name or table function
// Table functions look like: format(CSV, '...'), url('...'), s3Cluster(...)
if p.currentIs(token.IDENT) || p.current.Token.IsKeyword() {
// Check for subquery: DESCRIBE (SELECT ...)
if p.currentIs(token.LPAREN) {
desc.TableExpr = p.parseTableExpression()
} else if p.currentIs(token.IDENT) || p.current.Token.IsKeyword() {
// Parse table name or table function
// Table functions look like: format(CSV, '...'), url('...'), s3Cluster(...)
pos := p.current.Pos
tableName := p.current.Value
p.nextToken()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
{
"explain_todo": {
"stmt12": true,
"stmt14": true,
"stmt16": true
}
}
{}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"explain_todo": {
"stmt4": true,
"stmt7": true
"stmt4": true
}
}
8 changes: 1 addition & 7 deletions parser/testdata/01937_nested_chinese/metadata.json
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
{
"explain_todo": {
"stmt3": true,
"stmt4": true,
"stmt5": true
}
}
{}
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
{
"explain_todo": {
"stmt2": true
}
}
{}
15 changes: 1 addition & 14 deletions parser/testdata/02337_analyzer_columns_basic/metadata.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
{
"explain_todo": {
"stmt17": true,
"stmt20": true,
"stmt23": true,
"stmt26": true,
"stmt29": true,
"stmt3": true,
"stmt32": true,
"stmt35": true,
"stmt42": true,
"stmt43": true,
"stmt45": true,
"stmt48": true,
"stmt51": true,
"stmt6": true,
"stmt9": true
"stmt43": true
}
}
14 changes: 1 addition & 13 deletions parser/testdata/02338_analyzer_constants_basic/metadata.json
Original file line number Diff line number Diff line change
@@ -1,13 +1 @@
{
"explain_todo": {
"stmt11": true,
"stmt14": true,
"stmt17": true,
"stmt2": true,
"stmt20": true,
"stmt23": true,
"stmt25": true,
"stmt5": true,
"stmt8": true
}
}
{}
10 changes: 0 additions & 10 deletions parser/testdata/02339_analyzer_matcher_basic/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@
"stmt103": true,
"stmt105": true,
"stmt106": true,
"stmt15": true,
"stmt18": true,
"stmt19": true,
"stmt21": true,
"stmt22": true,
"stmt24": true,
"stmt27": true,
"stmt3": true,
"stmt30": true,
"stmt31": true,
"stmt33": true,
Expand All @@ -20,7 +16,6 @@
"stmt37": true,
"stmt42": true,
"stmt43": true,
"stmt45": true,
"stmt48": true,
"stmt49": true,
"stmt51": true,
Expand All @@ -37,19 +32,14 @@
"stmt69": true,
"stmt7": true,
"stmt70": true,
"stmt72": true,
"stmt76": true,
"stmt79": true,
"stmt80": true,
"stmt82": true,
"stmt83": true,
"stmt85": true,
"stmt86": true,
"stmt89": true,
"stmt9": true,
"stmt92": true,
"stmt93": true,
"stmt95": true,
"stmt98": true,
"stmt99": true
}
Expand Down
9 changes: 1 addition & 8 deletions parser/testdata/02340_analyzer_functions/metadata.json
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
{
"explain_todo": {
"stmt11": true,
"stmt14": true,
"stmt2": true,
"stmt5": true
}
}
{}
16 changes: 0 additions & 16 deletions parser/testdata/02342_analyzer_compound_types/metadata.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,19 @@
{
"explain_todo": {
"stmt14": true,
"stmt17": true,
"stmt20": true,
"stmt23": true,
"stmt26": true,
"stmt29": true,
"stmt30": true,
"stmt32": true,
"stmt35": true,
"stmt36": true,
"stmt38": true,
"stmt4": true,
"stmt41": true,
"stmt44": true,
"stmt47": true,
"stmt48": true,
"stmt5": true,
"stmt50": true,
"stmt53": true,
"stmt54": true,
"stmt6": true,
"stmt60": true,
"stmt63": true,
"stmt66": true,
"stmt69": true,
"stmt7": true,
"stmt72": true,
"stmt75": true,
"stmt76": true,
"stmt78": true,
"stmt8": true,
"stmt81": true,
"stmt82": true
Expand Down
86 changes: 0 additions & 86 deletions parser/testdata/02378_analyzer_projection_names/metadata.json
Original file line number Diff line number Diff line change
@@ -1,122 +1,36 @@
{
"explain_todo": {
"stmt101": true,
"stmt103": true,
"stmt105": true,
"stmt107": true,
"stmt109": true,
"stmt111": true,
"stmt113": true,
"stmt115": true,
"stmt117": true,
"stmt119": true,
"stmt121": true,
"stmt123": true,
"stmt125": true,
"stmt127": true,
"stmt129": true,
"stmt131": true,
"stmt133": true,
"stmt135": true,
"stmt137": true,
"stmt139": true,
"stmt141": true,
"stmt143": true,
"stmt145": true,
"stmt147": true,
"stmt149": true,
"stmt151": true,
"stmt153": true,
"stmt155": true,
"stmt157": true,
"stmt159": true,
"stmt161": true,
"stmt163": true,
"stmt165": true,
"stmt167": true,
"stmt169": true,
"stmt171": true,
"stmt173": true,
"stmt175": true,
"stmt177": true,
"stmt179": true,
"stmt181": true,
"stmt183": true,
"stmt185": true,
"stmt187": true,
"stmt189": true,
"stmt191": true,
"stmt193": true,
"stmt195": true,
"stmt197": true,
"stmt199": true,
"stmt201": true,
"stmt203": true,
"stmt205": true,
"stmt207": true,
"stmt209": true,
"stmt21": true,
"stmt211": true,
"stmt213": true,
"stmt215": true,
"stmt217": true,
"stmt219": true,
"stmt221": true,
"stmt223": true,
"stmt225": true,
"stmt227": true,
"stmt229": true,
"stmt23": true,
"stmt231": true,
"stmt233": true,
"stmt235": true,
"stmt237": true,
"stmt239": true,
"stmt241": true,
"stmt243": true,
"stmt245": true,
"stmt247": true,
"stmt25": true,
"stmt250": true,
"stmt252": true,
"stmt254": true,
"stmt256": true,
"stmt258": true,
"stmt27": true,
"stmt29": true,
"stmt31": true,
"stmt33": true,
"stmt35": true,
"stmt37": true,
"stmt39": true,
"stmt41": true,
"stmt43": true,
"stmt45": true,
"stmt47": true,
"stmt49": true,
"stmt51": true,
"stmt53": true,
"stmt55": true,
"stmt57": true,
"stmt59": true,
"stmt61": true,
"stmt63": true,
"stmt65": true,
"stmt67": true,
"stmt69": true,
"stmt71": true,
"stmt73": true,
"stmt75": true,
"stmt77": true,
"stmt79": true,
"stmt81": true,
"stmt83": true,
"stmt85": true,
"stmt87": true,
"stmt89": true,
"stmt91": true,
"stmt93": true,
"stmt95": true,
"stmt97": true,
"stmt99": true
}
Expand Down
6 changes: 1 addition & 5 deletions parser/testdata/03108_describe_union_all/metadata.json
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
{
"explain_todo": {
"stmt2": true
}
}
{}