Skip to content

Conversation

@jycor
Copy link

@jycor jycor commented Sep 13, 2023

This PR adds support for parsing the keywords INTERSECT and EXCEPT.
These work similar to UNION and work with DISTINCT and ALL keywords.

Additionally, there are new precedence tests; INTERSECT has a higher precedence than UNION and EXCEPT.
The rest are parsed left to right.

syntax for dolthub/dolt#6643

@nicktobey
Copy link

As per our discussion, we need tests to make sure that we're parsing with the correct operator precedence. (INTERSECT has higher precedence than the other two.) Otherwise I think this looks good.

Copy link

@max-hoffman max-hoffman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, very clever way of implementing precedence, just requesting some docs so we can remember how it works in the future

$$ = $1
}

set_op:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is clever but might be confusing for someone without context. It might be helpful to give an example like {1,2} ∩ {2,3} U {3,4} has two results depending on whether you execute the intersect or union first (same as addition/multiplication). Here is 3 sentences that make it clear how we enforce INTERSECT being executed before UNION/EXCEPT...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. It's clever but I'm still not entire sure I understand how it works. Some documentation would be really helpful.

}

// Union.Type
// SetOp.Type

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be dumb to rewrite this into "SetOpType" and distinct as a bool? or does that lose information

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not dumb, and it doesn't lose any information.
I just duplicated the existing logic; I'm pretty sure it was written that way in the first place so the yacc code is simpler.
Could just do

$$ = UnionStr
$$ = UnionAllStr
$$ = UnionDistinctStr

and convert it later instead of returning a new struct


type Statements []Statement

func (*Union) iStatement() {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the whitespace got messed up in this file.

$$ = $1
}

set_op:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. It's clever but I'm still not entire sure I understand how it works. Some documentation would be really helpful.

Copy link

@nicktobey nicktobey 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 now. Thanks!

@jycor jycor merged commit 648c869 into main Sep 20, 2023
@Hydrocharged Hydrocharged deleted the james/intersect-except branch February 7, 2024 13:44
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.

3 participants