Skip to content

Commit

Permalink
fix: store query comments in index to ast
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <[email protected]>
  • Loading branch information
harshit-gangal committed Sep 13, 2024
1 parent 814ddcf commit 035ef96
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
6 changes: 6 additions & 0 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1785,6 +1785,12 @@ var (
}, {
input: `create index Indexes on b (col1)`,
output: "alter table b add key `Indexes` (col1)",
}, {
input: `create /*vt+ foo=1 */ index Indexes on b (col1)`,
output: "alter /*vt+ foo=1 */ table b add key `Indexes` (col1)",
}, {
input: `alter /*vt+ foo=1 */ table b add key Indexes (col1)`,
output: "alter /*vt+ foo=1 */ table b add key `Indexes` (col1)",
}, {
input: `create fulltext index Indexes on b (col1)`,
output: "alter table b add fulltext key `Indexes` (col1)",
Expand Down
8 changes: 4 additions & 4 deletions go/vt/sqlparser/sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions go/vt/sqlparser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -1271,22 +1271,22 @@ alter_table_prefix:
create_index_prefix:
CREATE comment_opt INDEX sql_id using_opt ON table_name
{
$$ = &AlterTable{Table: $7, AlterOptions: []AlterOption{&AddIndexDefinition{IndexDefinition:&IndexDefinition{Info: &IndexInfo{Name:$4}, Options:$5}}}}
$$ = &AlterTable{Comments: Comments($2).Parsed(), Table: $7, AlterOptions: []AlterOption{&AddIndexDefinition{IndexDefinition:&IndexDefinition{Info: &IndexInfo{Name:$4}, Options:$5}}}}
setDDL(yylex, $$)
}
| CREATE comment_opt FULLTEXT INDEX sql_id using_opt ON table_name
{
$$ = &AlterTable{Table: $8, AlterOptions: []AlterOption{&AddIndexDefinition{IndexDefinition:&IndexDefinition{Info: &IndexInfo{Name:$5, Type: IndexTypeFullText}, Options:$6}}}}
$$ = &AlterTable{Comments: Comments($2).Parsed(), Table: $8, AlterOptions: []AlterOption{&AddIndexDefinition{IndexDefinition:&IndexDefinition{Info: &IndexInfo{Name:$5, Type: IndexTypeFullText}, Options:$6}}}}
setDDL(yylex, $$)
}
| CREATE comment_opt SPATIAL INDEX sql_id using_opt ON table_name
{
$$ = &AlterTable{Table: $8, AlterOptions: []AlterOption{&AddIndexDefinition{IndexDefinition:&IndexDefinition{Info: &IndexInfo{Name:$5, Type: IndexTypeSpatial}, Options:$6}}}}
$$ = &AlterTable{Comments: Comments($2).Parsed(), Table: $8, AlterOptions: []AlterOption{&AddIndexDefinition{IndexDefinition:&IndexDefinition{Info: &IndexInfo{Name:$5, Type: IndexTypeSpatial}, Options:$6}}}}
setDDL(yylex, $$)
}
| CREATE comment_opt UNIQUE INDEX sql_id using_opt ON table_name
{
$$ = &AlterTable{Table: $8, AlterOptions: []AlterOption{&AddIndexDefinition{IndexDefinition:&IndexDefinition{Info: &IndexInfo{Name:$5, Type: IndexTypeUnique}, Options:$6}}}}
$$ = &AlterTable{Comments: Comments($2).Parsed(), Table: $8, AlterOptions: []AlterOption{&AddIndexDefinition{IndexDefinition:&IndexDefinition{Info: &IndexInfo{Name:$5, Type: IndexTypeUnique}, Options:$6}}}}
setDDL(yylex, $$)
}

Expand Down

0 comments on commit 035ef96

Please sign in to comment.