orc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From omal...@apache.org
Subject orc git commit: ORC-67 Fix for reading GMT timezone info on MacOS.
Date Tue, 07 Jun 2016 03:45:42 GMT
Repository: orc
Updated Branches:
  refs/heads/master 7db932dcc -> ab3f87caf


ORC-67 Fix for reading GMT timezone info on MacOS.

Fixes #35

Signed-off-by: Owen O'Malley <omalley@apache.org>


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

Branch: refs/heads/master
Commit: ab3f87caf26382a420272b4f5947adf56b5a81eb
Parents: 7db932d
Author: Owen O'Malley <omalley@apache.org>
Authored: Mon Jun 6 14:23:40 2016 -0700
Committer: Owen O'Malley <omalley@apache.org>
Committed: Mon Jun 6 20:36:43 2016 -0700

----------------------------------------------------------------------
 c++/src/Timezone.cc       | 19 +++++++++++++------
 c++/test/TestTimezone.cc  | 10 ++++++++++
 tools/src/CMakeLists.txt  | 17 +++++++++++++----
 tools/src/TimezoneDump.cc | 42 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 78 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/orc/blob/ab3f87ca/c++/src/Timezone.cc
----------------------------------------------------------------------
diff --git a/c++/src/Timezone.cc b/c++/src/Timezone.cc
index 9e6edf2..b342a6c 100644
--- a/c++/src/Timezone.cc
+++ b/c++/src/Timezone.cc
@@ -71,12 +71,16 @@ namespace orc {
   /**
    * Find the position that is the closest and less than or equal to the
    * target.
-   * @return -1 if the target < array[0] or
+   * @return -1 if the target < array[0] or array is empty or
    *          i if array[i] <= target and (i == n or array[i] < array[i+1])
    */
   int64_t binarySearch(const std::vector<int64_t> &array, int64_t target) {
+    uint64_t size = array.size();
+    if (size == 0) {
+      return -1;
+    }
     uint64_t min = 0;
-    uint64_t max = array.size() - 1;
+    uint64_t max = size - 1;
     uint64_t mid = (min + max) / 2;
     while ((array[mid] != target) && (min < max)) {
       if (array[mid] < target) {
@@ -899,11 +903,14 @@ namespace orc {
     if (clk > lastTransition) {
       return futureRule->getVariant(clk);
     } else {
-      int64_t idx = binarySearch(transitions, clk);
-      if (idx < 0) {
-        idx = static_cast<int64_t>(ancientVariant);
+      int64_t transition = binarySearch(transitions, clk);
+      uint64_t idx;
+      if (transition < 0) {
+        idx = ancientVariant;
+      } else {
+        idx = currentVariant[static_cast<size_t>(transition)];
       }
-      return variants[currentVariant[static_cast<size_t>(idx)]];
+      return variants[idx];
     }
   }
 

http://git-wip-us.apache.org/repos/asf/orc/blob/ab3f87ca/c++/test/TestTimezone.cc
----------------------------------------------------------------------
diff --git a/c++/test/TestTimezone.cc b/c++/test/TestTimezone.cc
index 13a14ee..15a72f3 100644
--- a/c++/test/TestTimezone.cc
+++ b/c++/test/TestTimezone.cc
@@ -42,6 +42,7 @@ namespace orc {
 
   TEST(TestTimezone, testBinarySearch) {
     std::vector<int64_t> vect;
+    EXPECT_EQ(-1, binarySearch(vect, 0));
     vect.push_back(0);
     EXPECT_EQ(-1, binarySearch(vect, -5));
     EXPECT_EQ(0, binarySearch(vect, 0));
@@ -358,4 +359,13 @@ namespace orc {
     EXPECT_EQ("EDT", getVariantFromZone(*ny1, "1974-10-27 05:59:59"));
     EXPECT_EQ("EST", getVariantFromZone(*ny1, "1974-10-27 06:00:00"));
   }
+
+  TEST(TestTimezone, testGMTv1) {
+    const char GMT[] = ("VFppZgAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAQAAAA"
+                        "AAAAAAAAAAAQAAAAQAAAAAAABHTVQAAAA=");
+    std::unique_ptr<Timezone> gmt = getTimezone("GMT", decodeBase64(GMT));
+    EXPECT_EQ(1, gmt->getVersion());
+    EXPECT_EQ("GMT", getVariantFromZone(*gmt, "1974-01-06 09:59:59"));
+    EXPECT_EQ("GMT", getVariantFromZone(*gmt, "2015-06-06 12:34:56"));
+  }
 }  // namespace orc

http://git-wip-us.apache.org/repos/asf/orc/blob/ab3f87ca/tools/src/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/tools/src/CMakeLists.txt b/tools/src/CMakeLists.txt
index dbdab85..0fc5f64 100644
--- a/tools/src/CMakeLists.txt
+++ b/tools/src/CMakeLists.txt
@@ -46,7 +46,7 @@ target_link_libraries (orc-metadata
   orc
   ${PROTOBUF_LIBRARIES}
   )
-  
+
  add_executable (orc-statistics
   FileStatistics.cc
   )
@@ -54,8 +54,8 @@ target_link_libraries (orc-metadata
 target_link_libraries (orc-statistics
   orc
   ${PROTOBUF_LIBRARIES}
-  ) 
-  
+  )
+
 add_executable (orc-memory
   FileMemory.cc
   )
@@ -63,7 +63,16 @@ add_executable (orc-memory
 target_link_libraries (orc-memory
   orc
   ${PROTOBUF_LIBRARIES}
-  )   
+  )
+
+add_executable (timezone-dump
+  TimezoneDump.cc
+  )
+
+target_link_libraries (timezone-dump
+  orc
+  ${PROTOBUF_LIBRARIES}
+  )
 
 install(TARGETS
    orc-contents

http://git-wip-us.apache.org/repos/asf/orc/blob/ab3f87ca/tools/src/TimezoneDump.cc
----------------------------------------------------------------------
diff --git a/tools/src/TimezoneDump.cc b/tools/src/TimezoneDump.cc
new file mode 100644
index 0000000..250caf1
--- /dev/null
+++ b/tools/src/TimezoneDump.cc
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Timezone.hh"
+
+#include "Exceptions.hh"
+
+#include <string>
+#include <memory>
+#include <iostream>
+#include <string>
+
+void printFile(const std::string &name) {
+  std::cout << "Timezone " << name << ":\n";
+  const orc::Timezone& tz = orc::getTimezoneByName(name);
+  tz.print(std::cout);
+}
+
+int main(int argc, char* argv[]) {
+  if (argc < 2) {
+    std::cout << "Usage: timezone-dump<filename>\n";
+  }
+  for(int o=1; o < argc; ++o) {
+    printFile(argv[o]);
+  }
+  return 0;
+}


Mime
View raw message