-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
types, plan: return ErrInvalidDefault when date type column option of create table statement has a now() default value #4430
Conversation
… create table statement has a now() default value
plan/validator.go
Outdated
default: | ||
// TODO: Add more types. | ||
} | ||
return nil | ||
} | ||
|
||
func isNowBuiltinFunc(expr ast.ExprNode) 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.
This function checks now
symbolic, it doesn't have to be exactly now
.
Use isNowSymFunc
is better, like the one defined in parser.
plan/validator.go
Outdated
@@ -444,12 +444,27 @@ func checkColumn(colDef *ast.ColumnDef) error { | |||
return types.ErrIllegalValueForType.GenByArgs(types.TypeStr(tp.Tp), str) | |||
} | |||
} | |||
case mysql.TypeDate: |
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.
NOW
function is invalid for other types too, it's valid for only DATETIME
and TIMESTAMP
.
@coocood PTAL |
LGTM |
util/types/errors.go
Outdated
@@ -45,6 +45,8 @@ var ( | |||
ErrCastAsSignedOverflow = terror.ClassTypes.New(codeUnknown, msgCastAsSignedOverflow) | |||
// ErrCastNegIntAsUnsigned is returned when a negative integer be casted to an unsigned int. | |||
ErrCastNegIntAsUnsigned = terror.ClassTypes.New(codeUnknown, msgCastNegIntAsUnsigned) | |||
// ErrInvalidDefault is return when meet a invalid default value. |
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/ return/ returned
plan/validator.go
Outdated
@@ -450,6 +454,28 @@ func checkColumn(colDef *ast.ColumnDef) error { | |||
return nil | |||
} | |||
|
|||
func isNowSymFunc(expr ast.ExprNode) 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.
add a comment for this func.
plan/validator.go
Outdated
@@ -450,6 +454,28 @@ func checkColumn(colDef *ast.ColumnDef) error { | |||
return nil | |||
} | |||
|
|||
func isNowSymFunc(expr ast.ExprNode) bool { | |||
if funcCall, ok := expr.(*ast.FuncCallExpr); ok { | |||
if funcCall.FnName.L == ast.CurrentTimestamp { |
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.
why not check ast.Now here?
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.
DefaultValueExpr:
NowSymOptionFraction | SignedLiteral
NowSymOptionFraction:
NowSym
{
$$ = &ast.FuncCallExpr{FnName: model.NewCIStr("CURRENT_TIMESTAMP")}
}
| NowSymFunc '(' ')'
{
$$ = &ast.FuncCallExpr{FnName: model.NewCIStr("CURRENT_TIMESTAMP")}
}
| NowSymFunc '(' NUM ')'
{
$$ = &ast.FuncCallExpr{FnName: model.NewCIStr("CURRENT_TIMESTAMP")}
}
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.
we can add a comment for isNowSymFunc
to state that default value NOW()
is transformed to CURRENT_TIMESTAMP()
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.
ok
…/default_now_date_type
…ngcap/tidb into winkyao/default_now_date_type
plan/validator.go
Outdated
@@ -450,6 +454,33 @@ func checkColumn(colDef *ast.ColumnDef) error { | |||
return nil | |||
} | |||
|
|||
// isNowSymFunc check whether defaul value is a NOW() builtin function. |
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
/run-all-test |
for #4429