Describe the bug
A malformed null_regex panics the query task instead of returning an error.
CsvFormat::infer_schema_from_stream compiles the pattern with
// datafusion/datasource-csv/src/file_format.rs
let regex = Regex::new(null_regex.as_str())
.expect("Unable to parse CSV null regex.");
so any pattern the regex crate rejects aborts the task rather than surfacing
as a DataFusionError. It is reachable straight from SQL, from a CREATE EXTERNAL TABLE that does not spell out its columns, since that is what makes
schema inference run.
To Reproduce
CREATE EXTERNAL TABLE bad_regex
STORED AS CSV
LOCATION 'data.csv'
OPTIONS ('format.has_header' 'true', 'format.null_regex' '(');
task 9 panicked with message "Unable to parse CSV null regex.: Syntax(
regex parse error:
(
^
error: unclosed group
)"
Reproduced on main (9082d6b) through the sqllogictest harness. Any invalid
pattern does it; ( is just the shortest.
Expected behavior
An invalid null_regex is a bad option value, so it should come back as an
error naming the offending pattern — the same way other malformed CSV options
are handled — and leave the session usable.
Additional context
Noticed while working on #25213 / #25254. That PR changes CsvSource::builder
to return Result for the same reason on the read side, so it does not add a
second panic; this one is on the inference side and is independent of it.
The regex is also recompiled for every chunk inside the inference loop, so
hoisting the compile out is both the fix and a small saving.
I have a fix ready and will open a PR shortly.
Describe the bug
A malformed
null_regexpanics the query task instead of returning an error.CsvFormat::infer_schema_from_streamcompiles the pattern withso any pattern the
regexcrate rejects aborts the task rather than surfacingas a
DataFusionError. It is reachable straight from SQL, from aCREATE EXTERNAL TABLEthat does not spell out its columns, since that is what makesschema inference run.
To Reproduce
Reproduced on main (
9082d6b) through the sqllogictest harness. Any invalidpattern does it;
(is just the shortest.Expected behavior
An invalid
null_regexis a bad option value, so it should come back as anerror naming the offending pattern — the same way other malformed CSV options
are handled — and leave the session usable.
Additional context
Noticed while working on #25213 / #25254. That PR changes
CsvSource::builderto return
Resultfor the same reason on the read side, so it does not add asecond panic; this one is on the inference side and is independent of it.
The regex is also recompiled for every chunk inside the inference loop, so
hoisting the compile out is both the fix and a small saving.
I have a fix ready and will open a PR shortly.