Skip to content

Commit 2ea9bc9

Browse files
committed
Add recursion limit config to DFParser
Signed-off-by: Tai Le Manh <[email protected]>
1 parent 17446ad commit 2ea9bc9

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

datafusion/sql/src/parser.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ fn ensure_not_set<T>(field: &Option<T>, name: &str) -> Result<(), ParserError> {
257257
Ok(())
258258
}
259259

260+
// By default, allow expressions up to this deep before error
261+
const DEFAULT_REMAINING_DEPTH: usize = 100;
262+
260263
/// DataFusion SQL Parser based on [`sqlparser`]
261264
///
262265
/// Parses DataFusion's SQL dialect, often delegating to [`sqlparser`]'s [`Parser`].
@@ -287,7 +290,9 @@ impl<'a> DFParser<'a> {
287290
let tokens = tokenizer.tokenize()?;
288291

289292
Ok(DFParser {
290-
parser: Parser::new(dialect).with_tokens(tokens),
293+
parser: Parser::new(dialect)
294+
.with_recursion_limit(DEFAULT_REMAINING_DEPTH)
295+
.with_tokens(tokens),
291296
})
292297
}
293298

@@ -299,7 +304,7 @@ impl<'a> DFParser<'a> {
299304
}
300305

301306
/// Parse a SQL string and produce one or more [`Statement`]s with
302-
/// with the specified dialect.
307+
/// the specified dialect.
303308
pub fn parse_sql_with_dialect(
304309
sql: &str,
305310
dialect: &dyn Dialect,

0 commit comments

Comments
 (0)