You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "dhegberg (via GitHub)" <gi...@apache.org> on 2024/11/01 23:23:56 UTC
[PR] Support 'NULL' as Null in csv parser. [datafusion]
dhegberg opened a new pull request, #13228:
URL: https://github.com/apache/datafusion/pull/13228
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
Closes #12904.
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
Bring consistency between handling of `NULL` in CSV and SQL parsing.
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
Treat a `NULL` field in CSV as a null entry. Maintain treatment of 0 length entry as a null.
## Are these changes tested?
Added unit tests that test `NULL` and 0 length entries in the data CSV. Associated change in the testing data adds null columns: https://github.com/apache/arrow-testing/pull/103
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
## Are there any user-facing changes?
Yes, a `NULL` field in a .csv would no longer be treated as a string.
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api change` label.
-->
--
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] Support 'NULL' as Null in csv parser. [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #13228:
URL: https://github.com/apache/datafusion/pull/13228#discussion_r1828266229
##########
datafusion/core/Cargo.toml:
##########
@@ -127,6 +127,7 @@ parquet = { workspace = true, optional = true, default-features = true }
paste = "1.0.15"
pin-project-lite = "^0.2.7"
rand = { workspace = true }
+regex = { workspace = true }
Review Comment:
Yeah, the "better" think to do would be for arrow-rs to re-export the RegEx structure it used as it appears in the public API
--
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] Support 'NULL' as Null in csv parser. [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #13228:
URL: https://github.com/apache/datafusion/pull/13228
--
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] Support 'NULL' as Null in csv parser. [datafusion]
Posted by "dhegberg (via GitHub)" <gi...@apache.org>.
dhegberg commented on code in PR #13228:
URL: https://github.com/apache/datafusion/pull/13228#discussion_r1827063553
##########
datafusion/core/Cargo.toml:
##########
@@ -127,6 +127,7 @@ parquet = { workspace = true, optional = true, default-features = true }
paste = "1.0.15"
pin-project-lite = "^0.2.7"
rand = { workspace = true }
+regex = { workspace = true }
Review Comment:
When I remove it I have this error during `cargo build`:
```
error[E0432]: unresolved import `regex`
--> datafusion/core/src/datasource/file_format/csv.rs:59:5
|
59 | use regex::Regex;
| ^^^^^ help: a similar path exists: `datafusion_functions::regex`
For more information about this error, try `rustc --explain E0432`.
error: could not compile `datafusion` (lib) due to 1 previous error
```
--
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] Support 'NULL' as Null in csv parser. [datafusion]
Posted by "dhegberg (via GitHub)" <gi...@apache.org>.
dhegberg commented on PR #13228:
URL: https://github.com/apache/datafusion/pull/13228#issuecomment-2547418265
Updated to move Null parsing regex to a config.
Benchmark comparison when using regex does show some regression:
Before:
```
Running benches/csv_load.rs (/Users/dhegberg/workplace/datafusion/target/release/deps/csv_load-0ca64cec5e99a8c3)
Gnuplot not found, using plotters backend
Generated test dataset with 69642 rows
Benchmarking load csv testing/default csv read options
Benchmarking load csv testing/default csv read options: Warming up for 3.0000 s
Benchmarking load csv testing/default csv read options: Collecting 100 samples in estimated 20.457 s (1200 iterations)
Benchmarking load csv testing/default csv read options: Analyzing
load csv testing/default csv read options
time: [20.305 ms 20.536 ms 20.763 ms]
mean [20.305 ms 20.763 ms] std. dev. [1.0513 ms 1.2800 ms]
median [20.127 ms 21.042 ms] med. abs. dev. [1.0398 ms 1.6551 ms]
After:
```
Gnuplot not found, using plotters backend
Generated test dataset with 69642 rows
Benchmarking load csv testing/default csv read options
Benchmarking load csv testing/default csv read options: Warming up for 3.0000 s
Benchmarking load csv testing/default csv read options: Collecting 100 samples in estimated 21.606 s (1200 iterations)
Benchmarking load csv testing/default csv read options: Analyzing
load csv testing/default csv read options
time: [21.583 ms 21.856 ms 22.166 ms]
change: [+1.9609% +3.6130% +5.3682%] (p = 0.00 < 0.05)
Performance has regressed.
Found 4 outliers among 100 measurements (4.00%)
1 (1.00%) low mild
2 (2.00%) high mild
1 (1.00%) high severe
mean [21.583 ms 22.166 ms] std. dev. [988.76 µs 2.0538 ms]
median [21.438 ms 21.965 ms] med. abs. dev. [776.50 µs 1.3261 ms]
```
--
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] Support 'NULL' as Null in csv parser. [datafusion]
Posted by "eejbyfeldt (via GitHub)" <gi...@apache.org>.
eejbyfeldt commented on code in PR #13228:
URL: https://github.com/apache/datafusion/pull/13228#discussion_r1834466999
##########
datafusion/core/src/datasource/file_format/csv.rs:
##########
@@ -454,7 +455,9 @@ impl CsvFormat {
.has_header
.unwrap_or(state.config_options().catalog.has_header),
)
- .with_delimiter(self.options.delimiter);
+ .with_delimiter(self.options.delimiter)
+ // Support literal NULL or empty string as null
+ .with_null_regex(Regex::new(r"^NULL$|^$").unwrap());
Review Comment:
I think it might make sense to make it an configuration regardless if there is a performance degradation or not. This is because the new behavior will be a breaking change and potentially undesired behavior for some users.
--
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] Support 'NULL' as Null in csv parser. [datafusion]
Posted by "dhegberg (via GitHub)" <gi...@apache.org>.
dhegberg commented on PR #13228:
URL: https://github.com/apache/datafusion/pull/13228#issuecomment-2547489191
@jayzhan211 @alamb
I've revised this to set the null import via config.
Shows a small regression when this config is used, but it should be acceptable since this is opt in.
--
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] Support 'NULL' as Null in csv parser. [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #13228:
URL: https://github.com/apache/datafusion/pull/13228#discussion_r1828267500
##########
datafusion/core/src/datasource/file_format/csv.rs:
##########
@@ -454,7 +455,9 @@ impl CsvFormat {
.has_header
.unwrap_or(state.config_options().catalog.has_header),
)
- .with_delimiter(self.options.delimiter);
+ .with_delimiter(self.options.delimiter)
+ // Support literal NULL or empty string as null
+ .with_null_regex(Regex::new(r"^NULL$|^$").unwrap());
Review Comment:
A configuration option makes sense to me
I poked around for a csv querying benchmark and I can't find one. Perhaps we should write one 🤔 I don't know if this would have any effect
--
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] Support 'NULL' as Null in csv parser. [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #13228:
URL: https://github.com/apache/datafusion/pull/13228#issuecomment-2457680651
Marking as draft so we don't accidentally merge this
--
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] Support 'NULL' as Null in csv parser. [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #13228:
URL: https://github.com/apache/datafusion/pull/13228#discussion_r1829686601
##########
datafusion/core/src/datasource/file_format/csv.rs:
##########
@@ -454,7 +455,9 @@ impl CsvFormat {
.has_header
.unwrap_or(state.config_options().catalog.has_header),
)
- .with_delimiter(self.options.delimiter);
+ .with_delimiter(self.options.delimiter)
+ // Support literal NULL or empty string as null
+ .with_null_regex(Regex::new(r"^NULL$|^$").unwrap());
Review Comment:
Agreed -- thank you @dhegberg
--
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] Support 'NULL' as Null in csv parser. [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #13228:
URL: https://github.com/apache/datafusion/pull/13228#discussion_r1826960596
##########
datafusion/core/src/datasource/file_format/csv.rs:
##########
@@ -454,7 +455,8 @@ impl CsvFormat {
.has_header
.unwrap_or(state.config_options().catalog.has_header),
)
- .with_delimiter(self.options.delimiter);
+ .with_delimiter(self.options.delimiter)
+ .with_null_regex(Regex::new(r"^NULL$|^$").unwrap());
Review Comment:
```suggestion
// Support literal NULL or empty string as null
.with_null_regex(Regex::new(r"^NULL$|^$").unwrap());
```
##########
datafusion/core/Cargo.toml:
##########
@@ -127,6 +127,7 @@ parquet = { workspace = true, optional = true, default-features = true }
paste = "1.0.15"
pin-project-lite = "^0.2.7"
rand = { workspace = true }
+regex = { workspace = true }
Review Comment:
I believe this is not a new actual dependency as it is already a dependency of `arrow-csv`
--
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] Support 'NULL' as Null in csv parser. [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #13228:
URL: https://github.com/apache/datafusion/pull/13228#issuecomment-2552456288
🚀
--
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] Support 'NULL' as Null in csv parser. [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #13228:
URL: https://github.com/apache/datafusion/pull/13228#discussion_r1828267500
##########
datafusion/core/src/datasource/file_format/csv.rs:
##########
@@ -454,7 +455,9 @@ impl CsvFormat {
.has_header
.unwrap_or(state.config_options().catalog.has_header),
)
- .with_delimiter(self.options.delimiter);
+ .with_delimiter(self.options.delimiter)
+ // Support literal NULL or empty string as null
+ .with_null_regex(Regex::new(r"^NULL$|^$").unwrap());
Review Comment:
A configuration option makes sense to me
I poked around for a csv querying benchmark and I can't find one. Perhaps we should write one 🤔
--
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] Support 'NULL' as Null in csv parser. [datafusion]
Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan commented on code in PR #13228:
URL: https://github.com/apache/datafusion/pull/13228#discussion_r1827361232
##########
datafusion/core/src/datasource/file_format/csv.rs:
##########
@@ -454,7 +455,9 @@ impl CsvFormat {
.has_header
.unwrap_or(state.config_options().catalog.has_header),
)
- .with_delimiter(self.options.delimiter);
+ .with_delimiter(self.options.delimiter)
+ // Support literal NULL or empty string as null
+ .with_null_regex(Regex::new(r"^NULL$|^$").unwrap());
Review Comment:
Shouldn't this be a configuration option instead?
Most csv writers will use an empty string (`,,`) for null which also makes sense as default.
Having the regex enabled might also impact performance?
--
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] Support 'NULL' as Null in csv parser. [datafusion]
Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan commented on code in PR #13228:
URL: https://github.com/apache/datafusion/pull/13228#discussion_r1828834929
##########
datafusion/core/src/datasource/file_format/csv.rs:
##########
@@ -454,7 +455,9 @@ impl CsvFormat {
.has_header
.unwrap_or(state.config_options().catalog.has_header),
)
- .with_delimiter(self.options.delimiter);
+ .with_delimiter(self.options.delimiter)
+ // Support literal NULL or empty string as null
+ .with_null_regex(Regex::new(r"^NULL$|^$").unwrap());
Review Comment:
Sounds like a good plan to me!
--
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] Support 'NULL' as Null in csv parser. [datafusion]
Posted by "dhegberg (via GitHub)" <gi...@apache.org>.
dhegberg commented on PR #13228:
URL: https://github.com/apache/datafusion/pull/13228#issuecomment-2452780895
@alamb These tests will fail until the associated data changes are merged: https://github.com/apache/arrow-testing/pull/103
Let me know if there is a preferred way of setting up tests for these 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] Support 'NULL' as Null in csv parser. [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on PR #13228:
URL: https://github.com/apache/datafusion/pull/13228#issuecomment-2452747957
I think we can also add such test under `datafusion/core/tests/data/`
--
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] Support 'NULL' as Null in csv parser. [datafusion]
Posted by "dhegberg (via GitHub)" <gi...@apache.org>.
dhegberg commented on code in PR #13228:
URL: https://github.com/apache/datafusion/pull/13228#discussion_r1828539119
##########
datafusion/core/src/datasource/file_format/csv.rs:
##########
@@ -454,7 +455,9 @@ impl CsvFormat {
.has_header
.unwrap_or(state.config_options().catalog.has_header),
)
- .with_delimiter(self.options.delimiter);
+ .with_delimiter(self.options.delimiter)
+ // Support literal NULL or empty string as null
+ .with_null_regex(Regex::new(r"^NULL$|^$").unwrap());
Review Comment:
So, to confirm:
I'll open up a separate PR to implement a benchmark.
When that gets merged I'll update this PR to use a configuration option and add the new config to the benchmark test to confirm if there is a regression.
--
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