hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hashut...@apache.org
Subject svn commit: r1506218 - /hive/branches/vectorization/ql/src/java/org/apache/hadoop/hive/ql/io/orc/RecordReaderImpl.java
Date Tue, 23 Jul 2013 19:07:07 GMT
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;
         }
       }
 



Mime
View raw message