Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions c++/include/orc/Writer.hh
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ namespace orc {
* Close the write and flush any pending data to the output stream.
*/
virtual void close() = 0;

/**
* Add user metadata to the writer.
*/
virtual void addUserMetadata(const std::string name, const std::string value) = 0;
};
}

Expand Down
8 changes: 8 additions & 0 deletions c++/src/Writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ namespace orc {

void close() override;

void addUserMetadata(const std::string name, const std::string value) override;

private:
void init();
void initStripe();
Expand Down Expand Up @@ -323,6 +325,12 @@ namespace orc {
outStream->close();
}

void WriterImpl::addUserMetadata(const std::string name, const std::string value){
proto::UserMetadataItem* userMetadataItem = fileFooter.add_metadata();
userMetadataItem->set_name(name);
userMetadataItem->set_value(value);
}

void WriterImpl::init() {
// Write file header
outStream->write(WriterImpl::magicId, strlen(WriterImpl::magicId));
Expand Down
11 changes: 11 additions & 0 deletions c++/test/TestWriter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ namespace orc {
longBatch->numElements = 2000 - 1024;

writer->add(*batch);
writer->addUserMetadata("name0","value0");
writer->addUserMetadata("name1","value1");
writer->close();

std::unique_ptr<InputStream> inStream(
Expand All @@ -172,6 +174,15 @@ namespace orc {
EXPECT_TRUE(rowReader->next(*batch));
EXPECT_EQ(2000, batch->numElements);
EXPECT_FALSE(rowReader->next(*batch));

std::list<std::string> keys = reader->getMetadataKeys();
EXPECT_EQ(keys.size(), 2);
std::list<std::string>::const_iterator itr = keys.begin();
EXPECT_EQ(*itr, "name0");
EXPECT_EQ(reader->getMetadataValue(*itr), "value0");
itr++;
EXPECT_EQ(*itr, "name1");
EXPECT_EQ(reader->getMetadataValue(*itr), "value1");

for (uint64_t i = 0; i < 2000; ++i) {
structBatch = dynamic_cast<StructVectorBatch *>(batch.get());
Expand Down