Skip to content

Commit

Permalink
Add checks on all needed public operators
Browse files Browse the repository at this point in the history
  • Loading branch information
quanghgx committed Nov 15, 2023
1 parent 29fa161 commit e4508ff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cpp/src/parquet/arrow/arrow_reader_writer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5222,11 +5222,14 @@ TEST(TestArrowReadWrite, OperationsOnClosedWriter) {
// Should be ok
ASSERT_OK(writer->WriteTable(*table, 1));

// Operations on closed writer are incorrect. However, should not segfault
// Operations on closed writer are invalid
ASSERT_OK(writer->Close());

ASSERT_RAISES(Invalid, writer->NewBufferedRowGroup());
ASSERT_RAISES(Invalid, writer->NewRowGroup(1));
ASSERT_RAISES(Invalid, writer->WriteColumnChunk(table->column(0), 0, 1));
ASSERT_RAISES(Invalid, writer->NewBufferedRowGroup());
ASSERT_OK_AND_ASSIGN(auto record_batch, table->CombineChunksToBatch());
ASSERT_RAISES(Invalid, writer->WriteRecordBatch(*record_batch));
ASSERT_RAISES(Invalid, writer->WriteTable(*table, 1));
}

Expand Down
2 changes: 2 additions & 0 deletions cpp/src/parquet/arrow/writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ class FileWriterImpl : public FileWriter {

Status WriteColumnChunk(const std::shared_ptr<ChunkedArray>& data, int64_t offset,
int64_t size) override {
RETURN_NOT_OK(CheckClosed());
if (arrow_properties_->engine_version() == ArrowWriterProperties::V2 ||
arrow_properties_->engine_version() == ArrowWriterProperties::V1) {
if (row_group_writer_->buffered()) {
Expand Down Expand Up @@ -410,6 +411,7 @@ class FileWriterImpl : public FileWriter {
}

Status WriteRecordBatch(const RecordBatch& batch) override {
RETURN_NOT_OK(CheckClosed());
if (batch.num_rows() == 0) {
return Status::OK();
}
Expand Down

0 comments on commit e4508ff

Please sign in to comment.