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

reader/csv: Use binary mode on Windows #2121

Merged
merged 1 commit into from
Sep 30, 2023
Merged

Conversation

Riolku
Copy link
Contributor

@Riolku Riolku commented Sep 30, 2023

On windows, when using open(), files are opened in Text mode by default. This causes automatic line conversion from \r\n to \n. We don't want this behaviour, and furthermore, it messes up our computation. If the file contents are abc\r\n and Windows is directed to read, it will return 4 bytes, abc\n. However, the file position as reported by lseek is 5, since we are five bytes into the file. This means we can miss rows if we get really unlucky with block offsets.

Specifying _O_BINARY makes windows use binary mode, which is most compatible with the linux behaviour. Our CSV reader is prepared to handle carriage returns anyway.

On windows, when using `open()`, files are opened in Text mode by
default. This causes automatic line conversion from `\r\n` to `\n`.
We don't want this behaviour, and furthermore, it messes up our
computation. If the file contents are `abc\r\n` and Windows is directed
to read, it will return 4 bytes, `abc\n`. However, the file position as
reported by `lseek` is 5, since we are five bytes into the file. This
means we can miss rows if we get really unlucky with block offsets.

Specifying `_O_BINARY` makes windows use binary mode, which is most
compatible with the linux behaviour. Our CSV reader is prepared to
handle carriage returns anyway.
@codecov
Copy link

codecov bot commented Sep 30, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (bc74559) 0.00% compared to head (45a2362) 89.75%.

Additional details and impacted files
@@             Coverage Diff             @@
##           master    #2121       +/-   ##
===========================================
+ Coverage        0   89.75%   +89.75%     
===========================================
  Files           0      986      +986     
  Lines           0    35559    +35559     
===========================================
+ Hits            0    31916    +31916     
- Misses          0     3643     +3643     
Files Coverage Δ
...operator/persistent/reader/csv/base_csv_reader.cpp 96.05% <100.00%> (ø)

... and 985 files with indirect coverage changes

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

@andyfengHKU andyfengHKU merged commit 23e43b3 into master Sep 30, 2023
10 of 11 checks passed
@andyfengHKU andyfengHKU deleted the windows-binary-mode branch September 30, 2023 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants