Developer1010x opened a new issue, #25260:
URL: https://github.com/apache/datafusion/issues/25260

   ### 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
   
   ```rust
   // 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
   
   ```sql
   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.
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to