You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "cetra3 (via GitHub)" <gi...@apache.org> on 2025/02/19 00:08:24 UTC
[PR] Allow setting the recursion limit for sql parsing [datafusion]
cetra3 opened a new pull request, #14756:
URL: https://github.com/apache/datafusion/pull/14756
## Which issue does this PR close?
No issue, just running into this in production.
## Rationale for this change
At the moment there isn't a clean way to set the recursion limit on the sql parser.
## What changes are included in this PR?
This PR allows a config option, `datafusion.sql_parser.recursion_limit` which allows overriding the recursion limit.
## Are these changes tested?
No, it's just a config option.
## Are there any user-facing changes?
There will be some changes to public facing API. I'm also not sure if this is the *best* approach here, as `DFParser` might need a deeper refactor to keep things clean.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Allow setting the recursion limit for sql parsing [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #14756:
URL: https://github.com/apache/datafusion/pull/14756
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Allow setting the recursion limit for sql parsing [datafusion]
Posted by "cetra3 (via GitHub)" <gi...@apache.org>.
cetra3 commented on code in PR #14756:
URL: https://github.com/apache/datafusion/pull/14756#discussion_r1972732904
##########
datafusion/core/src/execution/session_state.rs:
##########
@@ -483,12 +483,21 @@ impl SessionState {
MsSQL, ClickHouse, BigQuery, Ansi."
)
})?;
- let mut statements = DFParser::parse_sql_with_dialect(sql, dialect.as_ref())?;
+
+ let recursion_limit = self.config.options().sql_parser.recursion_limit;
+
+ let mut statements = DFParser::parse_sql_with_dialect_limit(
Review Comment:
I've adjusted the PR to include a new `DFParserBuilder` that accomplishes this, but I've tried to keep the original methods as close as possible for backwards compat
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Allow setting the recursion limit for sql parsing [datafusion]
Posted by "cetra3 (via GitHub)" <gi...@apache.org>.
cetra3 commented on PR #14756:
URL: https://github.com/apache/datafusion/pull/14756#issuecomment-2686743916
@alamb I've added a test and a builder struct, let me know if you want further changes
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Allow setting the recursion limit for sql parsing [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #14756:
URL: https://github.com/apache/datafusion/pull/14756#discussion_r1970151516
##########
datafusion/sql/src/parser.rs:
##########
@@ -257,6 +257,9 @@ fn ensure_not_set<T>(field: &Option<T>, name: &str) -> Result<(), ParserError> {
Ok(())
}
+/// Same as `sqlparser`
+const DEFAULT_RECURSION_LIMIT: usize = 50;
Review Comment:
I verified this is the same default:
https://github.com/apache/datafusion-sqlparser-rs/blob/648efd7057d63c65b53eddc3d05cc89d5697d85c/src/parser/mod.rs#L187
##########
datafusion/core/src/execution/session_state.rs:
##########
@@ -483,12 +483,21 @@ impl SessionState {
MsSQL, ClickHouse, BigQuery, Ansi."
)
})?;
- let mut statements = DFParser::parse_sql_with_dialect(sql, dialect.as_ref())?;
+
+ let recursion_limit = self.config.options().sql_parser.recursion_limit;
+
+ let mut statements = DFParser::parse_sql_with_dialect_limit(
Review Comment:
The API for DFParser is already somewhat tough.
Rather than adding a new method here, could you make this a builder style instead, so ths would look something like this?
```suggestion
let mut statements = DFParser::new_with_dialect(sql, dialect.with_ref())
.with_recursion_limit(recursion_limit)
.parse_statements()
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Allow setting the recursion limit for sql parsing [datafusion]
Posted by "adriangb (via GitHub)" <gi...@apache.org>.
adriangb commented on PR #14756:
URL: https://github.com/apache/datafusion/pull/14756#issuecomment-2673767266
I'll note that we encountered this when parsing a dynamically generated expression containing a lot of `AND`s and `OR`s. I believe these sorts of expressions are parsed recursively, so it's pretty easy to hit 50 levels of recursion if each `AND` is a level.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Allow setting the recursion limit for sql parsing [datafusion]
Posted by "cetra3 (via GitHub)" <gi...@apache.org>.
cetra3 commented on PR #14756:
URL: https://github.com/apache/datafusion/pull/14756#issuecomment-2669866457
@jatin510 This number is actually the default in `sqlparser`: https://github.com/apache/datafusion-sqlparser-rs/blob/b482562618caa3efa89c2f42f87472b00a270926/src/parser/mod.rs#L187
So it will essentially be the exact same behaviour, but configurable.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Allow setting the recursion limit for sql parsing [datafusion]
Posted by "adriangb (via GitHub)" <gi...@apache.org>.
adriangb commented on PR #14756:
URL: https://github.com/apache/datafusion/pull/14756#issuecomment-2682837878
> @adriangb I think you are saying that this is a good change, right?
Yes I was just explaining why this is necessary - it's not immediately obvious how parsing SQL can be so recursive.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Allow setting the recursion limit for sql parsing [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #14756:
URL: https://github.com/apache/datafusion/pull/14756#issuecomment-2690438906
Thanks again @cetra3
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Allow setting the recursion limit for sql parsing [datafusion]
Posted by "jatin510 (via GitHub)" <gi...@apache.org>.
jatin510 commented on PR #14756:
URL: https://github.com/apache/datafusion/pull/14756#issuecomment-2667568452
I see that a recursion limit of 50 is introduced for SQL parsing.
Is this based on specific performance benchmarks or potential stack overflow risks?
Also, is there any reference to similar constraints in databases like PostgreSQL, or is this a DataFusion-specific safeguard?
@cetra3
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org