wgtmac commented on code in PR #55629:
URL: https://github.com/apache/arrow/pull/55629#discussion_r4643820725


##########
cpp/src/parquet/column_writer.cc:
##########
@@ -1338,7 +1345,14 @@ class TypedColumnWriterImpl : public ColumnWriterImpl,
           "Content-defined chunking is not supported in WriteBatch() or "
           "WriteBatchSpaced(), use WriteArrow() instead.");
     }
-    return WriteBatchInternal(num_values, def_levels, rep_levels, values);
+    if (closed_ || failed_) {
+      throw ParquetException("Cannot write to a closed or failed column 
writer");
+    }
+    failed_ = true;

Review Comment:
   Could we consolidate them in a small RAII guard? For example:
   
   ```cpp
   struct WriteGuard {
     bool& failed;
     bool succeeded = false;
   
     WriteGuard(bool closed, bool& failed) : failed(failed) {
       if (closed || failed) {
         throw ParquetStatusException(
             Status::Invalid("Cannot write to a closed or failed column 
writer"));
       }
       failed = true;
     }
   
     ~WriteGuard() { failed = !succeeded; }
   };
   ```
   
   `WriteBatch` and `WriteBatchSpaced` would use this guard and set `succeeded 
= true` after the internal call returns. For `WriteArrow`, we can do something 
like:
   
   ```cpp
   BEGIN_PARQUET_CATCH_EXCEPTIONS
   WriteGuard guard{closed_, failed_};
   auto status = WriteArrowInternal(...);
   guard.succeeded = status.ok();
   return status;
   END_PARQUET_CATCH_EXCEPTIONS
   ```



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