You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ha...@apache.org on 2013/07/23 21:07:07 UTC

svn commit: r1506218 - /hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/io/orc/RecordReaderImpl.java

Author: hashutosh
Date: Tue Jul 23 19:07:07 2013
New Revision: 1506218

URL: http://svn.apache.org/r1506218
Log:
HIVE-4884 : ORC TimestampTreeReader.nextVector() off by a second when time in fractional (Gopal V via Ashutosh Chauhan)

Modified:
    hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/io/orc/RecordReaderImpl.java

Modified: hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/io/orc/RecordReaderImpl.java
URL: http://svn.apache.org/viewvc/hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/io/orc/RecordReaderImpl.java?rev=1506218&r1=1506217&r2=1506218&view=diff
==============================================================================
--- hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/io/orc/RecordReaderImpl.java (original)
+++ hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/io/orc/RecordReaderImpl.java Tue Jul 23 19:07:07 2013
@@ -809,12 +809,19 @@ class RecordReaderImpl implements Record
       // Non repeating values preset in the vector. Iterate thru the vector and populate the time
       for (int i = 0; i < batchSize; i++) {
         if (!result.isNull[i]) {
-          result.vector[i] = (result.vector[result.isRepeating ? 0 : i] + WriterImpl.BASE_TIMESTAMP)
+          long ms = (result.vector[result.isRepeating ? 0 : i] + WriterImpl.BASE_TIMESTAMP)
               * WriterImpl.MILLIS_PER_SECOND;
-          nanoVector.vector[i] = parseNanos(nanoVector.vector[nanoVector.isRepeating ? 0 : i]);
+          long ns = parseNanos(nanoVector.vector[nanoVector.isRepeating ? 0 : i]);
+          // the rounding error exists because java always rounds up when dividing integers
+          // -42001/1000 = -42; and -42001 % 1000 = -1 (+ 1000)
+          // to get the correct value we need
+          // (-42 - 1)*1000 + 999 = -42001
+          // (42)*1000 + 1 = 42001
+          if(ms < 0 && ns != 0) {
+            ms -= 1000;
+          }
           // Convert millis into nanos and add the nano vector value to it
-          // since we don't use sql.Timestamp, rounding errors don't apply here
-          result.vector[i] = (result.vector[i] * 1000000) + nanoVector.vector[i];
+          result.vector[i] = (ms * 1000000) + ns;
         }
       }