diff --git a/cpp/src/arrow/adapters/orc/adapter.cc b/cpp/src/arrow/adapters/orc/adapter.cc index 41bb7f25cbc1..7d3309e4e75b 100644 --- a/cpp/src/arrow/adapters/orc/adapter.cc +++ b/cpp/src/arrow/adapters/orc/adapter.cc @@ -837,7 +837,9 @@ class ORCFileWriter::Impl { } Status Close() { - writer_->close(); + if (writer_) { + writer_->close(); + } return Status::OK(); } diff --git a/cpp/src/arrow/adapters/orc/adapter_test.cc b/cpp/src/arrow/adapters/orc/adapter_test.cc index 8d2ad777cae1..6b9aa4740b4f 100644 --- a/cpp/src/arrow/adapters/orc/adapter_test.cc +++ b/cpp/src/arrow/adapters/orc/adapter_test.cc @@ -406,6 +406,23 @@ TEST(TestAdapterRead, ReadIntAndStringFileMultipleStripes) { // Trivial +class TestORCWriterTrivialNoWrite : public ::testing::Test {}; +TEST_F(TestORCWriterTrivialNoWrite, noWrite) { + EXPECT_OK_AND_ASSIGN(auto buffer_output_stream, + io::BufferOutputStream::Create(kDefaultSmallMemStreamSize / 16)); + auto write_options = adapters::orc::WriteOptions(); +#ifdef ARROW_WITH_SNAPPY + write_options.compression = Compression::SNAPPY; +#else + write_options.compression = Compression::UNCOMPRESSED; +#endif + write_options.file_version = adapters::orc::FileVersion(0, 11); + write_options.compression_block_size = 32768; + write_options.row_index_stride = 5000; + EXPECT_OK_AND_ASSIGN(auto writer, adapters::orc::ORCFileWriter::Open( + buffer_output_stream.get(), write_options)); + ARROW_EXPECT_OK(writer->Close()); +} class TestORCWriterTrivialNoConversion : public ::testing::Test { public: TestORCWriterTrivialNoConversion() { diff --git a/python/pyarrow/tests/test_orc.py b/python/pyarrow/tests/test_orc.py index abdd8bc11f9a..866cc01452bb 100644 --- a/python/pyarrow/tests/test_orc.py +++ b/python/pyarrow/tests/test_orc.py @@ -613,3 +613,24 @@ def test_column_selection(tempdir): with pytest.raises(ValueError): orc_file.read(columns=[5]) + + +def test_wrong_usage_orc_writer(tempdir): + from pyarrow import orc + + path = str(tempdir / 'test.orc') + with orc.ORCWriter(path) as writer: + with pytest.raises(AttributeError): + writer.test() + + +def test_orc_writer_with_null_arrays(tempdir): + from pyarrow import orc + import pyarrow as pa + + path = str(tempdir / 'test.orc') + a = pa.array([1, None, 3, None]) + b = pa.array([None, None, None, None]) + table = pa.table({"int64": a, "utf8": b}) + with pytest.raises(pa.ArrowNotImplementedError): + orc.write_table(table, path)