-
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: Refine error message about "Invalid default value" #6333
Conversation
Hi contributor, thanks for your PR. This patch needs to be approved by someone of admins. They should reply with "/ok-to-test" to accept this PR for running test automatically. |
/run-all-tests |
ddl/ddl_api.go
Outdated
@@ -471,7 +471,10 @@ func checkDefaultValue(ctx sessionctx.Context, c *table.Column, hasDefaultValue | |||
if types.ErrTruncated.Equal(err) { | |||
return types.ErrInvalidDefault.GenByArgs(c.Name) | |||
} | |||
return errors.Trace(err) | |||
if err != nil { |
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 combine it with the upper if
? Should all errors be considered as invalid default
?
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.
@lamxTyler It's a bit complicate here I found. Illegal default value doesn't necessary result in ErrInvalidDefault
, actually. For example:
In MySQL:
mysql> create table t(a decimal(3) default 1.25567);
Query OK, 0 rows affected, 1 warning (0.03 sec)
mysql> show warnings;
+-------+------+----------------------------------------+
| Level | Code | Message |
+-------+------+----------------------------------------+
| Note | 1265 | Data truncated for column 'a' at row 1 |
+-------+------+----------------------------------------+
1 row in set (0.00 sec)
In TiDB:
tidb> create table t(a decimal(3) default 1.25567);
ERROR 1067 (42000): Invalid default value for 'a'
But if default value check if set in ALTER TABLE
situation(ddl/ddl_db_test.go: line 1139), The
ErrInvalidDefault
error is raised.
another example:
Im MySQL:
mysql> create table t ( a date default '2012-01-01 01:01:01');
Query OK, 0 rows affected, 1 warning (0.02 sec)
mysql> show warnings;
+-------+------+---------------------------------------------------------------------+
| Level | Code | Message |
+-------+------+---------------------------------------------------------------------+
| Note | 1292 | Incorrect date value: '2012-01-01 01:01:01' for column 'a' at row 1 |
+-------+------+---------------------------------------------------------------------+
1 row in set (0.00 sec)
In TiDB:
create table t ( a date default '2012-01-01 01:01:01');
Query OK, 0 rows affected (0.01 sec)
I think in case #6303 , we can fix the error message by throwing out ErrInvalidDefault
in all means, and Fix the corner cases or situations in extra one or more prs ..
/run-all-tests |
ddl/ddl_api.go
Outdated
if types.ErrTruncated.Equal(err) { | ||
return types.ErrInvalidDefault.GenByArgs(c.Name) | ||
if _, err := table.GetColDefaultValue(ctx, c.ToInfo()); err != nil { | ||
return errors.Trace(types.ErrInvalidDefault.GenByArgs(c.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.
Why trace the error? And please add a test for the fix.
/run-all-tests |
ddl/integration_test.go
Outdated
ctx sessionctx.Context | ||
} | ||
|
||
func (s *testIntegrationSuite) cleanEnv(c *C) { |
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 use TearDownTest
to avoid calling cleanEnv
in every 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.
I think we'd better clearEnv after every case. It's common that different cases use the same database name and table name. test.t
for example. We'd better clean them as soon as possible.
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.
TearDownTest
will be called automatically after every test case, we can rename cleanEnv
to TearDownTest
to avoid manually calling this 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.
ok
ddl/integration_test.go
Outdated
@@ -0,0 +1,88 @@ | |||
// Copyright 2015 PingCAP, Inc. |
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/2015/2018/
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
ddl/integration_test.go
Outdated
|
||
import ( | ||
"fmt" | ||
"github.com/juju/errors" |
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 blank line between line 17 and line 18
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.
@spongedu please address this comment.
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.
@zz-jason ok
@@ -467,11 +467,10 @@ func checkDefaultValue(ctx sessionctx.Context, c *table.Column, hasDefaultValue | |||
} | |||
|
|||
if c.DefaultValue != nil { | |||
_, err := table.GetColDefaultValue(ctx, c.ToInfo()) | |||
if types.ErrTruncated.Equal(err) { |
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'd better not remove this check totally,
it may be safer to add another check for err 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.
@XuHuaiyu as I commented above, it's a bit complicate here I found. Illegal default value doesn't necessary result in ErrInvalidDefault
, actually. For example:
In MySQL:
mysql> create table t(a decimal(3) default 1.25567);
Query OK, 0 rows affected, 1 warning (0.03 sec)
mysql> show warnings;
+-------+------+----------------------------------------+
| Level | Code | Message |
+-------+------+----------------------------------------+
| Note | 1265 | Data truncated for column 'a' at row 1 |
+-------+------+----------------------------------------+
1 row in set (0.00 sec)
In TiDB:
tidb> create table t(a decimal(3) default 1.25567);
ERROR 1067 (42000): Invalid default value for 'a'
But if default value check if set in ALTER TABLE
situation(ddl/ddl_db_test.go: line 1139), The
ErrInvalidDefault
error is raised.
another example:
Im MySQL:
mysql> create table t ( a date default '2012-01-01 01:01:01');
Query OK, 0 rows affected, 1 warning (0.02 sec)
mysql> show warnings;
+-------+------+---------------------------------------------------------------------+
| Level | Code | Message |
+-------+------+---------------------------------------------------------------------+
| Note | 1292 | Incorrect date value: '2012-01-01 01:01:01' for column 'a' at row 1 |
+-------+------+---------------------------------------------------------------------+
1 row in set (0.00 sec)
In TiDB:
create table t ( a date default '2012-01-01 01:01:01');
Query OK, 0 rows affected (0.01 sec)
I think in case #6303 , we can fix the error message by throwing out ErrInvalidDefault
in all means, ignore the error check, and Fix the corner cases or situations in extra one or more prs ..
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 |
LGTM |
@zimulala PTAL |
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 |
Fix #6303.