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

fix: maybe_parse preventing parser from erroring on recursion limit #1464

Merged
merged 6 commits into from
Oct 21, 2024

Conversation

tomershaniii
Copy link
Contributor

@tomershaniii tomershaniii commented Oct 9, 2024

This PR fixes a bug in the recursion checks, the bug is caused by maybe_parse ignoring the returned error, which (in the case of recursion depth check) prevents the Error from propagating back to the caller and may lead to unexpected parsing results.

The fix involves specific handling of the RecursionLimitExceeded error within maybe_parse and returning the error up the call stack.

Copy link
Contributor

@iffyio iffyio left a comment

Choose a reason for hiding this comment

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

Thanks for this fix @tomershaniii! Would it be possible to include a test case that passes with this fix? If so we could add one here for example

@tomershaniii
Copy link
Contributor Author

tomershaniii commented Oct 14, 2024

@iffyio took some yak shaving but it's finally here :-) check out test_parentheses_overflow
Some context for the other changes:

  • the parse_boxed variants were doing the boxing when exiting the recursion, which resulted in unreasonable low number of stack frames before overflowing, in the PRs i removed the parse_boxed functions and added native boxing to the respective parse_ functions

Copy link
Contributor

@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.

Looks great to me -- than you @tomershaniii and @iffyio

@@ -3191,7 +3191,7 @@ pub enum Statement {
/// Table confs
options: Vec<SqlOption>,
/// Cache table as a Query
query: Option<Query>,
query: Option<Box<Query>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a nice change

@@ -1103,7 +1103,7 @@ pub enum PivotValueSource {
/// Pivot on all values returned by a subquery.
///
/// See <https://docs.snowflake.com/en/sql-reference/constructs/pivot#pivot-on-column-values-using-a-subquery-with-dynamic-pivot>.
Subquery(Query),
Subquery(Box<Query>),
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

match f(self) {
Ok(t) => Ok(Some(t)),
// Unwind stack if limit exceeded
Err(ParserError::RecursionLimitExceeded) => Err(ParserError::RecursionLimitExceeded),
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@alamb
Copy link
Contributor

alamb commented Oct 16, 2024

Looks like a CI check is failing on this PR

@coveralls
Copy link

coveralls commented Oct 16, 2024

Pull Request Test Coverage Report for Build 11440876981

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 277 of 279 (99.28%) changed or added relevant lines in 17 files are covered.
  • 4 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.001%) to 89.388%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/parser/mod.rs 61 63 96.83%
Files with Coverage Reduction New Missed Lines %
tests/sqlparser_common.rs 4 89.6%
Totals Coverage Status
Change from base Build 11429400839: 0.001%
Covered Lines: 30400
Relevant Lines: 34009

💛 - Coveralls

Copy link
Contributor

@iffyio iffyio left a comment

Choose a reason for hiding this comment

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

LGTM! thanks @tomershaniii

@tomershaniii
Copy link
Contributor Author

CI issues fixed, please re-run

@tomershaniii
Copy link
Contributor Author

Build broken by another commit, please re-run CI

@alamb
Copy link
Contributor

alamb commented Oct 20, 2024

🤔 CI is still failing unfortunately

@tomershaniii
Copy link
Contributor Author

yet another rebase fix @alamb plz...

@alamb
Copy link
Contributor

alamb commented Oct 21, 2024

🚀

@alamb alamb merged commit 8e0d26a into apache:main Oct 21, 2024
10 checks passed
@alamb
Copy link
Contributor

alamb commented Oct 21, 2024

Thanks for sticking with this @tomershaniii and for the review @iffyio

@alamb alamb changed the title fix for maybe_parse preventing parser from erroring on recursion limit fix: change maybe_parse preventing parser from erroring on recursion limit Oct 21, 2024
@alamb alamb changed the title fix: change maybe_parse preventing parser from erroring on recursion limit fix: maybe_parse preventing parser from erroring on recursion limit Oct 21, 2024
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.

4 participants