Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rust): use wrapping_add in csv line snooping #15109

Merged
merged 2 commits into from
Mar 18, 2024
Merged

fix(rust): use wrapping_add in csv line snooping #15109

merged 2 commits into from
Mar 18, 2024

Conversation

ritchie46
Copy link
Member

fixes #15101

@github-actions github-actions bot added fix Bug fix rust Related to Rust Polars labels Mar 17, 2024
Copy link

codecov bot commented Mar 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.08%. Comparing base (f8ade71) to head (ce5ed1d).
Report is 1 commits behind head on main.

❗ Current head ce5ed1d differs from pull request most recent head a95014e. Consider uploading reports for the commit a95014e to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15109      +/-   ##
==========================================
- Coverage   81.08%   81.08%   -0.01%     
==========================================
  Files        1342     1342              
  Lines      174112   174112              
  Branches     2459     2459              
==========================================
- Hits       141178   141174       -4     
- Misses      32467    32470       +3     
- Partials      467      468       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -153,7 +153,7 @@ pub(crate) fn next_line_position(
if rejected_line_groups >= 3 {
return None;
}
lines_checked += 1;
lines_checked = lines_checked.wrapping_add(1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we decrement expected fields at 256 lines, and afterwards we decrement it every 65536 lines? Since lines_checked is a u16.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good point. Should probably just use u8 here.

// headers might have an extra value
// So if we have churned through enough lines
// we try one field less.
if lines_checked == 256 {
if lines_checked == u8::MAX {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nit - this is off-by-one on before the first wrap-around 😆

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's fine. It is just a heuristic to try less fields after some reasonable attempts. Off by one is still reasonable. 😄

@ritchie46 ritchie46 merged commit ff85894 into main Mar 18, 2024
18 checks passed
@ritchie46 ritchie46 deleted the wrap branch March 18, 2024 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

attempt to add with overflow in CsvReader when file length is > 2^16
2 participants