-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
ddl: enhance validation of column names when creating table #6349
Conversation
/run-all-tests |
ddl/ddl_api.go
Outdated
@@ -536,6 +536,15 @@ func checkTooManyColumns(colDefs []*ast.ColumnDef) error { | |||
return nil | |||
} | |||
|
|||
func checkContainDotColumn(tableName string, colDefs []*ast.ColumnDef) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add comments for the function.
ddl/ddl_api.go
Outdated
@@ -536,6 +536,16 @@ func checkTooManyColumns(colDefs []*ast.ColumnDef) error { | |||
return nil | |||
} | |||
|
|||
// checkContainDotColumns check field contains the table name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/check/checks
ddl/ddl_api.go
Outdated
@@ -536,6 +536,16 @@ func checkTooManyColumns(colDefs []*ast.ColumnDef) error { | |||
return nil | |||
} | |||
|
|||
// checkContainDotColumns check field contains the table name. | |||
func checkContainDotColumns(tableName string, colDefs []*ast.ColumnDef) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we check it in the function of Preprocess
?
/run-all-tests |
plan/preprocess.go
Outdated
@@ -462,6 +467,16 @@ func isIncorrectName(name string) bool { | |||
return false | |||
} | |||
|
|||
// checksContainDotColumns check field contains the table name. | |||
func checksContainDotColumns(tableName string, colDefs []*ast.ColumnDef) (string, bool) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- s/checksContainDotColumns/checkContainDotColumn/
- make this function as a member function of
preprocessor
and we can setp.err
inside this function, thus we can only return abool
value to indicate whether there is a column whose name contains a dot symbol.
plan/preprocess.go
Outdated
@@ -462,6 +467,16 @@ func isIncorrectName(name string) bool { | |||
return false | |||
} | |||
|
|||
// checksContainDotColumns check field contains the table name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is not that explicit, better put an example here?
tk.MustExec("drop table if exists test.t1") | ||
tk.MustExec("create table test.t1(t1.a char)") | ||
tk.MustExec("drop table if exists t2") | ||
tk.MustExec("create table t2(a char, t2.b int)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add test for
create table t(s.a char);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already add.
plan/preprocess.go
Outdated
@@ -224,6 +224,11 @@ func (p *preprocessor) checkCreateTableGrammar(stmt *ast.CreateTableStmt) { | |||
return | |||
} | |||
|
|||
if tableName, ok := checksContainDotColumns(tName, stmt.Cols); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add some comments
Please address comments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
plan/preprocess.go
Outdated
@@ -52,6 +52,7 @@ func (p *preprocessor) Enter(in ast.Node) (out ast.Node, skipChildren bool) { | |||
case *ast.CreateTableStmt: | |||
p.inCreateOrDropTable = true | |||
p.checkCreateTableGrammar(node) | |||
p.checkContainDotColumn(node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
call it in p.checkCreateTableGrammar is better.
/run-all-tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/run-all-tests |
plan/preprocess.go
Outdated
for _, colDef := range stmt.Cols { | ||
// check table name. | ||
if colDef.Name.Table.O != tName && len(colDef.Name.Table.O) != 0 { | ||
p.err = ddl.ErrWrongTableName.GenByArgs(colDef.Name.Table.O) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can break here.
Check the table name that are included in the field is it consistent with the
create table name
respond issues #6330