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

Support named windows in OVER (window_definition) clause #1166

Merged
merged 5 commits into from
Apr 7, 2024

Conversation

Nikita-str
Copy link
Contributor

Issue #999

Parse window_name in OVER ([window_name] [PARTITION BY ..] [ORDER BY ..] ..)

Actually disallow any keyword as `window_name` — seems like databases do the same
Copy link
Collaborator

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution @Nikita-str -- this makes sense to me

@@ -4115,6 +4117,62 @@ fn parse_window_functions() {
}),
expr_from_projection(&select.projection[0])
);

for i in 0..7 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@Nikita-str
Copy link
Contributor Author

@alamb first of all, should I do something with parse_deeply_nested_parens_hits_recursion_limits test? Because locally it's failed with stack overflow even in main branch. All others test result is ok.

@alamb
Copy link
Collaborator

alamb commented Mar 11, 2024

@alamb first of all, should I do something with parse_deeply_nested_parens_hits_recursion_limits test? Because locally it's failed with stack overflow even in main branch. All others test result is ok.

I think we may need to update the default limit to have a lower limit (it is right on the edge of stack limit in the debug build, and so any change to the stack size leads to a failure)

Maybe we can do it in a separate PR -- any chance you are willing to do so? If not I will try to do so but it may be several days

@Nikita-str
Copy link
Contributor Author

@alamb do you suggest to change const DEFAULT_REMAINING_DEPTH: usize = 50; in src\parser\mod.rs to 40 for example?

Maybe it's better to wrap this test code into new thread with bigger stack size and then wait until the thread finished?:

    const KB: usize = 1024;
    const MB: usize = 1024 * KB;
    std::thread::Builder::new().stack_size(8 * MB).spawn(move || { 
        // prev code
    }).unwrap().join().unwrap();

@alamb
Copy link
Collaborator

alamb commented Mar 11, 2024

@alamb do you suggest to change const DEFAULT_REMAINING_DEPTH: usize = 50; in src\parser\mod.rs to 40 for example?

Yes, this is basically my suggestion

The rationale is that doing so will prevent stack overflows / panics for debug builds.

Another thing we can do is to see if we can reduce the stack frame size for some of the intermediate function calls (reduce stack frame means make fewer local variables)

@Nikita-str
Copy link
Contributor Author

Nikita-str commented Mar 11, 2024

Maybe we can do it in a separate PR -- any chance you are willing to do so?

Ok, I will do it, at least by wrapping in new thread.
If I solve it by wrapping then I would to wrap all tests that assert ParserError::RecursionLimitExceeded to prevent future the same errors with stack overflow at least in already existed tests, ok?

Idea with wrapping is bad because it only handles the tests situation and when RecursionLimitExceeded situation will happen during development with using the crate, the user will get stack overflow

@alamb
Copy link
Collaborator

alamb commented Mar 11, 2024

You are not the first to hit this problem -- I think @universalmind303 saw it in #1144

Thus i think we need to do some real work -- I will try and find time later this week to help

@coveralls
Copy link

coveralls commented Apr 7, 2024

Pull Request Test Coverage Report for Build 8588647268

Details

  • 29 of 29 (100.0%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.02%) to 87.921%

Totals Coverage Status
Change from base Build 8588627223: 0.02%
Covered Lines: 20657
Relevant Lines: 23495

💛 - Coveralls

@alamb
Copy link
Collaborator

alamb commented Apr 7, 2024

I merged up from main and now this test is passing 🎉

@alamb alamb changed the title Named windows in OVER (window_definition) clause Support named windows in OVER (window_definition) clause Apr 7, 2024
@alamb
Copy link
Collaborator

alamb commented Apr 7, 2024

Thanks again @Nikita-str -- this is a very nice contribution

@alamb alamb merged commit 2310330 into sqlparser-rs:main Apr 7, 2024
10 checks passed
JichaoS pushed a commit to luabase/sqlparser-rs that referenced this pull request May 7, 2024
…-rs#1166)

Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
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

3 participants