mapleFU commented on issue #37840:
URL: https://github.com/apache/arrow/issues/37840#issuecomment-1734719908
```c++
arrow::Status status;
fs::FileSelector selector;
selector.base_dir = base_dir;
selector.recursive = true;
auto factory = ds::FileSystemDatasetFactory::Make(filesystem, selector,
format, ds::FileSystemFactoryOptions())
.ValueOrDie();
ds::FinishOptions finishOptions;
::arrow::SchemaBuilder builder;
auto s = builder.AddField(::arrow::field("dispatching_base_num",
::arrow::large_utf8()));
if (!s.ok()) {
s.Abort();
}
s =builder.AddField(::arrow::field("pickup_datetime",
::arrow::timestamp(::arrow::TimeUnit::SECOND)));
s =builder.AddField(::arrow::field("dropoff_datetime",
::arrow::timestamp(::arrow::TimeUnit::SECOND)));
s =builder.AddField(::arrow::field("PULocationID", ::arrow::int32()));
s =builder.AddField(::arrow::field("DOLocationID", ::arrow::int32()));
s =builder.AddField(::arrow::field("SR_Flag", ::arrow::int32()));
s =builder.AddField(::arrow::field("dispatching_base_number",
::arrow::large_utf8()));
if (!s.ok()) {
s.Abort();
}
finishOptions.schema = builder.Finish().ValueOrDie();
auto dataset = factory->Finish(finishOptions).ValueOrDie();
auto sb = dataset->NewScan().ValueOrDie();
s = sb->UseThreads(false);
if (!s.ok()) {
s.Abort();
}
auto scanner = sb->Finish().ValueOrDie();
{
// In this block I got total 57410540 rows
int64_t total_rows = 0;
if (scanner->options()->dataset_schema != nullptr) {
std::cout << "Schema: " <<
scanner->options()->dataset_schema->ToString() << std::endl;
} else {
std::cout << "Schema: " << "NONE" << std::endl;
}
status = scanner->Scan([&](ds::TaggedRecordBatch batch) -> arrow::Status
{
total_rows += batch.record_batch->num_rows();
return arrow::Status::OK();
});
std::cout << "total count rows in visitor mode = " << total_rows << ",
result:" << status.ToString() << "\n";
}
{
// In this block I got total 1526807659 rows
std::cout << "total count rows() = " <<
scanner->CountRows().ValueOrDie() << "\n";
}
return 0;
```
remember to check the `status` after computing
--
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]