Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions cpp/src/parquet/arrow/reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -735,10 +735,9 @@ class PARQUET_NO_EXPORT StructReader : public ColumnReaderImpl {
bool IsOrHasRepeatedChild() const final { return has_repeated_child_; }

Status LoadBatch(int64_t records_to_read) override {
for (const std::unique_ptr<ColumnReaderImpl>& reader : children_) {
RETURN_NOT_OK(reader->LoadBatch(records_to_read));
}
return Status::OK();
return ::arrow::internal::OptionalParallelFor(
ctx_->reader_properties->use_threads(), static_cast<int>(children_.size()),
[&](int i) { return children_[i]->LoadBatch(records_to_read); });
Comment on lines +738 to +740

@OmBiradar OmBiradar Jun 12, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

template <class FUNCTION>
Status OptionalParallelFor(bool use_threads, int num_tasks, FUNCTION&& func,
                           Executor* executor = internal::GetCpuThreadPool()) {
  if (use_threads) {
    return ParallelFor(num_tasks, std::forward<FUNCTION>(func), executor);
  } else {
    for (int i = 0; i < num_tasks; ++i) {
      RETURN_NOT_OK(func(i));
    }
    return Status::OK();
  }
}

At the end, it's always cast to an int so truncating is unavoidable.

}
Status BuildArray(int64_t length_upper_bound,
std::shared_ptr<ChunkedArray>* out) override;
Expand Down Expand Up @@ -825,10 +824,17 @@ Status StructReader::BuildArray(int64_t length_upper_bound,

END_PARQUET_CATCH_EXCEPTIONS
// Gather children arrays and def levels
for (auto& child : children_) {
std::shared_ptr<ChunkedArray> field;
RETURN_NOT_OK(child->BuildArray(validity_io.values_read, &field));
ARROW_ASSIGN_OR_RAISE(std::shared_ptr<ArrayData> array_data, ChunksToSingle(*field));
const int num_children = static_cast<int>(children_.size());

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

template <class FUNCTION>
Status OptionalParallelFor(bool use_threads, int num_tasks, FUNCTION&& func,
                           Executor* executor = internal::GetCpuThreadPool()) {
  if (use_threads) {
    return ParallelFor(num_tasks, std::forward<FUNCTION>(func), executor);
  } else {
    for (int i = 0; i < num_tasks; ++i) {
      RETURN_NOT_OK(func(i));
    }
    return Status::OK();
  }
}

At the end, it's always cast to an int so truncating is unavoidable.

std::vector<std::shared_ptr<ChunkedArray>> chunked_fields(num_children);

RETURN_NOT_OK(::arrow::internal::OptionalParallelFor(
ctx_->reader_properties->use_threads(), num_children, [&](int i) {
return children_[i]->BuildArray(validity_io.values_read, &chunked_fields[i]);
}));
children_array_data.reserve(num_children);
for (int i = 0; i < num_children; ++i) {
ARROW_ASSIGN_OR_RAISE(std::shared_ptr<ArrayData> array_data,
ChunksToSingle(*chunked_fields[i]));
children_array_data.push_back(std::move(array_data));
}

Expand Down