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

sql/{parse,plan}: Add support union parsing and execution. #68

Merged
merged 8 commits into from
Feb 26, 2020

Conversation

reltuk
Copy link
Contributor

@reltuk reltuk commented Feb 24, 2020

This is still partial. We need type coercion and schema validation to be done
in the analysis phase.

This is still partial. We need type coercion and schema validation to be done
in the analysis phase.
@reltuk reltuk requested a review from zachmu February 24, 2020 23:07
Copy link
Member

@zachmu zachmu left a 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(
Copy link
Member

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()
Copy link
Member

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

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Member

@zachmu zachmu left a 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) {
Copy link
Member

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

Copy link
Contributor Author

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"},
Copy link
Member

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()
Copy link
Member

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.

@reltuk reltuk merged commit d094902 into ld-master Feb 26, 2020
@Hydrocharged Hydrocharged deleted the aaron/union-execution-support branch April 23, 2020 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants