Skip to content

Commit

Permalink
Apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
mapleFU committed Aug 15, 2024
1 parent 96fc780 commit ab5cb56
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
9 changes: 7 additions & 2 deletions cpp/src/parquet/column_writer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1730,13 +1730,18 @@ TEST_F(TestInt32Writer, NoWriteKeyValueMetadata) {

TEST_F(TestInt32Writer, WriteKeyValueMetadata) {
auto writer = this->BuildWriter();
writer->AddKeyValueMetadata(KeyValueMetadata::Make({"hello"}, {"world"}));
writer->AddKeyValueMetadata(
KeyValueMetadata::Make({"hello", "bye"}, {"world", "earth"}));
// overwrite the previous value
writer->AddKeyValueMetadata(KeyValueMetadata::Make({"bye"}, {"moon"}));
writer->Close();
auto key_value_metadata = metadata_key_value_metadata();
ASSERT_THAT(key_value_metadata, NotNull());
ASSERT_EQ(1, key_value_metadata->size());
ASSERT_EQ(2, key_value_metadata->size());
ASSERT_OK_AND_ASSIGN(auto value, key_value_metadata->Get("hello"));
ASSERT_EQ("world", value);
ASSERT_OK_AND_ASSIGN(value, key_value_metadata->Get("bye"));
ASSERT_EQ("moon", value);
}

TEST_F(TestInt32Writer, ResetKeyValueMetadata) {
Expand Down
11 changes: 8 additions & 3 deletions cpp/src/parquet/metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,11 @@ std::shared_ptr<Statistics> MakeColumnStats(const format::ColumnMetaData& meta_d
throw ParquetException("Can't decode page statistics for selected column type");
}

// Get KeyValueMetadata from parquet Thrift RowGroup or ColumnChunk metadata.
//
// Returns nullptr if the metadata is not set.
template <typename Metadata>
std::shared_ptr<KeyValueMetadata> CopyKeyValueMetadata(const Metadata& source) {
std::shared_ptr<KeyValueMetadata> FromThriftKeyValueMetadata(const Metadata& source) {
std::shared_ptr<KeyValueMetadata> metadata = nullptr;
if (source.__isset.key_value_metadata) {
std::vector<std::string> keys;
Expand Down Expand Up @@ -380,7 +383,7 @@ class ColumnChunkMetaData::ColumnChunkMetaDataImpl {

private:
void InitKeyValueMetadata() {
key_value_metadata_ = CopyKeyValueMetadata(*column_metadata_);
key_value_metadata_ = FromThriftKeyValueMetadata(*column_metadata_);
}

mutable std::shared_ptr<Statistics> possible_stats_;
Expand Down Expand Up @@ -972,7 +975,9 @@ class FileMetaData::FileMetaDataImpl {
schema_.updateColumnOrders(column_orders);
}

void InitKeyValueMetadata() { key_value_metadata_ = CopyKeyValueMetadata(*metadata_); }
void InitKeyValueMetadata() {
key_value_metadata_ = FromThriftKeyValueMetadata(*metadata_);
}
};

std::shared_ptr<FileMetaData> FileMetaData::Make(
Expand Down

0 comments on commit ab5cb56

Please sign in to comment.