pitrou commented on code in PR #48692:
URL: https://github.com/apache/arrow/pull/48692#discussion_r2672584319


##########
cpp/src/parquet/column_writer_test.cc:
##########
@@ -2380,5 +2381,87 @@ TYPED_TEST(TestColumnWriterMaxRowsPerPage, 
RequiredLargeChunk) {
   }
 }
 
+class TestArrowWriteSerialize : public ::testing::Test {
+ public:
+  void SetUp() {
+    // Create a Parquet schema
+    // Int8 maps to Int32 in Parquet with INT_8 converted type
+    auto node = schema::PrimitiveNode::Make("int8_col", Repetition::OPTIONAL, 
Type::INT32,
+                                            ConvertedType::INT_8);
+    schema_descriptor_ = std::make_shared<ColumnDescriptor>(node, 1, 0);
+    sink_ = CreateOutputStream();
+    writer_properties_ = default_writer_properties();
+  }
+
+  std::shared_ptr<TypedColumnWriter<Int32Type>> BuildWriter() {
+    metadata_ =
+        ColumnChunkMetaDataBuilder::Make(writer_properties_, 
schema_descriptor_.get());
+    std::unique_ptr<PageWriter> pager =
+        PageWriter::Open(sink_, Compression::UNCOMPRESSED, metadata_.get());
+    std::shared_ptr<ColumnWriter> writer =
+        ColumnWriter::Make(metadata_.get(), std::move(pager), 
writer_properties_.get());
+    return std::static_pointer_cast<TypedColumnWriter<Int32Type>>(writer);
+  }
+
+  std::shared_ptr<TypedColumnReader<Int32Type>> BuildReader(int64_t num_rows) {
+    EXPECT_OK_AND_ASSIGN(auto buffer, sink_->Finish());
+    auto source = std::make_shared<::arrow::io::BufferReader>(buffer);
+    ReaderProperties reader_properties;
+    std::unique_ptr<PageReader> page_reader = PageReader::Open(
+        std::move(source), num_rows, Compression::UNCOMPRESSED, 
reader_properties);
+    std::shared_ptr<ColumnReader> reader =
+        ColumnReader::Make(schema_descriptor_.get(), std::move(page_reader));
+    return std::static_pointer_cast<TypedColumnReader<Int32Type>>(reader);
+  }
+
+ protected:
+  std::shared_ptr<ColumnDescriptor> schema_descriptor_;
+  std::shared_ptr<::arrow::io::BufferOutputStream> sink_;
+  std::shared_ptr<WriterProperties> writer_properties_;
+  std::unique_ptr<ColumnChunkMetaDataBuilder> metadata_;
+};
+
+TEST_F(TestArrowWriteSerialize, AllNulls) {
+  std::shared_ptr<::arrow::Buffer> null_bitmap;
+  ASSERT_OK_AND_ASSIGN(null_bitmap, ::arrow::AllocateBitmap(100));
+  // Set all bits to 0 (null)
+  ::arrow::bit_util::SetBitsTo(null_bitmap->mutable_data(), 0, 100, false);
+
+  std::shared_ptr<::arrow::Buffer> data_buffer = nullptr;

Review Comment:
   IIRC it's deliberate that a null buffer pointer is accepted there. I would 
rather not have this but it could break compatibility with existing usage.
   
   In any case, feel free to open a separate issue about it.



##########
cpp/src/parquet/column_writer_test.cc:
##########
@@ -2380,5 +2381,87 @@ TYPED_TEST(TestColumnWriterMaxRowsPerPage, 
RequiredLargeChunk) {
   }
 }
 
+class TestArrowWriteSerialize : public ::testing::Test {
+ public:
+  void SetUp() {
+    // Create a Parquet schema
+    // Int8 maps to Int32 in Parquet with INT_8 converted type
+    auto node = schema::PrimitiveNode::Make("int8_col", Repetition::OPTIONAL, 
Type::INT32,
+                                            ConvertedType::INT_8);
+    schema_descriptor_ = std::make_shared<ColumnDescriptor>(node, 1, 0);
+    sink_ = CreateOutputStream();
+    writer_properties_ = default_writer_properties();
+  }
+
+  std::shared_ptr<TypedColumnWriter<Int32Type>> BuildWriter() {
+    metadata_ =
+        ColumnChunkMetaDataBuilder::Make(writer_properties_, 
schema_descriptor_.get());
+    std::unique_ptr<PageWriter> pager =
+        PageWriter::Open(sink_, Compression::UNCOMPRESSED, metadata_.get());
+    std::shared_ptr<ColumnWriter> writer =
+        ColumnWriter::Make(metadata_.get(), std::move(pager), 
writer_properties_.get());
+    return std::static_pointer_cast<TypedColumnWriter<Int32Type>>(writer);
+  }
+
+  std::shared_ptr<TypedColumnReader<Int32Type>> BuildReader(int64_t num_rows) {
+    EXPECT_OK_AND_ASSIGN(auto buffer, sink_->Finish());
+    auto source = std::make_shared<::arrow::io::BufferReader>(buffer);
+    ReaderProperties reader_properties;
+    std::unique_ptr<PageReader> page_reader = PageReader::Open(
+        std::move(source), num_rows, Compression::UNCOMPRESSED, 
reader_properties);
+    std::shared_ptr<ColumnReader> reader =
+        ColumnReader::Make(schema_descriptor_.get(), std::move(page_reader));
+    return std::static_pointer_cast<TypedColumnReader<Int32Type>>(reader);
+  }
+
+ protected:
+  std::shared_ptr<ColumnDescriptor> schema_descriptor_;
+  std::shared_ptr<::arrow::io::BufferOutputStream> sink_;
+  std::shared_ptr<WriterProperties> writer_properties_;
+  std::unique_ptr<ColumnChunkMetaDataBuilder> metadata_;
+};
+
+TEST_F(TestArrowWriteSerialize, AllNulls) {
+  std::shared_ptr<::arrow::Buffer> null_bitmap;
+  ASSERT_OK_AND_ASSIGN(null_bitmap, ::arrow::AllocateBitmap(100));
+  // Set all bits to 0 (null)
+  ::arrow::bit_util::SetBitsTo(null_bitmap->mutable_data(), 0, 100, false);

Review Comment:
   You can just use `AllocateEmptyBitmap` which will zero-initialize the bitmap.



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