Skip to content

Commit

Permalink
fix: DDL comments to be recorded in AST (#16774)
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <[email protected]>
  • Loading branch information
harshit-gangal authored Sep 13, 2024
1 parent 814ddcf commit 155ede0
Show file tree
Hide file tree
Showing 12 changed files with 6,335 additions and 6,342 deletions.
1 change: 1 addition & 0 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ type (

// AlterDatabase represents a ALTER database statement.
AlterDatabase struct {
Comments *ParsedComments
DBName IdentifierCS
UpdateDataDirectory bool
AlterOptions []DatabaseOption
Expand Down
1 change: 1 addition & 0 deletions go/vt/sqlparser/ast_clone.go

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

4 changes: 3 additions & 1 deletion go/vt/sqlparser/ast_copy_on_rewrite.go

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

1 change: 1 addition & 0 deletions go/vt/sqlparser/ast_equals.go

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

4 changes: 2 additions & 2 deletions go/vt/sqlparser/ast_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -2186,7 +2186,7 @@ func (node *SelectInto) Format(buf *TrackedBuffer) {

// Format formats the node.
func (node *CreateDatabase) Format(buf *TrackedBuffer) {
buf.astPrintf(node, "create database %v", node.Comments)
buf.astPrintf(node, "create %vdatabase ", node.Comments)
if node.IfNotExists {
buf.literal("if not exists ")
}
Expand All @@ -2205,7 +2205,7 @@ func (node *CreateDatabase) Format(buf *TrackedBuffer) {

// Format formats the node.
func (node *AlterDatabase) Format(buf *TrackedBuffer) {
buf.literal("alter database")
buf.astPrintf(node, "alter %vdatabase", node.Comments)
if node.DBName.NotEmpty() {
buf.astPrintf(node, " %v", node.DBName)
}
Expand Down
7 changes: 5 additions & 2 deletions go/vt/sqlparser/ast_format_fast.go

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

5 changes: 5 additions & 0 deletions go/vt/sqlparser/ast_rewrite.go

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

3 changes: 3 additions & 0 deletions go/vt/sqlparser/ast_visit.go

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

2 changes: 2 additions & 0 deletions go/vt/sqlparser/cached_size.go

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

10 changes: 8 additions & 2 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 Expand Up @@ -2797,12 +2803,12 @@ var (
}, {
input: "rollback",
}, {
input: "create database /* simple */ test_db",
input: "create /* simple */ database test_db",
}, {
input: "create schema test_db",
output: "create database test_db",
}, {
input: "create database /* simple */ if not exists test_db",
input: "create /* simple */ database if not exists test_db",
}, {
input: "create schema if not exists test_db",
output: "create database if not exists test_db",
Expand Down
Loading

0 comments on commit 155ede0

Please sign in to comment.