Skip to content

Commit 7ff0d80

Browse files
adamreevedgreiss
authored andcommitted
apacheGH-38039: [C++][Parquet] Fix segfault getting compression level 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 <[email protected]> Signed-off-by: Antoine Pitrou <[email protected]>
1 parent 4dca212 commit 7ff0d80

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

cpp/src/parquet/properties.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,12 @@ class PARQUET_EXPORT ColumnProperties {
196196

197197
size_t max_statistics_size() const { return max_stats_size_; }
198198

199-
int compression_level() const { return codec_options_->compression_level; }
199+
int compression_level() const {
200+
if (!codec_options_) {
201+
return ::arrow::util::kUseDefaultCompressionLevel;
202+
}
203+
return codec_options_->compression_level;
204+
}
200205

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

cpp/src/parquet/properties_test.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ TEST(TestWriterProperties, Basics) {
4949
ASSERT_FALSE(props->page_checksum_enabled());
5050
}
5151

52+
TEST(TestWriterProperties, DefaultCompression) {
53+
std::shared_ptr<WriterProperties> props = WriterProperties::Builder().build();
54+
55+
ASSERT_EQ(props->compression(ColumnPath::FromDotString("any")),
56+
Compression::UNCOMPRESSED);
57+
ASSERT_EQ(props->compression_level(ColumnPath::FromDotString("any")),
58+
::arrow::util::kUseDefaultCompressionLevel);
59+
}
60+
5261
TEST(TestWriterProperties, AdvancedHandling) {
5362
WriterProperties::Builder builder;
5463
builder.compression("gzip", Compression::GZIP);

0 commit comments

Comments
 (0)