cyb70289 commented on code in PR #33656:
URL: https://github.com/apache/arrow/pull/33656#discussion_r1070246249


##########
cpp/src/parquet/properties.h:
##########
@@ -843,6 +863,9 @@ class PARQUET_EXPORT ArrowWriterProperties {
     bool store_schema_;
     bool compliant_nested_types_;
     EngineVersion engine_version_;
+
+    bool use_threads_;
+    ::arrow::internal::Executor* executor_;

Review Comment:
   Is `executor_` guaranteed to be initialized? 



##########
cpp/src/parquet/arrow/writer.cc:
##########
@@ -403,17 +410,31 @@ class FileWriterImpl : public FileWriter {
     }
 
     auto WriteBatch = [&](int64_t offset, int64_t size) {
+      std::vector<std::unique_ptr<ArrowColumnWriterV2>> writers;
+
       int column_index_start = 0;
       for (int i = 0; i < batch.num_columns(); i++) {
-        ChunkedArray chunkedArray(batch.column(i));
+        ChunkedArray chunkedArray{batch.column(i)};
         ARROW_ASSIGN_OR_RAISE(
             std::unique_ptr<ArrowColumnWriterV2> writer,
             ArrowColumnWriterV2::Make(chunkedArray, offset, size, 
schema_manifest_,
                                       row_group_writer_, column_index_start));
-        RETURN_NOT_OK(writer->Write(&column_write_context_));
         column_index_start += writer->leaf_count();
+        writers.emplace_back(std::move(writer));
       }
-      return Status::OK();
+
+      auto executor = arrow_properties_->executor() == nullptr
+                          ? ::arrow::internal::GetCpuThreadPool()
+                          : arrow_properties_->executor();
+
+      return ::arrow::internal::OptionalParallelFor(
+          arrow_properties_->use_threads(), static_cast<int>(writers.size()),
+          [&](int i) {
+            auto ctx = arrow_properties_->use_threads() ? 
&column_write_context_.at(i)
+                                                        : 
&column_write_context_.back();
+            return writers[i]->Write(ctx);
+          },
+          executor);

Review Comment:
   This code is a bit tedious IMO. Probably the code can be much simpler if it 
is only called for use-thead case.



##########
cpp/src/parquet/arrow/writer.cc:
##########
@@ -403,17 +410,31 @@ class FileWriterImpl : public FileWriter {
     }
 
     auto WriteBatch = [&](int64_t offset, int64_t size) {
+      std::vector<std::unique_ptr<ArrowColumnWriterV2>> writers;
+
       int column_index_start = 0;
       for (int i = 0; i < batch.num_columns(); i++) {
-        ChunkedArray chunkedArray(batch.column(i));
+        ChunkedArray chunkedArray{batch.column(i)};
         ARROW_ASSIGN_OR_RAISE(
             std::unique_ptr<ArrowColumnWriterV2> writer,
             ArrowColumnWriterV2::Make(chunkedArray, offset, size, 
schema_manifest_,
                                       row_group_writer_, column_index_start));
-        RETURN_NOT_OK(writer->Write(&column_write_context_));
         column_index_start += writer->leaf_count();
+        writers.emplace_back(std::move(writer));

Review Comment:
   I understand it's to unify use-thread and non-thread code, but it's looks 
not ideal to always create such a vector for non-thread case.



-- 
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]

Reply via email to