-
Notifications
You must be signed in to change notification settings - Fork 106
fix(parquet): check compression codec availability #656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,9 @@ | |
| */ | ||
|
|
||
| #include <optional> | ||
| #include <string> | ||
| #include <utility> | ||
| #include <vector> | ||
|
|
||
| #include <arrow/array.h> | ||
| #include <arrow/c/bridge.h> | ||
|
|
@@ -26,6 +29,7 @@ | |
| #include <arrow/record_batch.h> | ||
| #include <arrow/table.h> | ||
| #include <arrow/type.h> | ||
| #include <arrow/util/compression.h> | ||
| #include <arrow/util/key_value_metadata.h> | ||
| #include <parquet/arrow/reader.h> | ||
| #include <parquet/arrow/writer.h> | ||
|
|
@@ -124,6 +128,27 @@ void DoRoundtrip(std::shared_ptr<::arrow::Array> data, std::shared_ptr<Schema> s | |
| ASSERT_TRUE(out != nullptr) << "Reader.Next() returned no data"; | ||
| } | ||
|
|
||
| struct ParquetCodec { | ||
| std::string name; | ||
| ::arrow::Compression::type compression; | ||
| }; | ||
|
|
||
| std::optional<ParquetCodec> UnavailableParquetCodec() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LGTM should this function return the list of unavailable codecs instead of the first one? Otherwise I feel like the name could be slightly misleading, maybe
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed the helper to |
||
| const std::vector<ParquetCodec> codecs = { | ||
| {.name = "snappy", .compression = ::arrow::Compression::SNAPPY}, | ||
| {.name = "gzip", .compression = ::arrow::Compression::GZIP}, | ||
| {.name = "brotli", .compression = ::arrow::Compression::BROTLI}, | ||
| {.name = "lz4", .compression = ::arrow::Compression::LZ4}, | ||
| {.name = "zstd", .compression = ::arrow::Compression::ZSTD}, | ||
| }; | ||
| for (const auto& codec : codecs) { | ||
| if (!::arrow::util::Codec::IsAvailable(codec.compression)) { | ||
| return codec; | ||
| } | ||
| } | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| class ParquetReaderTest : public TempFileTestBase { | ||
|
|
@@ -461,6 +486,29 @@ TEST_F(ParquetReadWrite, EmptyStruct) { | |
| IsError(ErrorKind::kNotImplemented)); | ||
| } | ||
|
|
||
| TEST_F(ParquetReadWrite, RejectsUnavailableCompressionCodec) { | ||
| auto unavailable_codec = UnavailableParquetCodec(); | ||
| if (!unavailable_codec.has_value()) { | ||
| GTEST_SKIP() << "All optional Parquet compression codecs are available"; | ||
| } | ||
|
|
||
| auto schema = std::make_shared<Schema>( | ||
| std::vector<SchemaField>{SchemaField::MakeRequired(1, "id", int32())}); | ||
| WriterProperties writer_properties; | ||
| writer_properties.Set(WriterProperties::kParquetCompression, unavailable_codec->name); | ||
|
|
||
| auto writer = WriterFactoryRegistry::Open( | ||
| FileFormatType::kParquet, {.path = "unavailable_codec.parquet", | ||
| .schema = schema, | ||
| .io = arrow::ArrowFileSystemFileIO::MakeMockFileIO(), | ||
| .properties = std::move(writer_properties)}); | ||
|
|
||
| EXPECT_THAT(writer, IsError(ErrorKind::kInvalidArgument)); | ||
| EXPECT_THAT(writer, | ||
| HasErrorMessage("Parquet compression codec " + unavailable_codec->name + | ||
| " is not available in the current build")); | ||
| } | ||
|
|
||
| TEST_F(ParquetReadWrite, SimpleStructRoundTrip) { | ||
| auto schema = std::make_shared<Schema>(std::vector<SchemaField>{ | ||
| SchemaField::MakeOptional(1, "a", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's unreachable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's reachable. The
returns were changed to assignments except the finalelsebranch. But I have no idea if that's a better style :-)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
ParseCompressionto use early returns again while keeping the availability check after parsing.