TatianaJin commented on issue #38676:
URL: https://github.com/apache/arrow/issues/38676#issuecomment-2309628567
This problem extends to cases when we want to skip `(n-1)` lines in an
`n`-row block where the last line does not end with a new lline.
```cpp
#include <fstream>
#include <iostream>
#include <ostream>
#include <arrow/csv/api.h>
#include <arrow/filesystem/localfs.h>
int main() {
auto csv_file = "CSVReaderTest.csv";
{ // generate test file
std::ofstream ostream(csv_file);
// n = 4 lines
std::string data = "a,b\n0,1\n3,4\n5,6";
// no new line at the end
ostream.write(data.data(), data.size());
ostream.close();
}
// options
auto read_options = arrow::csv::ReadOptions::Defaults();
// skip n - 1 = 3 rows
read_options.skip_rows = 3;
read_options.autogenerate_column_names = true;
auto parse_options = arrow::csv::ParseOptions::Defaults();
auto convert_options = arrow::csv::ConvertOptions::Defaults();
auto arrow_fs = std::make_shared<::arrow::fs::LocalFileSystem>();
auto random_access_file = arrow_fs->OpenInputFile(csv_file).ValueOrDie();
// die on this statement
auto record_batch_reader =
arrow::csv::StreamingReader::Make(arrow::io::default_io_context(),
random_access_file,
read_options,
parse_options, convert_options)
.ValueOrDie();
std::cout << record_batch_reader->ToTable().ValueOrDie()->ToString() <<
std::endl;
return 0;
}
```
--
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]