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

Code before:
  auto zstd_codec_options = std::make_shared<::arrow::util::ZstdCodecOptions>();
  zstd_codec_options->compression_level = 3;
  zstd_codec_options->cctx_params = {{ZSTD_c_windowLog, 23}};
  zstd_codec_options->dctx_params = {{ZSTD_d_windowLogMax, 23}};
  builder.codec_options("zstd", zstd_codec_options);
  builder.compression("brotli", Compression::BROTLI);
  auto gzip_codec_options = std::make_shared<::arrow::util::GZipCodecOptions>();
  gzip_codec_options->compression_level = 5;
  gzip_codec_options->window_bits = 12;
  builder.codec_options("gzip", gzip_codec_options);
  auto codec_options = std::make_shared<CodecOptions>();
  builder.codec_options(codec_options);
  auto brotli_codec_options = std::make_shared<::arrow::util::BrotliCodecOptions>();
  brotli_codec_options->compression_level = 11;
  brotli_codec_options->window_bits = 20;
  builder.codec_options("brotli", brotli_codec_options);
  std::shared_ptr<WriterProperties> props = builder.build();

  ASSERT_EQ(5,
            props->codec_options(ColumnPath::FromDotString("gzip"))->compression_level);
  ASSERT_EQ(12, std::dynamic_pointer_cast<::arrow::util::GZipCodecOptions>(
                    props->codec_options(ColumnPath::FromDotString("gzip")))
                    ->window_bits);
  ASSERT_EQ(3,
            props->codec_options(ColumnPath::FromDotString("zstd"))->compression_level);
  ASSERT_EQ(23, std::dynamic_pointer_cast<::arrow::util::ZstdCodecOptions>(
                    props->codec_options(ColumnPath::FromDotString("zstd")))
                    ->cctx_params[ZSTD_c_windowLog]);
  ASSERT_EQ(23, std::dynamic_pointer_cast<::arrow::util::ZstdCodecOptions>(
                    props->codec_options(ColumnPath::FromDotString("zstd")))
                    ->dctx_params[ZSTD_d_windowLogMax]);
  ASSERT_EQ(11,
            props->codec_options(ColumnPath::FromDotString("brotli"))->compression_level);
  ASSERT_EQ(20, std::dynamic_pointer_cast<::arrow::util::BrotliCodecOptions>(
                    props->codec_options(ColumnPath::FromDotString("brotli")))
                    ->window_bits);
}

TEST(TestWriterProperties, ContentDefinedChunkingSettings) {
  WriterProperties::Builder builder;
  std::shared_ptr<WriterProperties> props = builder.build();

  ASSERT_FALSE(props->content_defined_chunking_enabled());
  auto cdc_options = props->content_defined_chunking_options();
  ASSERT_EQ(cdc_options.min_chunk_size, 256 * 1024);
  ASSERT_EQ(cdc_options.max_chunk_size, 1024 * 1024);
  ASSERT_EQ(cdc_options.norm_level, 0);

  builder.enable_content_defined_chunking();
  builder.content_defined_chunking_options(CdcOptions{512 * 1024, 2048 * 1024, 1});
  props = builder.build();

Review comment (suggestion):
I'm not sure these additional tests are useful. It if works for `GZipCodecOptions`, then it will work for `ZstdCodecOptions` too.

Code after:
  builder.compression("gzip", Compression::GZIP);
  auto zstd_codec_options = std::make_shared<::arrow::util::ZstdCodecOptions>();
  zstd_codec_options->compression_context_params = {{ZSTD_c_windowLog, 23}};
  builder.codec_options("zstd", zstd_codec_options);
  builder.compression("brotli", Compression::BROTLI);
  auto gzip_codec_options = std::make_shared<::arrow::util::GZipCodecOptions>();
  gzip_codec_options->compression_level = 5;
  gzip_codec_options->window_bits = 12;
  builder.codec_options("gzip", gzip_codec_options);
  auto codec_options = std::make_shared<CodecOptions>();
  builder.codec_options(codec_options);
  auto brotli_codec_options = std::make_shared<::arrow::util::BrotliCodecOptions>();
  brotli_codec_options->compression_level = 11;
  brotli_codec_options->window_bits = 20;
  builder.codec_options("brotli", brotli_codec_options);
  std::shared_ptr<WriterProperties> props = builder.build();

  ASSERT_EQ(5,
            props->codec_options(ColumnPath::FromDotString("gzip"))->compression_level);
  ASSERT_EQ(12, std::dynamic_pointer_cast<::arrow::util::GZipCodecOptions>(
                    props->codec_options(ColumnPath::FromDotString("gzip")))
                    ->window_bits);
  ASSERT_EQ(Codec::UseDefaultCompressionLevel(),
            props->codec_options(ColumnPath::FromDotString("zstd"))->compression_level);
  ASSERT_EQ(11,
            props->codec_options(ColumnPath::FromDotString("brotli"))->compression_level);
  ASSERT_EQ(20, std::dynamic_pointer_cast<::arrow::util::BrotliCodecOptions>(
                    props->codec_options(ColumnPath::FromDotString("brotli")))
                    ->window_bits);
}

TEST(TestWriterProperties, ContentDefinedChunkingSettings) {
  WriterProperties::Builder builder;
  std::shared_ptr<WriterProperties> props = builder.build();

  ASSERT_FALSE(props->content_defined_chunking_enabled());
  auto cdc_options = props->content_defined_chunking_options();
  ASSERT_EQ(cdc_options.min_chunk_size, 256 * 1024);
  ASSERT_EQ(cdc_options.max_chunk_size, 1024 * 1024);
  ASSERT_EQ(cdc_options.norm_level, 0);

  builder.enable_content_defined_chunking();
  builder.content_defined_chunking_options(CdcOptions{512 * 1024, 2048 * 1024, 1});
  props = builder.build();
  ASSERT_TRUE(props->content_defined_chunking_enabled());
  cdc_options = props->content_defined_chunking_options();
  ASSERT_EQ(cdc_options.min_chunk_size, 512 * 1024);
  ASSERT_EQ(cdc_options.max_chunk_size, 2048 * 1024);
  ASSERT_EQ(cdc_options.norm_level, 1);
}