Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4.3k
GH-42971: [C++] Parquet stream writer: Allow writing BYTE_ARRAY with converted type NONE#44739
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
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -26,6 +26,8 @@ | ||
| #include <string_view> | ||
| #include <vector> | ||
| #include "arrow/util/span.h" | ||
| #include "parquet/column_writer.h" | ||
| #include "parquet/file_writer.h" | ||
| @@ -151,6 +153,12 @@ class PARQUET_EXPORT StreamWriter { | ||
| StreamWriter& operator<<(const std::string& v); | ||
| StreamWriter& operator<<(::std::string_view v); | ||
| /// \brief Helper class to write variable length raw data. | ||
| using RawDataView = ::arrow::util::span<const uint8_t>; | ||
| /// \brief Output operators for variable length raw data. | ||
pulkomandy marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| StreamWriter& operator<<(RawDataView v); | ||
| /// \brief Output operator for optional fields. | ||
| template <typename T> | ||
| StreamWriter& operator<<(const optional<T>& v) { | ||
| @@ -190,7 +198,8 @@ class PARQUET_EXPORT StreamWriter { | ||
| return *this; | ||
| } | ||
| StreamWriter& WriteVariableLength(const char* data_ptr, std::size_t data_len); | ||
| StreamWriter& WriteVariableLength(const char* data_ptr, std::size_t data_len, | ||
| ConvertedType::type converted_type); | ||
| StreamWriter& WriteFixedLength(const char* data_ptr, std::size_t data_len); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -80,6 +80,9 @@ class TestStreamWriter : public ::testing::Test { | ||
| fields.push_back(schema::PrimitiveNode::Make("double_field", Repetition::REQUIRED, | ||
| Type::DOUBLE, ConvertedType::NONE)); | ||
| fields.push_back(schema::PrimitiveNode::Make("bytes_field", Repetition::REQUIRED, | ||
| Type::BYTE_ARRAY, ConvertedType::NONE)); | ||
| return std::static_pointer_cast<schema::GroupNode>( | ||
| schema::GroupNode::Make("schema", Repetition::REQUIRED, fields)); | ||
| } | ||
| @@ -99,7 +102,7 @@ TEST_F(TestStreamWriter, DefaultConstructed) { | ||
| EXPECT_EQ(0, os.current_column()); | ||
| EXPECT_EQ(0, os.current_row()); | ||
| EXPECT_EQ(0, os.num_columns()); | ||
| EXPECT_EQ(0, os.SkipColumns(10)); | ||
| EXPECT_EQ(0, os.SkipColumns(11)); | ||
| } | ||
| TEST_F(TestStreamWriter, TypeChecking) { | ||
| @@ -162,6 +165,17 @@ TEST_F(TestStreamWriter, TypeChecking) { | ||
| EXPECT_THROW(writer_ << 5.4f, ParquetException); | ||
| EXPECT_NO_THROW(writer_ << 5.4); | ||
| // Required type: Variable length byte array. | ||
| // Strings and naked char* are rejected because they should use UTF8 instead of None | ||
| // type. | ||
| EXPECT_EQ(10, writer_.current_column()); | ||
| EXPECT_THROW(writer_ << 5, ParquetException); | ||
| EXPECT_THROW(writer_ << char3_array, ParquetException); | ||
| EXPECT_THROW(writer_ << char4_array, ParquetException); | ||
| EXPECT_THROW(writer_ << char5_array, ParquetException); | ||
pitrou marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| EXPECT_THROW(writer_ << std::string("not ok"), ParquetException); | ||
| EXPECT_NO_THROW(writer_ << StreamWriter::RawDataView((uint8_t*)"\xff\0ok", 4)); | ||
| EXPECT_EQ(0, writer_.current_row()); | ||
| EXPECT_NO_THROW(writer_ << EndRow); | ||
| EXPECT_EQ(1, writer_.current_row()); | ||
| @@ -210,6 +224,11 @@ TEST_F(TestStreamWriter, RequiredFieldChecking) { | ||
| EXPECT_THROW(writer_ << optional<double>(), ParquetException); | ||
| EXPECT_NO_THROW(writer_ << optional<double>(5.4)); | ||
| // Required field of type: Variable length byte array. | ||
| EXPECT_THROW(writer_ << optional<StreamWriter::RawDataView>(), ParquetException); | ||
| EXPECT_NO_THROW( | ||
| writer_ << std::make_optional<StreamWriter::RawDataView>((uint8_t*)"ok", 2)); | ||
| EXPECT_NO_THROW(writer_ << EndRow); | ||
| } | ||
| @@ -234,6 +253,7 @@ TEST_F(TestStreamWriter, EndRow) { | ||
| EXPECT_NO_THROW(writer_ << uint64_t((1ull << 60) + 123)); | ||
| EXPECT_NO_THROW(writer_ << 25.4f); | ||
| EXPECT_NO_THROW(writer_ << 3.3424); | ||
| EXPECT_NO_THROW(writer_ << StreamWriter::RawDataView((uint8_t*)"ok", 2)); | ||
| // Correct use of end row after all fields have been output. | ||
| EXPECT_NO_THROW(writer_ << EndRow); | ||
| EXPECT_EQ(1, writer_.current_row()); | ||
| @@ -272,6 +292,10 @@ TEST_F(TestStreamWriter, EndRowGroup) { | ||
| EXPECT_NO_THROW(writer_ << uint64_t((1ull << 60) - i * i)) << "index: " << i; | ||
| EXPECT_NO_THROW(writer_ << 42325.4f / float(i + 1)) << "index: " << i; | ||
| EXPECT_NO_THROW(writer_ << 3.2342e5 / double(i + 1)) << "index: " << i; | ||
| std::string tmpString = std::to_string(i); | ||
| EXPECT_NO_THROW(writer_ << StreamWriter::RawDataView((uint8_t*)tmpString.c_str(), | ||
| tmpString.length())) | ||
| << "index: " << i; | ||
| EXPECT_NO_THROW(writer_ << EndRow) << "index: " << i; | ||
| if (i % 1000 == 0) { | ||
| @@ -293,7 +317,8 @@ TEST_F(TestStreamWriter, SkipColumns) { | ||
| writer_ << true << std::string("Cannot skip mandatory columns"); | ||
| EXPECT_THROW(writer_.SkipColumns(1), ParquetException); | ||
| writer_ << 'x' << std::array<char, 4>{'A', 'B', 'C', 'D'} << int8_t(2) << uint16_t(3) | ||
| << int32_t(4) << uint64_t(5) << 6.0f << 7.0; | ||
| << int32_t(4) << uint64_t(5) << 6.0f << 7.0 | ||
| << StreamWriter::RawDataView((uint8_t*)"ok", 2); | ||
| writer_ << EndRow; | ||
| } | ||
| @@ -304,7 +329,8 @@ TEST_F(TestStreamWriter, AppendNotImplemented) { | ||
| writer_ = StreamWriter{ParquetFileWriter::Open(outfile, GetSchema())}; | ||
| writer_ << false << std::string("Just one row") << 'x' | ||
| << std::array<char, 4>{'A', 'B', 'C', 'D'} << int8_t(2) << uint16_t(3) | ||
| << int32_t(4) << uint64_t(5) << 6.0f << 7.0; | ||
| << int32_t(4) << uint64_t(5) << 6.0f << 7.0 | ||
| << StreamWriter::RawDataView((uint8_t*)"ok", 2); | ||
| writer_ << EndRow; | ||
| writer_ = StreamWriter{}; | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.