You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "Developer1010x (via GitHub)" <gi...@apache.org> on 2026/09/13 06:01:24 UTC

[PR] fix: apply CSV null_regex when reading, not only when inferring the schema [datafusion]

Developer1010x opened a new pull request, #25254:
URL: https://github.com/apache/datafusion/pull/25254

   ## Which issue does this PR close?
   
   - Closes #25213.
   
   ## Rationale for this change
   
   Setting `null_regex` on a CSV source has no effect on the data that comes back.
   A field matching the pattern is read as the literal string, and if it lands in a
   column typed as a number the query fails outright:
   
   ```
   Arrow error: Parser error: Error while parsing value 'N/A' as type 'Int64'
   for column 1 at line 2. Row data: '[2,N/A]'
   ```
   
   That second case is the one that matters in practice — `N/A`, `NULL` and `-`
   placeholders are almost always sitting in columns that are otherwise numeric,
   which is the reason to reach for `null_regex` in the first place.
   
   The option was applied to the `arrow::csv::reader::Format` used by
   `CsvFormat::infer_schema`, but never to the `ReaderBuilder` that parses the
   rows. Inference therefore behaves as though the regex were honored and only the
   data disagrees, which is what makes it easy to miss.
   
   ## What changes are included in this PR?
   
   - `CsvSource::null_regex()`, alongside the existing `escape()`, `comment()` and
     `terminator()` accessors.
   - `CsvSource::builder()` applies the regex, and now returns `Result` so an
     invalid pattern surfaces as a configuration error instead of panicking.
     `CsvFormat::infer_schema` currently `.expect()`s on the same regex, so a
     malformed pattern is a panic there today; this side no longer adds a second
     one.
   - Three call sites updated for the new signature: `CsvSource::open`, and the two
     streaming decoder paths in `CsvOpener::open` (the byte-range branch and the
     `GetResultPayload::Stream` branch). Those two go through `builder()` as well,
     so they were missing the regex for the same reason.
   
   The fix is four lines; the signature change is what makes it touch more.
   
   ## What is the testing strategy for this PR?
   
   There was no coverage of `null_regex` anywhere in the repository before this
   change — not in `datafusion/datasource-csv`, not in the sqllogictest files.
   
   Unit tests in `datafusion/datasource-csv/src/source.rs`:
   
   - `null_regex_nulls_matching_string_values`
   - `null_regex_nulls_matching_values_in_numeric_columns` — the case that errors
     today rather than returning a wrong value
   - `without_null_regex_the_placeholder_is_read_verbatim` — control, pins that the
     unset behavior does not change
   - `invalid_null_regex_is_reported_as_an_error`
   
   I checked these are not vacuous: with the four added lines in `builder()`
   removed, the three behavioral tests fail and the control still passes.
   
   SQL-level coverage in `datafusion/sqllogictest/test_files/csv_files.slt`, over a
   new `datafusion/core/tests/data/null_regex.csv` fixture, covering a matching
   value in both a `VARCHAR` and an `INT` column.
   
   ## Are there any user-facing changes?
   
   `null_regex` starts doing what it is documented to do. Anything that set the
   option and worked around it being ignored — for example by typing a column as
   `VARCHAR` to avoid the parse error, then filtering the placeholder out in SQL —
   will now see NULL where it previously saw the literal string.
   
   No public API changes: `builder()` is private, and the new `null_regex()`
   accessor is additive.
   


-- 
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] fix: apply CSV null_regex when reading, not only when inferring the schema [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #25254:
URL: https://github.com/apache/datafusion/pull/25254#issuecomment-5937037879

   @Developer1010x  do you have time to resolve the conflicts on this PR and merge up from main?


-- 
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] fix: apply CSV null_regex when reading, not only when inferring the schema [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #25254:
URL: https://github.com/apache/datafusion/pull/25254#issuecomment-6384150398

   I am disappointed that that PR seems to have been AI spam that @Developer1010x  didn't see fit to complete.  However, since @Jefffrey  spent his time to review it I have merged it up and and gotten it ready to go


-- 
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] fix: apply CSV null_regex when reading, not only when inferring the schema [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #25254:
URL: https://github.com/apache/datafusion/pull/25254


-- 
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] fix: apply CSV null_regex when reading, not only when inferring the schema [datafusion]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #25254:
URL: https://github.com/apache/datafusion/pull/25254#issuecomment-5660388717

   ## [Codecov](https://app.codecov.io/gh/apache/datafusion/pull/25254?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `96.73913%` with `3 lines` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 81.88%. Comparing base ([`9082d6b`](https://app.codecov.io/gh/apache/datafusion/commit/9082d6b10c29b72d56bede3d8e353d9d61fde542?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`7ac3811`](https://app.codecov.io/gh/apache/datafusion/commit/7ac38110c23798e802b2b57336a2d7c161dec332?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 10 commits behind head on main.
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/datafusion/pull/25254?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [datafusion/datasource-csv/src/source.rs](https://app.codecov.io/gh/apache/datafusion/pull/25254?src=pr&el=tree&filepath=datafusion%2Fdatasource-csv%2Fsrc%2Fsource.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZGF0YWZ1c2lvbi9kYXRhc291cmNlLWNzdi9zcmMvc291cmNlLnJz) | 96.73% | [0 Missing and 3 partials :warning: ](https://app.codecov.io/gh/apache/datafusion/pull/25254?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@           Coverage Diff           @@
   ##             main   #25254   +/-   ##
   =======================================
     Coverage   81.88%   81.88%           
   =======================================
     Files        1133     1133           
     Lines      424522   424609   +87     
     Branches   424522   424609   +87     
   =======================================
   + Hits       347623   347701   +78     
   - Misses      56285    56290    +5     
   - Partials    20614    20618    +4     
   ```
   </details>
   
   [:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/datafusion/pull/25254?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
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