Skip to content

Commit

Permalink
apacheGH-38039: [C++][Parquet] Fix segfault getting compression level…
Browse files Browse the repository at this point in the history
… for a Parquet column (apache#38025)

### Rationale for this change

After the changes in apache#35886, getting the compression level for a Parquet column segfaults if the compression level or other options weren't previously set

### What changes are included in this PR?

Adds a null check on the codec options of the column  properties before trying to access the compression level.

### Are these changes tested?

Yes, I added a unit test.

### Are there any user-facing changes?

This fixes a regression added after 13.0.0 so isn't a user-facing fix
* Closes: apache#38039

Authored-by: Adam Reeve <adreeve@gmail.com>
Signed-off-by: Antoine Pitrou <antoine@python.org>
  • Loading branch information
adamreeve authored and Jeremy Aguilon committed Oct 23, 2023
1 parent d9d22be commit ca241d1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cpp/src/parquet/properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,12 @@ class PARQUET_EXPORT ColumnProperties {

size_t max_statistics_size() const { return max_stats_size_; }

int compression_level() const { return codec_options_->compression_level; }
int compression_level() const {
if (!codec_options_) {
return ::arrow::util::kUseDefaultCompressionLevel;
}
return codec_options_->compression_level;
}

const std::shared_ptr<CodecOptions>& codec_options() const { return codec_options_; }

Expand Down
9 changes: 9 additions & 0 deletions cpp/src/parquet/properties_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ TEST(TestWriterProperties, Basics) {
ASSERT_FALSE(props->page_checksum_enabled());
}

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

ASSERT_EQ(props->compression(ColumnPath::FromDotString("any")),
Compression::UNCOMPRESSED);
ASSERT_EQ(props->compression_level(ColumnPath::FromDotString("any")),
::arrow::util::kUseDefaultCompressionLevel);
}

TEST(TestWriterProperties, AdvancedHandling) {
WriterProperties::Builder builder;
builder.compression("gzip", Compression::GZIP);
Expand Down

0 comments on commit ca241d1

Please sign in to comment.