Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing of PARTITION BY KEY #10958

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 10 additions & 2 deletions go/vt/sqlparser/ast_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,11 @@ func (node *PartitionOption) Format(buf *TrackedBuffer) {
if node.KeyAlgorithm != 0 {
buf.astPrintf(node, " algorithm = %d", node.KeyAlgorithm)
}
buf.astPrintf(node, " %v", node.ColList)
if len(node.ColList) == 0 {
buf.literal(" ()")
} else {
buf.astPrintf(node, " %v", node.ColList)
}
case RangeType, ListType:
buf.astPrintf(node, " %s", node.Type.ToString())
if node.Expr != nil {
Expand Down Expand Up @@ -611,7 +615,11 @@ func (node *SubPartition) Format(buf *TrackedBuffer) {
if node.KeyAlgorithm != 0 {
buf.astPrintf(node, " algorithm = %d", node.KeyAlgorithm)
}
buf.astPrintf(node, " %v", node.ColList)
if len(node.ColList) == 0 {
buf.literal(" ()")
} else {
buf.astPrintf(node, " %v", node.ColList)
}
}

if node.SubPartitions != -1 {
Expand Down
16 changes: 12 additions & 4 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.

3 changes: 3 additions & 0 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,9 @@ var (
}, {
input: "create table t (id int) partition by key (id) partitions 2",
output: "create table t (\n\tid int\n)\npartition by key (id) partitions 2",
}, {
input: "create table t (id int, primary key(id)) partition by key () partitions 2",
output: "create table t (\n\tid int,\n\tprimary key (id)\n)\npartition by key () partitions 2",
}, {
input: "create table t (id int) partition by key algorithm = 1 (id)",
output: "create table t (\n\tid int\n)\npartition by key algorithm = 1 (id)",
Expand Down
Loading