-
-
Notifications
You must be signed in to change notification settings - Fork 190
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
sql/{parse,plan}: Add support union parsing and execution. #68
Conversation
This is still partial. We need type coercion and schema validation to be done in the analysis phase.
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.
Looks great, just what I would expect. A final solution should include engine tests and exercise distinct logic
@@ -1507,6 +1507,26 @@ var fixtures = map[string]sql.Node{ | |||
`SELECT * FROM foo`, | |||
true, | |||
), | |||
`SELECT 2 UNION SELECT 3` : plan.NewUnion( |
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 add a couple tests for distinct, as well as unions of 3 or more select statements
if err != nil { | ||
return nil, err | ||
} | ||
return ui.cur.Next() |
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 recurse here instead
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 (much) clearer without recursion. Am I crazy?
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.
The issue is that this is only correct when N=2. For the general case of composing an iterator from N sub iterators, if ui.cur.Next() on line 87 returns (nil, io.EOF), then recursion correctly continues to the next element, but what you have now terminates early.
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.
But that's not what this method does...agreed if this iterator took a bunch of row iterators and concat'd them, this impl would need to be different.
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 still think recursion is cleaner, but you do you :p
…the schema of both sides of a union is the same.
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.
Looks good, but it's probably time to commit to whether you want to enforce equal types or try to convert. Converting everything to a string is a reasonable first pass. Left.Type.Convert(right) would also be fine.
return false | ||
} | ||
for i := range ls { | ||
if !reflect.DeepEqual(ls[i].Type, rs[i].Type) { |
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.
Seems like this is mutually exclusive with the type conversion code in mergeUnionSchemas
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.
It is, but it's supposed to be a sanity check step in case schema merge fails.
memory.NewTable( | ||
"mytable", | ||
sql.Schema{ | ||
{Name: "foo", Source: "mytable"}, |
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.
Types? Seems important
if err != nil { | ||
return nil, err | ||
} | ||
return ui.cur.Next() |
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.
The issue is that this is only correct when N=2. For the general case of composing an iterator from N sub iterators, if ui.cur.Next() on line 87 returns (nil, io.EOF), then recursion correctly continues to the next element, but what you have now terminates early.
This is still partial. We need type coercion and schema validation to be done
in the analysis phase.