-
Notifications
You must be signed in to change notification settings - Fork 18
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
Allow other options to precede COLLATE in column type defintions #195
Conversation
82f888a
to
d4cdb1d
Compare
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, only real comment is that it seems some of the timestamp default tests got lost
}, { | ||
// test utc_timestamp with and without () | ||
input: "create table t (\n" + | ||
" time1 timestamp default utc_timestamp,\n" + |
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.
Where did the tests for these go?
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.
You didn't read my description sir lol
@@ -2361,89 +2365,116 @@ column_type_options: | |||
{ | |||
opt := ColumnType{Null: BoolVal(true), NotNull: BoolVal(false), sawnull: true} | |||
if err := $1.merge(opt); err != nil { | |||
yylex.Error(err.Error()) | |||
return 1 | |||
yylex.Error(err.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.
Probably should preserve the default 4 space indents here and below (better corresponds to the golang tab)
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.
All other indents in the file (or at least the majority) use two spaces rather than tabs, so I changed it to be more consistent. Makes sense that we'd use tab instead, but I wanna keep consistency for now.
Fixes dolthub/dolt#4403
Previously,
COLLATE
had to immediately follow the column type in a column definition. As per the above issue, this is not a required rule in MySQL. The fix involved moving all collation-related options from thecolumn_type
rule to thecolumn_type_options
. This caused a conflict incolumn_type_options
, ascolumn_default
also has aCOLLATE
rule. The conflicting rule resolved to the following:For reference, this is the new
COLLATE
rule incolumn_type_options
:Given the MySQL expression
DEFAULT "xyz" COLLATE utf8mb4_bin
, it could match either rule, which caused the conflict.value_expression
is too permissive in this context, and although we filter out invalid expressions in GMS, we need to be more restrictive here in the parser to prevent conflicts. In addition, the above example should put the collation on the column, as it is not possible to add a collation to a default string literal (must use the expression form:DEFAULT ("xyz" COLLATE utf8mb4_bin)
).To fix this, the
column_default
rule was updated to be vastly more restrictive. This also highlighted some tests in GMS that enforce incorrect behavior, but those have been fixed ahead-of-time, and will be incorporated into the bump PR.NOTE: For some reason, we had tests allowing the use of
utc_timestamp
,utc_date
, etc. as default values without the need for parentheses. This is not allowed in MySQL, so I am unsure as to why we allowed them in the first place. Perhaps because they're similar toCURRENT_TIMESTAMP
, so we just allowed all of them? Regardless, the tests have been removed as they no longer pass (as they should not pass).