Repository: apache/arrow
File: cpp/src/parquet/column_writer_test.cc (C++)

Code before:

  ColumnProperties column_properties;
  column_properties.set_bloom_filter_options(BloomFilterOptions{SMALL_SIZE, 0.05});

  auto writer = this->BuildWriter(SMALL_SIZE, column_properties);
  writer->WriteBatch(this->values_.size(), nullptr, nullptr, this->values_ptr_);
  writer->Close();

  // Make sure that column values are read correctly
  this->SetupValuesOut(SMALL_SIZE);
  this->ReadColumnFully();
  ASSERT_EQ(SMALL_SIZE, this->values_read_);
  ASSERT_EQ(this->values_, this->values_out_);

  // Verify values are found by bloom filter
  for (auto& value : this->values_) {
    if constexpr (std::is_same_v<TypeParam, FLBAType>) {
      EXPECT_TRUE(this->bloom_filter_->FindHash(
          this->bloom_filter_->Hash(&value, this->descr_->type_length())));
    } else {
      EXPECT_TRUE(this->bloom_filter_->FindHash(this->bloom_filter_->Hash(value)));
    }
  }
}

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;

Review comment (suggestion):
I'm not sure if this is the right place to add this test. It seems that `column_writer_test.cc` does not deal with writing Arrow arrays. Is it better to move it to the `arrow_reader_writer_test.cc` by manually creating an Arrow array with all null values and null value buffer? In that approach, we don't need to deal with boilerplate like `ColumnChunkMetaDataBuilder`, `PageWriter` and `ColumnWriter` below. BTW, we can also use `TEST` instead of `TEST_F` with class definition because we only have one case here.

Code after:
                                              DoubleType, ByteArrayType, FLBAType>;

TYPED_TEST_SUITE(TestBloomFilterWriter, TestBloomFilterTypes);

TYPED_TEST(TestBloomFilterWriter, Basic) {
  this->GenerateData(SMALL_SIZE);

  ColumnProperties column_properties;
  column_properties.set_bloom_filter_options(BloomFilterOptions{SMALL_SIZE, 0.05});

  auto writer = this->BuildWriter(SMALL_SIZE, column_properties);
  writer->WriteBatch(this->values_.size(), nullptr, nullptr, this->values_ptr_);
  writer->Close();

  // Make sure that column values are read correctly
  this->SetupValuesOut(SMALL_SIZE);
  this->ReadColumnFully();
  ASSERT_EQ(SMALL_SIZE, this->values_read_);
  ASSERT_EQ(this->values_, this->values_out_);

  // Verify values are found by bloom filter
  for (auto& value : this->values_) {
    if constexpr (std::is_same_v<TypeParam, FLBAType>) {
      EXPECT_TRUE(this->bloom_filter_->FindHash(
          this->bloom_filter_->Hash(&value, this->descr_->type_length())));
    } else {
      EXPECT_TRUE(this->bloom_filter_->FindHash(this->bloom_filter_->Hash(value)));
    }
  }
}

}  // namespace test
}  // namespace parquet