Conversation
|
I'm very interested in getting design feedback here! The new field in Also, the recent rewrite of ast.go and creation of rewriter.go happened while this patch was being developed, and I'd like to be sure I'm doing things correctly in that new context. The next important ALTER commands to be handled are probably |
66b1788 to
a0cddab
Compare
fe9d446 to
5dc8db5
Compare
|
looks like an unrelated flaky test? Lmk if it's real! |
go/vt/sqlparser/ast.go
Outdated
There was a problem hiding this comment.
Shouldn't this be drop partition %v? Maybe we should add tests cases for the new constructs in parse_test.go to make sure that parsing and pretty printing both agree?
There was a problem hiding this comment.
Annoyingly, it's not and I didn't want to change the way the Partitions struct worked. We already have test cases for drop partition:
}, {
input: "alter table a drop partition p2712",
output: "alter table a drop partition (p2712)",
}, {
There was a problem hiding this comment.
This generates a syntax error in mysql:
mysql> alter table a drop partition (a,b);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(a,b)' at line 1
mysql> alter table a drop partition a;
ERROR 1505 (HY000): Partition management on a not partitioned table is not possible
mysql> alter table a drop partition a, b;
ERROR 1505 (HY000): Partition management on a not partitioned table is not possible
If you want to reuse an existing type, you could use Exprs which prints a comma-separated list. Otherwise, I'd recommend creating a new ColIdents type so you can define a separate formatting for that member.
Also, I assume partition names are case-insensitive. Otherwise, we should use TabletIdents.
|
Yeah, that looks like a flaky test. I restarted it. 🙏 This looks really good in general. Thank you for taking the time to do this. The one concern I have, which is not specific to this PR but more in general of your additions to the parser, is that Vitess might start accepting, but ignoring, whole or parts of queries. It would be nice to have a way of marking AST objects in some way as unsupported, and fail early in the pipeline with a clear message. Not sure how that would work yet. If you have ideas, do share. |
To throw a potential solution out there... we could add struct tags to unsupported fields like so DDL struct {
...
PartitionSpec *PartitionSpec
VindexCols []ColIdent
Ignore string `vitess:"unsupported"`
AlterSpecs []*AlterSpec `vitess:"unsupported"`
}Then we'd check if `unsupported" feilds were set after parsing – which would trigger an error. Although this would certainly involve some reflection at runtime that would come at a cost. |
This is a significant, but not complete expansion of the ALTER support in sqlparser. It adds support for these ALTER commands: * `ADD COLUMN` * `DROP COLUMN` * `ADD INDEX` * `DROP INDEX` * `DROP FOREIGN KEY` * `DROP PRIMARY KEY` * `ADD PARTITION` * `DROP PARTITION` * `ADD CHECK` (as a no-op; it's parsed but never executed by mysql servers) The main addition with this API is an additional field on `DDL` that is a slice of newly created `AlterSpecs`. An `AlterSpec` represents one of the commands that can occur in the same `ALTER` statement with other commands. This differentiates them from the `ALTER` statement parse states already in `sql.y` which are concerned with `ALTER` commands that must be the sole commands in the statement. The `ADD PARTITION` and `DROP PARTITION` states are the exception and are new singleton commands that `sql.y` now supports. This patch also includes some incidental updates to `go.mod` because of tooling issues (described in vitessio#5755) and are duplicated in vitessio#5766 Updates vitessio#5705 Signed-off-by: Jeff Hodges <jeff@somethingsimilar.com>
|
The desire for those unsupported checks would perhaps make more sense in a higher level package? The sqlparser could be just a sql language parser (since that's complicated enough), and handling semantics seem like they'd be better done above it. |
5dc8db5 to
0a94549
Compare
|
Sorry for letting this linger, @jmhodges. Seems like a conflict has snuck in. When it's in this file, I always just remove the file and recreate it using |
|
Note that the |
systay
left a comment
There was a problem hiding this comment.
DROP PARTITION needs to be fixed
|
@jmhodges this PR has fallen behind. Do you want to rework it? |
|
Closing this due to inactivity. |
|
The day job is taking up my brain. Won't be able to continue working on this for a while. |
|
No problem. Feel free to resurrect this when you get the time. |
This is a significant, but not complete expansion of the ALTER support in
sqlparser.
It adds support for these ALTER commands:
ADD COLUMNDROP COLUMNADD INDEXDROP INDEXDROP FOREIGN KEYDROP PRIMARY KEYADD PARTITIONDROP PARTITIONADD CHECK(as a no-op; it's parsed but never executed by mysql servers)The main addition with this API is an additional field on
DDLthat is a sliceof newly created
AlterSpecs. AnAlterSpecrepresents one of the commandsthat can occur in the same
ALTERstatement with other commands. Thisdifferentiates them from the
ALTERstatement parse states already insql.ywhich are concerned with
ALTERcommands that must be the sole commands in thestatement.
The
ADD PARTITIONandDROP PARTITIONstates are the exception and are newsingleton commands that
sql.ynow supports.This patch also includes some incidental updates to
go.modbecause of toolingissues (described in #5755) and are duplicated in #5766
Updates #5705
Signed-off-by: Jeff Hodges jeff@somethingsimilar.com