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

Window frame support #764

Merged
merged 2 commits into from
Jan 27, 2022
Merged

Window frame support #764

merged 2 commits into from
Jan 27, 2022

Conversation

max-hoffman
Copy link
Contributor

This PR adds sql.WindowFrame and sql.WindowFramers to represent
window frames from AST -> plan -> exec.

Every unique and valid combination of window frame
Start and End bounds has a plan node (sql.WindowFrame)
and a framer (sql.WindowFramer) pair. The frames, framers,
and constructor functions that map from AST -> plan and
plan -> exec are generated by optgen.

@@ -21,3 +21,17 @@ when the opportunities arise.
If we end up using more of cockroach DB's optimizer, they codegen their
expressions, normalization rules, exploration rules, and execution code
stem from this general setup.

## Generators
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zachmu summary of codegen

@@ -166,6 +166,19 @@ type WindowFramer interface {
//SlidingInterval(ctx Context) (WindowInterval, WindowInterval, WindowInterval)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zachmu this is important, will add doc comments

@@ -255,3 +257,162 @@ func (f *GroupByFramer) Interval() (sql.WindowInterval, error) {
func (f *GroupByFramer) SlidingInterval(ctx sql.Context) (sql.WindowInterval, sql.WindowInterval, sql.WindowInterval) {
panic("implement me")
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zachmu this is the point of failure for ROWS frame correctness

)

//go:generate optgen -out window_frame_factory.og.go -pkg parse frameFactory window_frame_factory.go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@zachmu this is the bottleneck for AST -> plan node correctness

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.

Seems like a sound approach, just one major suggestion.

This needs more tests, probably generated as well.

sql/core.go Show resolved Hide resolved
sql/core.go Outdated Show resolved Hide resolved
sql/core.go Outdated Show resolved Hide resolved
sql/expression/common.go Outdated Show resolved Hide resolved
unboundedPreceding bool
startCurrentRow bool
endCurrentRow bool
startPrecedingExpr int
Copy link
Member

Choose a reason for hiding this comment

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

Odd to call these expr when they are ints

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what if i called them both startNPreceding?

sql/expression/function/aggregation/window_framer.og.go Outdated Show resolved Hide resolved
sql/plan/window_frame.go Outdated Show resolved Hide resolved
This PR adds sql.WindowFrame and sql.WindowFramers to represent
window frames from AST -> plan -> exec.

Every unique and valid combination of window frame
Start and End bounds has a plan node (sql.WindowFrame)
and a framer (sql.WindowFramer) pair. The frames, framers,
and constructor functions that map from AST -> plan and
plan -> exec are generated by optgen.

Only rowFrameBase implemented in this PR, range frame tests
are commented out until rangeFrameBase is implemented.
@max-hoffman max-hoffman merged commit 1defbc6 into main Jan 27, 2022
@max-hoffman max-hoffman deleted the max/window-frames branch January 27, 2022 19:41
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.

2 participants