-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add recursion limit configuration to DFParser
#14095
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -257,6 +257,9 @@ fn ensure_not_set<T>(field: &Option<T>, name: &str) -> Result<(), ParserError> { | |
Ok(()) | ||
} | ||
|
||
// By default, allow expressions up to this deep before error | ||
const DEFAULT_REMAINING_DEPTH: usize = 100; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I double checked that the default in sqlparser is 50 so this is 2x the size https://docs.rs/sqlparser/latest/src/sqlparser/parser/mod.rs.html#187 I am a little worried about this as it is a hard coded limit but I think we can always make it a config flag later |
||
|
||
/// DataFusion SQL Parser based on [`sqlparser`] | ||
/// | ||
/// Parses DataFusion's SQL dialect, often delegating to [`sqlparser`]'s [`Parser`]. | ||
|
@@ -287,7 +290,9 @@ impl<'a> DFParser<'a> { | |
let tokens = tokenizer.tokenize()?; | ||
|
||
Ok(DFParser { | ||
parser: Parser::new(dialect).with_tokens(tokens), | ||
parser: Parser::new(dialect) | ||
.with_recursion_limit(DEFAULT_REMAINING_DEPTH) | ||
.with_tokens(tokens), | ||
}) | ||
} | ||
|
||
|
@@ -299,7 +304,7 @@ impl<'a> DFParser<'a> { | |
} | ||
|
||
/// Parse a SQL string and produce one or more [`Statement`]s with | ||
/// with the specified dialect. | ||
/// the specified dialect. | ||
pub fn parse_sql_with_dialect( | ||
sql: &str, | ||
dialect: &dyn Dialect, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ const SQLITE_PREFIX: &str = "sqlite"; | |
pub fn main() -> Result<()> { | ||
tokio::runtime::Builder::new_multi_thread() | ||
.enable_all() | ||
.thread_stack_size(4 * 1024 * 1024) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to adjust this config to avoid error There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am worried about this. We have recently added the the Here is the stack where it overflows (precisely what the Recursion limit is designed to prevent:
Note @blaginin recently added the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow, very clear. So, I will close this PR and wait for the new release of |
||
.build()? | ||
.block_on(run_tests()) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can say this is 2x the default limit of sqlparser so it is clear this is meant to increase the limit