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

Nullable Timestamp Column Fix #7740

Merged
merged 5 commits into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
8 changes: 8 additions & 0 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,15 @@ type ColumnType struct {

// ColumnTypeOptions are generic field options for a column type
type ColumnTypeOptions struct {
/* We need both Null and NotNull to distinguish 3 cases -
GuptaManan100 marked this conversation as resolved.
Show resolved Hide resolved
1. When Not Null is specified (NotNull = true, Null = false)
2. When Null is specified (NotNull = false, Null = true)
3. When nothing is specified (NotNull = false, Null = false)
The complexity arises from the fact that we do not know whether the column will be nullable or not if nothing is specified.
Therefore we do not know whether the column is nullable or not in case 3.
*/
NotNull bool
Null bool
GuptaManan100 marked this conversation as resolved.
Show resolved Hide resolved
Autoincrement bool
Default Expr
OnUpdate Expr
Expand Down
1 change: 1 addition & 0 deletions go/vt/sqlparser/ast_equals.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/ast_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,9 @@ func (ct *ColumnType) Format(buf *TrackedBuffer) {
if ct.Collate != "" {
buf.astPrintf(ct, " %s %s", keywordStrings[COLLATE], ct.Collate)
}
if ct.Options.Null {
buf.astPrintf(ct, " %s", keywordStrings[NULL])
}
if ct.Options.NotNull {
buf.astPrintf(ct, " %s %s", keywordStrings[NOT], keywordStrings[NULL])
}
Expand Down
4 changes: 4 additions & 0 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.

11 changes: 11 additions & 0 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,9 @@ var (
}, {
input: "CREATE TABLE aipk (id INT AUTO_INCREMENT PRIMARY KEY)",
output: "create table aipk (\n\tid INT auto_increment primary key\n)",
}, {
input: "create table foo (f timestamp null not null , g timestamp not null null)",
GuptaManan100 marked this conversation as resolved.
Show resolved Hide resolved
output: "create table foo (\n\tf timestamp not null,\n\tg timestamp null\n)",
}, {
input: "alter vschema create vindex hash_vdx using hash",
}, {
Expand Down Expand Up @@ -2569,6 +2572,14 @@ func TestCreateTable(t *testing.T) {
" col_multipolygon2 multipolygon not null\n" +
")",

// test null columns
"create table foo (\n" +
" id int primary key,\n" +
" a varchar(255) null,\n" +
" b varchar(255) null default 'foo',\n" +
" c timestamp null default current_timestamp()\n" +
")",

// test defining indexes separately
"create table t (\n" +
" id int auto_increment,\n" +
Expand Down
Loading