You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@orc.apache.org by md...@apache.org on 2018/08/12 12:43:29 UTC

orc git commit: ORC-394: Add addUserMetadata() function to C++ write

Repository: orc
Updated Branches:
  refs/heads/master 114f10448 -> 2aa7e5248


ORC-394: Add addUserMetadata() function to C++ write

Fixes #300

Signed-off-by: Deepak Majeti <md...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/orc/repo
Commit: http://git-wip-us.apache.org/repos/asf/orc/commit/2aa7e524
Tree: http://git-wip-us.apache.org/repos/asf/orc/tree/2aa7e524
Diff: http://git-wip-us.apache.org/repos/asf/orc/diff/2aa7e524

Branch: refs/heads/master
Commit: 2aa7e52484b592702b5808f08134fa5bb1b4e665
Parents: 114f104
Author: zherui cao <zh...@hpe.com>
Authored: Thu Aug 9 23:54:25 2018 -0400
Committer: Deepak Majeti <md...@apache.org>
Committed: Sun Aug 12 08:42:44 2018 -0400

----------------------------------------------------------------------
 c++/include/orc/Writer.hh |  5 +++++
 c++/src/Writer.cc         |  8 ++++++++
 c++/test/TestWriter.cc    | 11 +++++++++++
 3 files changed, 24 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/orc/blob/2aa7e524/c++/include/orc/Writer.hh
----------------------------------------------------------------------
diff --git a/c++/include/orc/Writer.hh b/c++/include/orc/Writer.hh
index cdda922..1284c65 100644
--- a/c++/include/orc/Writer.hh
+++ b/c++/include/orc/Writer.hh
@@ -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;
   };
 }
 

http://git-wip-us.apache.org/repos/asf/orc/blob/2aa7e524/c++/src/Writer.cc
----------------------------------------------------------------------
diff --git a/c++/src/Writer.cc b/c++/src/Writer.cc
index 3a56360..fee3318 100644
--- a/c++/src/Writer.cc
+++ b/c++/src/Writer.cc
@@ -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();
@@ -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));

http://git-wip-us.apache.org/repos/asf/orc/blob/2aa7e524/c++/test/TestWriter.cc
----------------------------------------------------------------------
diff --git a/c++/test/TestWriter.cc b/c++/test/TestWriter.cc
index c3788d2..f7597e8 100644
--- a/c++/test/TestWriter.cc
+++ b/c++/test/TestWriter.cc
@@ -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(
@@ -173,6 +175,15 @@ namespace orc {
     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());
       longBatch = dynamic_cast<LongVectorBatch *>(structBatch->fields[0]);