You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@orc.apache.org by om...@apache.org on 2017/09/26 19:35:05 UTC

orc git commit: ORC-226 Support getWriterId in c++ reader interface

Repository: orc
Updated Branches:
  refs/heads/master c15108310 -> 83983a2bd


ORC-226 Support getWriterId in c++ reader interface

Add getWriterIdValue() and getWriterId() to obtain Orc file writer id
through reader.

Fixes #151

Change-Id: I77b8165cadc65c55f64242bac07a7c63d2e898e4
Signed-off-by: Owen O'Malley <om...@apache.org>


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

Branch: refs/heads/master
Commit: 83983a2bd5df2f0aa3101288fbb3702e3a858e58
Parents: c151083
Author: Xiening.Dai <xn...@live.com>
Authored: Wed Sep 20 12:14:01 2017 -0700
Committer: Owen O'Malley <om...@apache.org>
Committed: Tue Sep 26 12:33:57 2017 -0700

----------------------------------------------------------------------
 c++/include/orc/Common.hh |  7 +++++++
 c++/include/orc/Reader.hh | 12 ++++++++++++
 c++/src/Reader.cc         | 20 ++++++++++++++++++++
 c++/src/Reader.hh         |  4 ++++
 c++/src/Writer.cc         |  8 ++------
 c++/test/TestWriter.cc    |  4 ++++
 6 files changed, 49 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/orc/blob/83983a2b/c++/include/orc/Common.hh
----------------------------------------------------------------------
diff --git a/c++/include/orc/Common.hh b/c++/include/orc/Common.hh
index afe075b..fc413d5 100644
--- a/c++/include/orc/Common.hh
+++ b/c++/include/orc/Common.hh
@@ -63,6 +63,13 @@ namespace orc {
     std::string toString() const;
   };
 
+  enum WriterId {
+    ORC_JAVA_WRITER = 0,
+    ORC_CPP_WRITER = 1,
+    PRESTO_WRITER = 2,
+    UNKNOWN_WRITER = INT32_MAX
+  };
+
   enum CompressionKind {
     CompressionKind_NONE = 0,
     CompressionKind_ZLIB = 1,

http://git-wip-us.apache.org/repos/asf/orc/blob/83983a2b/c++/include/orc/Reader.hh
----------------------------------------------------------------------
diff --git a/c++/include/orc/Reader.hh b/c++/include/orc/Reader.hh
index a004e46..b5e2e7e 100644
--- a/c++/include/orc/Reader.hh
+++ b/c++/include/orc/Reader.hh
@@ -288,6 +288,18 @@ namespace orc {
     virtual uint64_t getCompressionSize() const = 0;
 
     /**
+     * Get ID of writer that generated the file.
+     * @return UNKNOWN_WRITER if the writer ID is undefined
+     */
+    virtual WriterId getWriterId() const = 0;
+
+    /**
+     * Get the writer id value when getWriterId() returns an unknown writer.
+     * @return the integer value of the writer ID.
+     */
+    virtual uint32_t getWriterIdValue() const = 0;
+
+    /**
      * Get the version of the writer.
      * @return the version of the writer.
      */

http://git-wip-us.apache.org/repos/asf/orc/blob/83983a2b/c++/src/Reader.cc
----------------------------------------------------------------------
diff --git a/c++/src/Reader.cc b/c++/src/Reader.cc
index 113f759..92f5f21 100644
--- a/c++/src/Reader.cc
+++ b/c++/src/Reader.cc
@@ -417,6 +417,26 @@ namespace orc {
     return footer->numberofrows();
   }
 
+  WriterId ReaderImpl::getWriterId() const {
+    if (footer->has_writer()) {
+      uint32_t id = footer->writer();
+      if (id > WriterId::PRESTO_WRITER) {
+        return WriterId::UNKNOWN_WRITER;
+      } else {
+	return static_cast<WriterId>(id);
+      }
+    }
+    return WriterId::ORC_JAVA_WRITER;
+  }
+
+  uint32_t ReaderImpl::getWriterIdValue() const {
+    if (footer->has_writer()) {
+      return footer->writer();
+    } else {
+      return WriterId::ORC_JAVA_WRITER;
+    }
+  }
+
   WriterVersion ReaderImpl::getWriterVersion() const {
     if (!contents->postscript->has_writerversion()) {
       return WriterVersion_ORIGINAL;

http://git-wip-us.apache.org/repos/asf/orc/blob/83983a2b/c++/src/Reader.hh
----------------------------------------------------------------------
diff --git a/c++/src/Reader.hh b/c++/src/Reader.hh
index cd54cbb..e4e0942 100644
--- a/c++/src/Reader.hh
+++ b/c++/src/Reader.hh
@@ -216,6 +216,10 @@ namespace orc {
 
     FileVersion getFormatVersion() const override;
 
+    WriterId getWriterId() const override;
+
+    uint32_t getWriterIdValue() const override;
+
     WriterVersion getWriterVersion() const override;
 
     uint64_t getNumberOfRows() const override;

http://git-wip-us.apache.org/repos/asf/orc/blob/83983a2b/c++/src/Writer.cc
----------------------------------------------------------------------
diff --git a/c++/src/Writer.cc b/c++/src/Writer.cc
index 3603f94..a4ae090 100644
--- a/c++/src/Writer.cc
+++ b/c++/src/Writer.cc
@@ -205,7 +205,7 @@ namespace orc {
     proto::Metadata metadata;
 
     static const char* magicId;
-    static const uint32_t writerId;
+    static const WriterId writerId;
 
   public:
     WriterImpl(
@@ -234,11 +234,7 @@ namespace orc {
 
   const char * WriterImpl::magicId = "ORC";
 
-  // Identification for C++ Orc writer
-  // 0 = ORC Java
-  // 1 = ORC C++
-  // 2 = Presto
-  const uint32_t WriterImpl::writerId = 1;
+  const WriterId WriterImpl::writerId = WriterId::ORC_CPP_WRITER;
 
   WriterImpl::WriterImpl(
                          const Type& t,

http://git-wip-us.apache.org/repos/asf/orc/blob/83983a2b/c++/test/TestWriter.cc
----------------------------------------------------------------------
diff --git a/c++/test/TestWriter.cc b/c++/test/TestWriter.cc
index 79a1d2d..3df4626 100644
--- a/c++/test/TestWriter.cc
+++ b/c++/test/TestWriter.cc
@@ -92,6 +92,10 @@ namespace orc {
     EXPECT_EQ(WriterVersion_ORC_135, reader->getWriterVersion());
     EXPECT_EQ(0, reader->getNumberOfRows());
 
+    WriterId writerId = WriterId::ORC_CPP_WRITER;
+    EXPECT_EQ(writerId, reader->getWriterId());
+    EXPECT_EQ(1, reader->getWriterIdValue());
+
     std::unique_ptr<ColumnVectorBatch> batch = rowReader->createRowBatch(1024);
     EXPECT_FALSE(rowReader->next(*batch));
   }