-
-
Notifications
You must be signed in to change notification settings - Fork 212
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
add case for enum return types in multi-branch case statement #2766
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7531,6 +7531,68 @@ where | |
}, | ||
}, | ||
}, | ||
{ | ||
Name: "multi enum return types", | ||
SetUpScript: []string{ | ||
"create table t (i int primary key, e enum('abc', 'def', 'ghi'));", | ||
"insert into t values (1, 'abc'), (2, 'def'), (3, 'ghi');", | ||
}, | ||
Assertions: []ScriptTestAssertion{ | ||
{ | ||
Query: "select i, (case e when 'abc' then e when 'def' then e when 'ghi' then e end) as e from t;", | ||
Expected: []sql.Row{ | ||
{1, "abc"}, | ||
{2, "def"}, | ||
{3, "ghi"}, | ||
}, | ||
}, | ||
{ | ||
Skip: true, | ||
Query: "select i, (case e when 'abc' then e when 'def' then e when 'ghi' then 'something' end) as e from t;", | ||
Expected: []sql.Row{ | ||
{1, "abc"}, | ||
{2, "def"}, | ||
{3, "something"}, | ||
}, | ||
}, | ||
{ | ||
Skip: true, | ||
Query: "select i, (case e when 'abc' then e when 'def' then e when 'ghi' then 123 end) as e from t;", | ||
Expected: []sql.Row{ | ||
{1, "abc"}, | ||
{2, "def"}, | ||
{3, "123"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Name: "enum cast to int and string", | ||
SetUpScript: []string{ | ||
"create table t (i int primary key, e enum('abc', 'def', 'ghi'));", | ||
"insert into t values (1, 'abc'), (2, 'def'), (3, 'ghi');", | ||
}, | ||
Assertions: []ScriptTestAssertion{ | ||
{ | ||
Skip: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. e.g. it might be helpful to add a comment linking to the GitHub issue for these skipped tests. That would help provide more context for a future code reader. |
||
Query: "select i, cast(e as signed) from t;", | ||
Expected: []sql.Row{ | ||
{1, 1}, | ||
{2, 2}, | ||
{3, 3}, | ||
}, | ||
}, | ||
{ | ||
Skip: true, | ||
Query: "select i, cast(e as char) from t;", | ||
Expected: []sql.Row{ | ||
{1, "abc"}, | ||
{2, "def"}, | ||
{3, "ghi"}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
var SpatialScriptTests = []ScriptTest{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,12 @@ func combinedCaseBranchType(left, right sql.Type) sql.Type { | |
if right == types.Null { | ||
return left | ||
} | ||
if types.IsEnum(left) && types.IsEnum(right) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably worth adding a comment to explain what we're doing here. This seems pretty difficult to reverse engineer and figure out in a year or two when someone new looks at this code and tries to figure out why these cases are in here. |
||
return right | ||
} | ||
if types.IsSet(left) && types.IsSet(right) { | ||
return right | ||
} | ||
if types.IsTextOnly(left) && types.IsTextOnly(right) { | ||
return types.LongText | ||
} | ||
|
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 it's generally useful to add some context if we're skipping a test. Could be what's missing to make the test pass or anything else that could be useful to someone looking at this brand new next year and trying to figure out why the test is skipped.