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 2020/01/24 17:49:41 UTC
[orc] branch branch-1.5 updated (ea20218 -> 8d4aeec)
This is an automated email from the ASF dual-hosted git repository.
omalley pushed a change to branch branch-1.5
in repository https://gitbox.apache.org/repos/asf/orc.git.
discard ea20218 orc tail statistics
discard 33f9d86 orc-578 fix schema conversions with proleptic dates/times.
new 7031f12 ORC-578: Fix schema conversions with proleptic dates/times.
new 8d4aeec ORC-578: Addendum fixing up the stripe statistics
This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version. This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:
* -- * -- B -- O -- O -- O (ea20218)
\
N -- N -- N refs/heads/branch-1.5 (8d4aeec)
You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.
Any revisions marked "omit" are not gone; other references still
refer to them. Any revisions marked "discard" are gone forever.
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
[orc] 02/02: ORC-578: Addendum fixing up the stripe statistics
Posted by om...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
omalley pushed a commit to branch branch-1.5
in repository https://gitbox.apache.org/repos/asf/orc.git
commit 8d4aeec23535bfb3732dde68a031c925e2418186
Author: Jesus Camacho Rodriguez <jc...@apache.org>
AuthorDate: Wed Jan 15 11:25:41 2020 -0800
ORC-578: Addendum fixing up the stripe statistics
Signed-off-by: Owen O'Malley <om...@apache.org>
---
.../core/src/java/org/apache/orc/StripeStatistics.java | 18 ++++++++----------
java/core/src/java/org/apache/orc/impl/OrcTail.java | 6 ++++--
java/core/src/java/org/apache/orc/impl/ReaderImpl.java | 3 ++-
.../src/java/org/apache/orc/impl/RecordReaderImpl.java | 13 +++++++++----
.../test/org/apache/orc/impl/TestRecordReaderImpl.java | 4 ++--
5 files changed, 25 insertions(+), 19 deletions(-)
diff --git a/java/core/src/java/org/apache/orc/StripeStatistics.java b/java/core/src/java/org/apache/orc/StripeStatistics.java
index 6fa5764..1e772a5 100644
--- a/java/core/src/java/org/apache/orc/StripeStatistics.java
+++ b/java/core/src/java/org/apache/orc/StripeStatistics.java
@@ -19,22 +19,23 @@
package org.apache.orc;
import org.apache.orc.impl.ColumnStatisticsImpl;
-import org.apache.orc.impl.ReaderImpl;
import java.util.List;
public class StripeStatistics {
private final List<OrcProto.ColumnStatistics> cs;
- private final ReaderImpl reader;
+ private final boolean writerUsedProlepticGregorian;
+ private final boolean convertToProlepticGregorian;
public StripeStatistics(List<OrcProto.ColumnStatistics> list) {
- this(list, null);
+ this(list, false, false);
}
public StripeStatistics(List<OrcProto.ColumnStatistics> list,
- ReaderImpl reader) {
+ boolean writerUsedProlepticGregorian, boolean convertToProlepticGregorian) {
this.cs = list;
- this.reader = reader;
+ this.writerUsedProlepticGregorian = writerUsedProlepticGregorian;
+ this.convertToProlepticGregorian = convertToProlepticGregorian;
}
/**
@@ -45,11 +46,8 @@ public class StripeStatistics {
public ColumnStatistics[] getColumnStatistics() {
ColumnStatistics[] result = new ColumnStatistics[cs.size()];
for (int i = 0; i < result.length; ++i) {
- if (reader == null) {
- result[i] = ColumnStatisticsImpl.deserialize(null, cs.get(i));
- } else {
- result[i] = ColumnStatisticsImpl.deserialize(null, cs.get(i), reader);
- }
+ result[i] = ColumnStatisticsImpl.deserialize(
+ null, cs.get(i), writerUsedProlepticGregorian, convertToProlepticGregorian);
}
return result;
}
diff --git a/java/core/src/java/org/apache/orc/impl/OrcTail.java b/java/core/src/java/org/apache/orc/impl/OrcTail.java
index 3c78874..d83d3ee 100644
--- a/java/core/src/java/org/apache/orc/impl/OrcTail.java
+++ b/java/core/src/java/org/apache/orc/impl/OrcTail.java
@@ -92,12 +92,14 @@ public final class OrcTail {
return (int) fileTail.getPostscript().getCompressionBlockSize();
}
- public List<StripeStatistics> getStripeStatistics() throws IOException {
+ public List<StripeStatistics> getStripeStatistics(
+ boolean writerUsedProlepticGregorian, boolean convertToProlepticGregorian)
+ throws IOException {
List<StripeStatistics> result = new ArrayList<>();
List<OrcProto.StripeStatistics> ssProto = getStripeStatisticsProto();
if (ssProto != null) {
for (OrcProto.StripeStatistics ss : ssProto) {
- result.add(new StripeStatistics(ss.getColStatsList()));
+ result.add(new StripeStatistics(ss.getColStatsList(), writerUsedProlepticGregorian, convertToProlepticGregorian));
}
}
return result;
diff --git a/java/core/src/java/org/apache/orc/impl/ReaderImpl.java b/java/core/src/java/org/apache/orc/impl/ReaderImpl.java
index 5a86440..34da133 100644
--- a/java/core/src/java/org/apache/orc/impl/ReaderImpl.java
+++ b/java/core/src/java/org/apache/orc/impl/ReaderImpl.java
@@ -834,7 +834,8 @@ public class ReaderImpl implements Reader {
}
List<StripeStatistics> result = new ArrayList<>();
for (OrcProto.StripeStatistics ss : stripeStats) {
- result.add(new StripeStatistics(ss.getColStatsList(), this));
+ result.add(new StripeStatistics(ss.getColStatsList(), writerUsedProlepticGregorian(),
+ options.getConvertToProlepticGregorian()));
}
return result;
}
diff --git a/java/core/src/java/org/apache/orc/impl/RecordReaderImpl.java b/java/core/src/java/org/apache/orc/impl/RecordReaderImpl.java
index b07dbb2..ad56732 100644
--- a/java/core/src/java/org/apache/orc/impl/RecordReaderImpl.java
+++ b/java/core/src/java/org/apache/orc/impl/RecordReaderImpl.java
@@ -457,7 +457,7 @@ public class RecordReaderImpl implements RecordReader {
OrcFile.WriterVersion writerVersion,
TypeDescription type) {
return evaluatePredicateProto(statsProto, predicate, kind, encoding, bloomFilter,
- writerVersion, type, false);
+ writerVersion, type, false, false, false);
}
/**
@@ -481,8 +481,11 @@ public class RecordReaderImpl implements RecordReader {
OrcProto.BloomFilter bloomFilter,
OrcFile.WriterVersion writerVersion,
TypeDescription type,
- boolean useUTCTimestamp) {
- ColumnStatistics cs = ColumnStatisticsImpl.deserialize(null, statsProto);
+ boolean useUTCTimestamp,
+ boolean writerUsedProlepticGregorian,
+ boolean convertToProlepticGregorian) {
+ ColumnStatistics cs = ColumnStatisticsImpl.deserialize(
+ null, statsProto, writerUsedProlepticGregorian, convertToProlepticGregorian);
Object minValue = getMin(cs, useUTCTimestamp);
Object maxValue = getMax(cs, useUTCTimestamp);
// files written before ORC-135 stores timestamp wrt to local timezone causing issues with PPD.
@@ -974,7 +977,9 @@ public class RecordReaderImpl implements RecordReader {
predicate, bfk, encodings.get(columnIx), bf,
writerVersion, evolution.getFileSchema().
findSubtype(columnIx),
- useUTCTimestamp);
+ useUTCTimestamp,
+ writerUsedProlepticGregorian,
+ convertToProlepticGregorian);
} catch (Exception e) {
exceptionCount[pred] += 1;
if (e instanceof SargCastException) {
diff --git a/java/core/src/test/org/apache/orc/impl/TestRecordReaderImpl.java b/java/core/src/test/org/apache/orc/impl/TestRecordReaderImpl.java
index 4c740c2..ab5b95f 100644
--- a/java/core/src/test/org/apache/orc/impl/TestRecordReaderImpl.java
+++ b/java/core/src/test/org/apache/orc/impl/TestRecordReaderImpl.java
@@ -455,7 +455,7 @@ public class TestRecordReaderImpl {
return RecordReaderImpl.evaluatePredicateProto(stats, predicate, null,
encoding, null,
include135 ? OrcFile.WriterVersion.ORC_135: OrcFile.WriterVersion.ORC_101,
- TypeDescription.createTimestamp(), useUTCTimestamp);
+ TypeDescription.createTimestamp(), useUTCTimestamp, false, false);
}
static TruthValue evaluateTimestampBloomfilter(OrcProto.ColumnStatistics stats,
@@ -478,7 +478,7 @@ public class TestRecordReaderImpl {
BloomFilterIO.serialize(builder, bloom);
return RecordReaderImpl.evaluatePredicateProto(stats, predicate, kind,
encoding.build(), builder.build(), version,
- TypeDescription.createTimestamp(), useUTCTimestamp);
+ TypeDescription.createTimestamp(), useUTCTimestamp, false, false);
}
@Test
[orc] 01/02: ORC-578: Fix schema conversions with proleptic
dates/times.
Posted by om...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
omalley pushed a commit to branch branch-1.5
in repository https://gitbox.apache.org/repos/asf/orc.git
commit 7031f1297b123ab5338c9326a4176e095b3bb40e
Author: Owen O'Malley <om...@apache.org>
AuthorDate: Thu Dec 12 23:08:40 2019 -0800
ORC-578: Fix schema conversions with proleptic dates/times.
Fixes #462
Signed-off-by: Owen O'Malley <om...@apache.org>
---
LICENSE | 34 +
java/core/pom.xml | 4 +
.../org/apache/orc/impl/ColumnStatisticsImpl.java | 8 +-
.../apache/orc/impl/ConvertTreeReaderFactory.java | 903 +++++++--------------
.../src/java/org/apache/orc/impl/DateUtils.java | 206 +++--
.../org/apache/orc/impl/SerializationUtils.java | 29 +
.../src/java/org/apache/orc/impl/WriterImpl.java | 4 +-
.../threeten/extra/chrono/HybridChronology.java | 455 +++++++++++
.../java/org/threeten/extra/chrono/HybridDate.java | 537 ++++++++++++
.../org/apache/orc/TestProlepticConversions.java | 186 +++++
.../test/org/apache/orc/impl/TestDateUtils.java | 60 ++
.../org/apache/orc/impl/TestSchemaEvolution.java | 680 +++++++++++++++-
java/pom.xml | 5 +
.../test/resources/orc-file-dump-bloomfilter.out | 2 +-
.../test/resources/orc-file-dump-bloomfilter2.out | 2 +-
.../orc-file-dump-dictionary-threshold.out | 2 +-
java/tools/src/test/resources/orc-file-dump.json | 2 +-
java/tools/src/test/resources/orc-file-dump.out | 2 +-
.../tools/src/test/resources/orc-file-has-null.out | 2 +-
19 files changed, 2408 insertions(+), 715 deletions(-)
diff --git a/LICENSE b/LICENSE
index 1cb1082..7050787 100644
--- a/LICENSE
+++ b/LICENSE
@@ -331,3 +331,37 @@ For zlib:
If you redistribute modified sources, we would appreciate that you include in
the file ChangeLog history information documenting your changes. Please read
the FAQ for more information on the distribution of modified source versions.
+
+For orc.threeten:
+
+ /*
+ * Copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * * Neither the name of JSR-310 nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
\ No newline at end of file
diff --git a/java/core/pom.xml b/java/core/pom.xml
index 87396a1..14e309a 100644
--- a/java/core/pom.xml
+++ b/java/core/pom.xml
@@ -71,6 +71,10 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.threeten</groupId>
+ <artifactId>threeten-extra</artifactId>
+ </dependency>
<!-- test inter-project -->
<dependency>
diff --git a/java/core/src/java/org/apache/orc/impl/ColumnStatisticsImpl.java b/java/core/src/java/org/apache/orc/impl/ColumnStatisticsImpl.java
index 80f69e5..0532644 100644
--- a/java/core/src/java/org/apache/orc/impl/ColumnStatisticsImpl.java
+++ b/java/core/src/java/org/apache/orc/impl/ColumnStatisticsImpl.java
@@ -1349,21 +1349,21 @@ public class ColumnStatisticsImpl implements ColumnStatistics {
maximum = DateUtils.convertTime(
SerializationUtils.convertToUtc(TimeZone.getDefault(),
timestampStats.getMaximum()),
- writerUsedProlepticGregorian, convertToProlepticGregorian);
+ writerUsedProlepticGregorian, convertToProlepticGregorian, true);
}
if (timestampStats.hasMinimum()) {
minimum = DateUtils.convertTime(
SerializationUtils.convertToUtc(TimeZone.getDefault(),
timestampStats.getMinimum()),
- writerUsedProlepticGregorian, convertToProlepticGregorian);
+ writerUsedProlepticGregorian, convertToProlepticGregorian, true);
}
if (timestampStats.hasMaximumUtc()) {
maximum = DateUtils.convertTime(timestampStats.getMaximumUtc(),
- writerUsedProlepticGregorian, convertToProlepticGregorian);
+ writerUsedProlepticGregorian, convertToProlepticGregorian, true);
}
if (timestampStats.hasMinimumUtc()) {
minimum = DateUtils.convertTime(timestampStats.getMinimumUtc(),
- writerUsedProlepticGregorian, convertToProlepticGregorian);
+ writerUsedProlepticGregorian, convertToProlepticGregorian, true);
}
}
diff --git a/java/core/src/java/org/apache/orc/impl/ConvertTreeReaderFactory.java b/java/core/src/java/org/apache/orc/impl/ConvertTreeReaderFactory.java
index b9fb48d..289eaef 100644
--- a/java/core/src/java/org/apache/orc/impl/ConvertTreeReaderFactory.java
+++ b/java/core/src/java/org/apache/orc/impl/ConvertTreeReaderFactory.java
@@ -19,14 +19,25 @@ package org.apache.orc.impl;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
-import java.sql.Date;
import java.sql.Timestamp;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.ZoneId;
+import java.time.chrono.Chronology;
+import java.time.chrono.IsoChronology;
+import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeFormatterBuilder;
+import java.time.format.DateTimeParseException;
+import java.time.format.SignStyle;
+import java.time.temporal.ChronoField;
import java.util.EnumMap;
import java.util.Map;
+import java.util.TimeZone;
import org.apache.hadoop.hive.common.type.HiveDecimal;
import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector;
import org.apache.hadoop.hive.ql.exec.vector.ColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.DateColumnVector;
import org.apache.hadoop.hive.ql.exec.vector.Decimal64ColumnVector;
import org.apache.hadoop.hive.ql.exec.vector.DecimalColumnVector;
import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector;
@@ -34,11 +45,11 @@ import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector;
import org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector;
import org.apache.hadoop.hive.ql.exec.vector.expressions.StringExpr;
import org.apache.hadoop.hive.ql.util.TimestampUtils;
-import org.apache.hadoop.hive.serde2.io.DateWritable;
import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable;
import org.apache.orc.OrcProto;
import org.apache.orc.TypeDescription;
import org.apache.orc.TypeDescription.Category;
+import org.threeten.extra.chrono.HybridChronology;
/**
* Convert ORC tree readers.
@@ -50,7 +61,7 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
*/
public static class ConvertTreeReader extends TreeReader {
- private TreeReader convertTreeReader;
+ protected TreeReader convertTreeReader;
ConvertTreeReader(int columnId) throws IOException {
super(columnId, null);
@@ -189,17 +200,6 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
}
}
- protected float parseFloatFromString(String string) {
- try {
- float floatValue = Float.parseFloat(string);
- isParseError = false;
- return floatValue;
- } catch (NumberFormatException e) {
- isParseError = true;
- return Float.NaN;
- }
- }
-
protected double parseDoubleFromString(String string) {
try {
double value = Double.parseDouble(string);
@@ -224,32 +224,6 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
}
}
- /**
- * @param string
- * @return the Timestamp parsed, or null if there was a parse error.
- */
- protected Timestamp parseTimestampFromString(String string) {
- try {
- Timestamp value = Timestamp.valueOf(string);
- return value;
- } catch (IllegalArgumentException e) {
- return null;
- }
- }
-
- /**
- * @param string
- * @return the Date parsed, or null if there was a parse error.
- */
- protected Date parseDateFromString(String string) {
- try {
- Date value = Date.valueOf(string);
- return value;
- } catch (IllegalArgumentException e) {
- return null;
- }
- }
-
protected String stringFromBytesColumnVectorEntry(
BytesColumnVector bytesColVector, int elementNum) {
String string;
@@ -492,65 +466,18 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
}
}
- public static class AnyIntegerFromFloatTreeReader extends ConvertTreeReader {
-
- private FloatTreeReader floatTreeReader;
-
- private final TypeDescription readerType;
- private DoubleColumnVector doubleColVector;
- private LongColumnVector longColVector;
-
- AnyIntegerFromFloatTreeReader(int columnId, TypeDescription readerType)
- throws IOException {
- super(columnId);
- this.readerType = readerType;
- floatTreeReader = new FloatTreeReader(columnId);
- setConvertTreeReader(floatTreeReader);
- }
-
- @Override
- public void setConvertVectorElement(int elementNum) throws IOException {
- double doubleValue = doubleColVector.vector[elementNum];
- if (!doubleCanFitInLong(doubleValue)) {
- longColVector.isNull[elementNum] = true;
- longColVector.noNulls = false;
- } else {
- // UNDONE: Does the overflow check above using double really work here for float?
- float floatValue = (float) doubleValue;
- downCastAnyInteger(longColVector, elementNum, (long) floatValue, readerType);
- }
- }
-
- @Override
- public void nextVector(ColumnVector previousVector,
- boolean[] isNull,
- final int batchSize) throws IOException {
- if (doubleColVector == null) {
- // Allocate column vector for file; cast column vector for reader.
- doubleColVector = new DoubleColumnVector();
- longColVector = (LongColumnVector) previousVector;
- }
- // Read present/isNull stream
- floatTreeReader.nextVector(doubleColVector, isNull, batchSize);
-
- convertVector(doubleColVector, longColVector, batchSize);
- }
- }
-
public static class AnyIntegerFromDoubleTreeReader extends ConvertTreeReader {
- private DoubleTreeReader doubleTreeReader;
-
private final TypeDescription readerType;
private DoubleColumnVector doubleColVector;
private LongColumnVector longColVector;
- AnyIntegerFromDoubleTreeReader(int columnId, TypeDescription readerType)
+ AnyIntegerFromDoubleTreeReader(int columnId, TypeDescription readerType,
+ TreeReader fromReader)
throws IOException {
super(columnId);
this.readerType = readerType;
- doubleTreeReader = new DoubleTreeReader(columnId);
- setConvertTreeReader(doubleTreeReader);
+ setConvertTreeReader(fromReader);
}
@Override
@@ -574,7 +501,7 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
longColVector = (LongColumnVector) previousVector;
}
// Read present/isNull stream
- doubleTreeReader.nextVector(doubleColVector, isNull, batchSize);
+ convertTreeReader.nextVector(doubleColVector, isNull, batchSize);
convertVector(doubleColVector, longColVector, batchSize);
}
@@ -730,10 +657,9 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
@Override
public void setConvertVectorElement(int elementNum) throws IOException {
- // Use TimestampWritable's getSeconds.
- long longValue = TimestampUtils.millisToSeconds(
- timestampColVector.asScratchTimestamp(elementNum).getTime());
- downCastAnyInteger(longColVector, elementNum, longValue, readerType);
+ long millis = timestampColVector.asScratchTimestamp(elementNum).getTime();
+ long seconds = Math.floorDiv(millis, 1000);
+ downCastAnyInteger(longColVector, elementNum, seconds, readerType);
}
@Override
@@ -752,207 +678,6 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
}
}
- public static class FloatFromAnyIntegerTreeReader extends ConvertTreeReader {
-
- private AnyIntegerTreeReader anyIntegerAsLongTreeReader;
-
- private LongColumnVector longColVector;
- private DoubleColumnVector doubleColVector;
-
- FloatFromAnyIntegerTreeReader(int columnId, TypeDescription fileType,
- Context context) throws IOException {
- super(columnId);
- anyIntegerAsLongTreeReader =
- new AnyIntegerTreeReader(columnId, fileType, context);
- setConvertTreeReader(anyIntegerAsLongTreeReader);
- }
-
- @Override
- public void setConvertVectorElement(int elementNum) throws IOException {
- float floatValue = (float) longColVector.vector[elementNum];
- if (!Float.isNaN(floatValue)) {
- doubleColVector.vector[elementNum] = floatValue;
- } else {
- doubleColVector.vector[elementNum] = Double.NaN;
- doubleColVector.noNulls = false;
- doubleColVector.isNull[elementNum] = true;
- }
- }
-
- @Override
- public void nextVector(ColumnVector previousVector,
- boolean[] isNull,
- final int batchSize) throws IOException {
- if (longColVector == null) {
- // Allocate column vector for file; cast column vector for reader.
- longColVector = new LongColumnVector();
- doubleColVector = (DoubleColumnVector) previousVector;
- }
- // Read present/isNull stream
- anyIntegerAsLongTreeReader.nextVector(longColVector, isNull, batchSize);
-
- convertVector(longColVector, doubleColVector, batchSize);
- }
- }
-
- public static class FloatFromDoubleTreeReader extends ConvertTreeReader {
-
- private DoubleTreeReader doubleTreeReader;
-
- FloatFromDoubleTreeReader(int columnId) throws IOException {
- super(columnId);
- doubleTreeReader = new DoubleTreeReader(columnId);
- setConvertTreeReader(doubleTreeReader);
- }
-
- @Override
- public void nextVector(ColumnVector previousVector,
- boolean[] isNull,
- final int batchSize) throws IOException {
- doubleTreeReader.nextVector(previousVector, isNull, batchSize);
-
- DoubleColumnVector resultColVector = (DoubleColumnVector) previousVector;
- double[] resultVector = resultColVector.vector;
- if (resultColVector.isRepeating) {
- if (resultColVector.noNulls || !resultColVector.isNull[0]) {
- resultVector[0] = (float) resultVector[0];
- } else {
- // Remains null.
- }
- } else if (resultColVector.noNulls){
- for (int i = 0; i < batchSize; i++) {
- resultVector[i] = (float) resultVector[i];
- }
- } else {
- for (int i = 0; i < batchSize; i++) {
- if (!resultColVector.isNull[i]) {
- resultVector[i] = (float) resultVector[i];
- } else {
- // Remains null.
- }
- }
- }
- }
- }
-
- public static class FloatFromDecimalTreeReader extends ConvertTreeReader {
-
- private DecimalTreeReader decimalTreeReader;
-
- private final int precision;
- private final int scale;
- private DecimalColumnVector decimalColVector;
- private DoubleColumnVector doubleColVector;
-
- FloatFromDecimalTreeReader(int columnId, TypeDescription fileType,
- TypeDescription readerType, Context context) throws IOException {
- super(columnId);
- this.precision = fileType.getPrecision();
- this.scale = fileType.getScale();
- decimalTreeReader = new DecimalTreeReader(columnId, precision, scale, context);
- setConvertTreeReader(decimalTreeReader);
- }
-
- @Override
- public void setConvertVectorElement(int elementNum) throws IOException {
- doubleColVector.vector[elementNum] =
- (float) decimalColVector.vector[elementNum].doubleValue();
- }
-
- @Override
- public void nextVector(ColumnVector previousVector,
- boolean[] isNull,
- final int batchSize) throws IOException {
- if (decimalColVector == null) {
- // Allocate column vector for file; cast column vector for reader.
- decimalColVector = new DecimalColumnVector(precision, scale);
- doubleColVector = (DoubleColumnVector) previousVector;
- }
- // Read present/isNull stream
- decimalTreeReader.nextVector(decimalColVector, isNull, batchSize);
-
- convertVector(decimalColVector, doubleColVector, batchSize);
- }
- }
-
- public static class FloatFromStringGroupTreeReader extends ConvertTreeReader {
-
- private TreeReader stringGroupTreeReader;
-
- private BytesColumnVector bytesColVector;
- private DoubleColumnVector doubleColVector;
-
- FloatFromStringGroupTreeReader(int columnId, TypeDescription fileType, Context context)
- throws IOException {
- super(columnId);
- stringGroupTreeReader = getStringGroupTreeReader(columnId, fileType, context);
- setConvertTreeReader(stringGroupTreeReader);
- }
-
- @Override
- public void setConvertVectorElement(int elementNum) throws IOException {
- String string = stringFromBytesColumnVectorEntry(bytesColVector, elementNum);
- float floatValue = parseFloatFromString(string);
- if (!getIsParseError()) {
- doubleColVector.vector[elementNum] = floatValue;
- } else {
- doubleColVector.vector[elementNum] = Double.NaN;
- doubleColVector.noNulls = false;
- doubleColVector.isNull[elementNum] = true;
- }
- }
-
- @Override
- public void nextVector(ColumnVector previousVector,
- boolean[] isNull,
- final int batchSize) throws IOException {
- if (bytesColVector == null) {
- // Allocate column vector for file; cast column vector for reader.
- bytesColVector = new BytesColumnVector();
- doubleColVector = (DoubleColumnVector) previousVector;
- }
- // Read present/isNull stream
- stringGroupTreeReader.nextVector(bytesColVector, isNull, batchSize);
-
- convertVector(bytesColVector, doubleColVector, batchSize);
- }
- }
-
- public static class FloatFromTimestampTreeReader extends ConvertTreeReader {
-
- private TimestampTreeReader timestampTreeReader;
-
- private TimestampColumnVector timestampColVector;
- private DoubleColumnVector doubleColVector;
-
- FloatFromTimestampTreeReader(int columnId, Context context) throws IOException {
- super(columnId);
- timestampTreeReader = new TimestampTreeReader(columnId, context);
- setConvertTreeReader(timestampTreeReader);
- }
-
- @Override
- public void setConvertVectorElement(int elementNum) throws IOException {
- doubleColVector.vector[elementNum] = (float) TimestampUtils.getDouble(
- timestampColVector.asScratchTimestamp(elementNum));
- }
-
- @Override
- public void nextVector(ColumnVector previousVector,
- boolean[] isNull,
- final int batchSize) throws IOException {
- if (timestampColVector == null) {
- // Allocate column vector for file; cast column vector for reader.
- timestampColVector = new TimestampColumnVector();
- doubleColVector = (DoubleColumnVector) previousVector;
- }
- // Read present/isNull stream
- timestampTreeReader.nextVector(timestampColVector, isNull, batchSize);
-
- convertVector(timestampColVector, doubleColVector, batchSize);
- }
- }
-
public static class DoubleFromAnyIntegerTreeReader extends ConvertTreeReader {
private AnyIntegerTreeReader anyIntegerAsLongTreeReader;
@@ -997,51 +722,6 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
}
}
- public static class DoubleFromFloatTreeReader extends ConvertTreeReader {
-
- private FloatTreeReader floatTreeReader;
-
- DoubleFromFloatTreeReader(int columnId) throws IOException {
- super(columnId);
- floatTreeReader = new FloatTreeReader(columnId);
- setConvertTreeReader(floatTreeReader);
- }
-
- @Override
- public void nextVector(ColumnVector previousVector,
- boolean[] isNull,
- final int batchSize) throws IOException {
- // we get the DoubleColumnVector produced by float tree reader first, then iterate through
- // the elements and make double -> float -> string -> double conversion to preserve the
- // precision. When float tree reader reads float and assign it to double, java's widening
- // conversion adds more precision which will break all comparisons.
- // Example: float f = 74.72
- // double d = f ---> 74.72000122070312
- // Double.parseDouble(String.valueOf(f)) ---> 74.72
- floatTreeReader.nextVector(previousVector, isNull, batchSize);
-
- DoubleColumnVector doubleColumnVector = (DoubleColumnVector) previousVector;
- if (doubleColumnVector.isRepeating) {
- if (doubleColumnVector.noNulls || !doubleColumnVector.isNull[0]) {
- final float f = (float) doubleColumnVector.vector[0];
- doubleColumnVector.vector[0] = Double.parseDouble(String.valueOf(f));
- }
- } else if (doubleColumnVector.noNulls){
- for (int i = 0; i < batchSize; i++) {
- final float f = (float) doubleColumnVector.vector[i];
- doubleColumnVector.vector[i] = Double.parseDouble(String.valueOf(f));
- }
- } else {
- for (int i = 0; i < batchSize; i++) {
- if (!doubleColumnVector.isNull[i]) {
- final float f = (float) doubleColumnVector.vector[i];
- doubleColumnVector.vector[i] = Double.parseDouble(String.valueOf(f));
- }
- }
- }
- }
- }
-
public static class DoubleFromDecimalTreeReader extends ConvertTreeReader {
private DecimalTreeReader decimalTreeReader;
@@ -1138,8 +818,13 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
@Override
public void setConvertVectorElement(int elementNum) throws IOException {
- doubleColVector.vector[elementNum] = TimestampUtils.getDouble(
- timestampColVector.asScratchTimestamp(elementNum));
+ Timestamp ts = timestampColVector.asScratchTimestamp(elementNum);
+ double result = Math.floorDiv(ts.getTime(), 1000);
+ int nano = ts.getNanos();
+ if (nano != 0) {
+ result += nano / 1_000_000_000.0;
+ }
+ doubleColVector.vector[elementNum] = result;
}
@Override
@@ -1158,6 +843,30 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
}
}
+ public static class FloatFromDoubleTreeReader extends ConvertTreeReader {
+ FloatFromDoubleTreeReader(int columnId,
+ TreeReader fromReader) throws IOException {
+ super(columnId);
+ setConvertTreeReader(fromReader);
+ }
+
+ @Override
+ public void nextVector(ColumnVector previousVector,
+ boolean[] isNull,
+ final int batchSize) throws IOException {
+ // Read present/isNull stream
+ convertTreeReader.nextVector(previousVector, isNull, batchSize);
+ DoubleColumnVector vector = (DoubleColumnVector) previousVector;
+ if (previousVector.isRepeating) {
+ vector.vector[0] = (float) vector.vector[0];
+ } else {
+ for(int i=0; i < batchSize; ++i) {
+ vector.vector[i] = (float) vector.vector[i];
+ }
+ }
+ }
+ }
+
public static class DecimalFromAnyIntegerTreeReader extends ConvertTreeReader {
private AnyIntegerTreeReader anyIntegerAsLongTreeReader;
@@ -1201,71 +910,16 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
}
}
- public static class DecimalFromFloatTreeReader extends ConvertTreeReader {
-
- private FloatTreeReader floatTreeReader;
-
- private DoubleColumnVector doubleColVector;
- private ColumnVector decimalColVector;
-
- DecimalFromFloatTreeReader(int columnId, TypeDescription readerType)
- throws IOException {
- super(columnId);
- floatTreeReader = new FloatTreeReader(columnId);
- setConvertTreeReader(floatTreeReader);
- }
-
- @Override
- public void setConvertVectorElement(int elementNum) throws IOException {
- float floatValue = (float) doubleColVector.vector[elementNum];
- if (!Float.isNaN(floatValue)) {
- HiveDecimal decimalValue =
- HiveDecimal.create(Float.toString(floatValue));
- if (decimalValue != null) {
- // The DecimalColumnVector will enforce precision and scale and set the entry to null when out of bounds.
- if (decimalColVector instanceof Decimal64ColumnVector) {
- ((Decimal64ColumnVector) decimalColVector).set(elementNum, decimalValue);
- } else {
- ((DecimalColumnVector) decimalColVector).set(elementNum, decimalValue);
- }
- } else {
- decimalColVector.noNulls = false;
- decimalColVector.isNull[elementNum] = true;
- }
- } else {
- decimalColVector.noNulls = false;
- decimalColVector.isNull[elementNum] = true;
- }
- }
-
- @Override
- public void nextVector(ColumnVector previousVector,
- boolean[] isNull,
- final int batchSize) throws IOException {
- if (doubleColVector == null) {
- // Allocate column vector for file; cast column vector for reader.
- doubleColVector = new DoubleColumnVector();
- decimalColVector = previousVector;
- }
- // Read present/isNull stream
- floatTreeReader.nextVector(doubleColVector, isNull, batchSize);
-
- convertVector(doubleColVector, decimalColVector, batchSize);
- }
- }
-
public static class DecimalFromDoubleTreeReader extends ConvertTreeReader {
- private DoubleTreeReader doubleTreeReader;
-
private DoubleColumnVector doubleColVector;
private ColumnVector decimalColVector;
- DecimalFromDoubleTreeReader(int columnId, TypeDescription readerType)
+ DecimalFromDoubleTreeReader(int columnId, TypeDescription readerType,
+ TreeReader fromReader)
throws IOException {
super(columnId);
- doubleTreeReader = new DoubleTreeReader(columnId);
- setConvertTreeReader(doubleTreeReader);
+ setConvertTreeReader(fromReader);
}
@Override
@@ -1294,7 +948,7 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
decimalColVector = previousVector;
}
// Read present/isNull stream
- doubleTreeReader.nextVector(doubleColVector, isNull, batchSize);
+ convertTreeReader.nextVector(doubleColVector, isNull, batchSize);
convertVector(doubleColVector, decimalColVector, batchSize);
}
@@ -1362,9 +1016,13 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
@Override
public void setConvertVectorElement(int elementNum) throws IOException {
- double doubleValue = TimestampUtils.getDouble(
- timestampColVector.asScratchTimestamp(elementNum));
- HiveDecimal value = HiveDecimal.create(Double.toString(doubleValue));
+ long seconds = Math.floorDiv(timestampColVector.time[elementNum], 1000);
+ long nanos = timestampColVector.nanos[elementNum];
+ if (seconds < 0 && nanos > 0) {
+ seconds += 1;
+ nanos = 1_000_000_000 - nanos;
+ }
+ HiveDecimal value = HiveDecimal.create(String.format("%d.%09d", seconds, nanos));
if (value != null) {
// The DecimalColumnVector will enforce precision and scale and set the entry to null when out of bounds.
if (decimalColVector instanceof Decimal64ColumnVector) {
@@ -1480,66 +1138,17 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
}
}
- public static class StringGroupFromFloatTreeReader extends ConvertTreeReader {
-
- private FloatTreeReader floatTreeReader;
-
- private final TypeDescription readerType;
- private DoubleColumnVector doubleColVector;
- private BytesColumnVector bytesColVector;
-
-
- StringGroupFromFloatTreeReader(int columnId, TypeDescription readerType,
- Context context) throws IOException {
- super(columnId);
- this.readerType = readerType;
- floatTreeReader = new FloatTreeReader(columnId);
- setConvertTreeReader(floatTreeReader);
- }
-
- @Override
- public void setConvertVectorElement(int elementNum) {
- float floatValue = (float) doubleColVector.vector[elementNum];
- if (!Float.isNaN(floatValue)) {
- String string = String.valueOf(floatValue);
- byte[] bytes = string.getBytes(StandardCharsets.UTF_8);
- assignStringGroupVectorEntry(bytesColVector, elementNum, readerType, bytes);
- } else {
- bytesColVector.noNulls = false;
- bytesColVector.isNull[elementNum] = true;
- }
- }
-
- @Override
- public void nextVector(ColumnVector previousVector,
- boolean[] isNull,
- final int batchSize) throws IOException {
- if (doubleColVector == null) {
- // Allocate column vector for file; cast column vector for reader.
- doubleColVector = new DoubleColumnVector();
- bytesColVector = (BytesColumnVector) previousVector;
- }
- // Read present/isNull stream
- floatTreeReader.nextVector(doubleColVector, isNull, batchSize);
-
- convertVector(doubleColVector, bytesColVector, batchSize);
- }
- }
-
public static class StringGroupFromDoubleTreeReader extends ConvertTreeReader {
- private DoubleTreeReader doubleTreeReader;
-
private final TypeDescription readerType;
private DoubleColumnVector doubleColVector;
private BytesColumnVector bytesColVector;
StringGroupFromDoubleTreeReader(int columnId, TypeDescription readerType,
- Context context) throws IOException {
+ Context context, TreeReader fromReader) throws IOException {
super(columnId);
this.readerType = readerType;
- doubleTreeReader = new DoubleTreeReader(columnId);
- setConvertTreeReader(doubleTreeReader);
+ setConvertTreeReader(fromReader);
}
@Override
@@ -1565,7 +1174,7 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
bytesColVector = (BytesColumnVector) previousVector;
}
// Read present/isNull stream
- doubleTreeReader.nextVector(doubleColVector, isNull, batchSize);
+ convertTreeReader.nextVector(doubleColVector, isNull, batchSize);
convertVector(doubleColVector, bytesColVector, batchSize);
}
@@ -1623,6 +1232,60 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
}
}
+ /**
+ * The format for converting from/to string/date.
+ * Eg. "2019-07-09"
+ */
+ static final DateTimeFormatter DATE_FORMAT =
+ new DateTimeFormatterBuilder()
+ .appendValue(ChronoField.YEAR, 4, 10, SignStyle.EXCEEDS_PAD)
+ .appendLiteral('-')
+ .appendValue(ChronoField.MONTH_OF_YEAR, 2)
+ .appendLiteral('-')
+ .appendValue(ChronoField.DAY_OF_MONTH, 2)
+ .toFormatter();
+
+ /**
+ * The format for converting from/to string/timestamp.
+ * Eg. "2019-07-09 13:11:00"
+ */
+ static final DateTimeFormatter TIMESTAMP_FORMAT =
+ new DateTimeFormatterBuilder()
+ .append(DATE_FORMAT)
+ .appendLiteral(' ')
+ .appendValue(ChronoField.HOUR_OF_DAY, 2)
+ .appendLiteral(':')
+ .appendValue(ChronoField.MINUTE_OF_HOUR, 2)
+ .optionalStart()
+ .appendLiteral(':')
+ .appendValue(ChronoField.SECOND_OF_MINUTE, 2)
+ .optionalStart()
+ .appendFraction(ChronoField.NANO_OF_SECOND, 0, 9, true)
+ .toFormatter();
+
+ static final long MIN_EPOCH_SECONDS = Instant.MIN.getEpochSecond();
+ static final long MAX_EPOCH_SECONDS = Instant.MAX.getEpochSecond();
+
+ /**
+ * Convert a decimal to an Instant using seconds & nanos.
+ * @param vector the decimal64 column vector
+ * @param element the element number to use
+ * @return the timestamp instant
+ */
+ static Instant decimalToInstant(DecimalColumnVector vector, int element) {
+ // copy the value so that we can mutate it
+ HiveDecimalWritable value = new HiveDecimalWritable(vector.vector[element]);
+ long seconds = value.longValue();
+ if (seconds < MIN_EPOCH_SECONDS || seconds > MAX_EPOCH_SECONDS) {
+ return null;
+ } else {
+ value.mutateFractionPortion();
+ value.mutateScaleByPowerOfTen(9);
+ int nanos = (int) value.longValue();
+ return Instant.ofEpochSecond(seconds, nanos);
+ }
+ }
+
public static class StringGroupFromTimestampTreeReader extends ConvertTreeReader {
private TimestampTreeReader timestampTreeReader;
@@ -1630,6 +1293,8 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
private final TypeDescription readerType;
private TimestampColumnVector timestampColVector;
private BytesColumnVector bytesColVector;
+ private final DateTimeFormatter formatter;
+ private final ZoneId local;
StringGroupFromTimestampTreeReader(int columnId, TypeDescription readerType,
Context context) throws IOException {
@@ -1637,13 +1302,20 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
this.readerType = readerType;
timestampTreeReader = new TimestampTreeReader(columnId, context);
setConvertTreeReader(timestampTreeReader);
+ local = context.getUseUTCTimestamp() ? ZoneId.of("UTC")
+ : ZoneId.systemDefault();
+ Chronology chronology = context.useProlepticGregorian()
+ ? IsoChronology.INSTANCE : HybridChronology.INSTANCE;
+ formatter = TIMESTAMP_FORMAT.withChronology(chronology);
}
@Override
public void setConvertVectorElement(int elementNum) throws IOException {
- String string =
- timestampColVector.asScratchTimestamp(elementNum).toString();
- byte[] bytes = string.getBytes(StandardCharsets.UTF_8);
+ Instant instant = Instant.ofEpochSecond(Math.floorDiv(
+ timestampColVector.time[elementNum], 1000),
+ timestampColVector.nanos[elementNum]);
+ byte[] bytes = instant.atZone(local).format(formatter)
+ .getBytes(StandardCharsets.UTF_8);
assignStringGroupVectorEntry(bytesColVector, elementNum, readerType, bytes);
}
@@ -1668,9 +1340,9 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
private DateTreeReader dateTreeReader;
private final TypeDescription readerType;
- private LongColumnVector longColVector;
+ private DateColumnVector longColVector;
private BytesColumnVector bytesColVector;
- private Date date;
+ private final boolean useProlepticGregorian;
StringGroupFromDateTreeReader(int columnId, TypeDescription readerType,
Context context) throws IOException {
@@ -1678,14 +1350,14 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
this.readerType = readerType;
dateTreeReader = new DateTreeReader(columnId, context);
setConvertTreeReader(dateTreeReader);
- date = new Date(0);
+ useProlepticGregorian = context.useProlepticGregorian();
}
@Override
- public void setConvertVectorElement(int elementNum) throws IOException {
- date.setTime(DateWritable.daysToMillis((int) longColVector.vector[elementNum]));
- String string = date.toString();
- byte[] bytes = string.getBytes(StandardCharsets.UTF_8);
+ public void setConvertVectorElement(int elementNum) {
+ String dateStr = DateUtils.printDate((int) (longColVector.vector[elementNum]),
+ useProlepticGregorian);
+ byte[] bytes = dateStr.getBytes(StandardCharsets.UTF_8);
assignStringGroupVectorEntry(bytesColVector, elementNum, readerType, bytes);
}
@@ -1695,7 +1367,7 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
final int batchSize) throws IOException {
if (longColVector == null) {
// Allocate column vector for file; cast column vector for reader.
- longColVector = new LongColumnVector();
+ longColVector = new DateColumnVector();
bytesColVector = (BytesColumnVector) previousVector;
}
// Read present/isNull stream
@@ -1807,6 +1479,10 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
private LongColumnVector longColVector;
private TimestampColumnVector timestampColVector;
+ private final boolean useUtc;
+ private final TimeZone local;
+ private final boolean fileUsedProlepticGregorian;
+ private final boolean useProlepticGregorian;
TimestampFromAnyIntegerTreeReader(int columnId, TypeDescription fileType,
Context context) throws IOException {
@@ -1814,13 +1490,23 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
anyIntegerAsLongTreeReader =
new AnyIntegerTreeReader(columnId, fileType, context);
setConvertTreeReader(anyIntegerAsLongTreeReader);
+ this.useUtc = context.getUseUTCTimestamp();
+ local = useUtc ? TimeZone.getTimeZone("UTC") : TimeZone.getDefault();
+ fileUsedProlepticGregorian = context.fileUsedProlepticGregorian();
+ useProlepticGregorian = context.useProlepticGregorian();
}
@Override
public void setConvertVectorElement(int elementNum) {
- long longValue = longColVector.vector[elementNum];
- // UNDONE: What does the boolean setting need to be?
- timestampColVector.set(elementNum, new Timestamp(longValue));
+ // Use as millis to be compatible with orc 1.5.x, although orc 1.6
+ // uses seconds here.
+ long millis = longColVector.vector[elementNum];
+ if (!useUtc) {
+ millis = SerializationUtils.convertFromUtc(local, millis);
+ }
+ timestampColVector.time[elementNum] = millis;
+ timestampColVector.nanos[elementNum] =
+ (int) Math.floorMod(millis, 1000) * 1_000_000;
}
@Override
@@ -1832,71 +1518,54 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
longColVector = new LongColumnVector();
timestampColVector = (TimestampColumnVector) previousVector;
}
+ timestampColVector.changeCalendar(fileUsedProlepticGregorian, false);
// Read present/isNull stream
anyIntegerAsLongTreeReader.nextVector(longColVector, isNull, batchSize);
convertVector(longColVector, timestampColVector, batchSize);
- }
- }
-
- public static class TimestampFromFloatTreeReader extends ConvertTreeReader {
-
- private FloatTreeReader floatTreeReader;
-
- private DoubleColumnVector doubleColVector;
- private TimestampColumnVector timestampColVector;
-
- TimestampFromFloatTreeReader(int columnId, TypeDescription fileType,
- Context context) throws IOException {
- super(columnId);
- floatTreeReader = new FloatTreeReader(columnId);
- setConvertTreeReader(floatTreeReader);
- }
-
- @Override
- public void setConvertVectorElement(int elementNum) {
- float floatValue = (float) doubleColVector.vector[elementNum];
- Timestamp timestampValue = TimestampUtils.doubleToTimestamp(floatValue);
- // The TimestampColumnVector will set the entry to null when a null timestamp is passed in.
- timestampColVector.set(elementNum, timestampValue);
- }
-
- @Override
- public void nextVector(ColumnVector previousVector,
- boolean[] isNull,
- final int batchSize) throws IOException {
- if (doubleColVector == null) {
- // Allocate column vector for file; cast column vector for reader.
- doubleColVector = new DoubleColumnVector();
- timestampColVector = (TimestampColumnVector) previousVector;
- }
- // Read present/isNull stream
- floatTreeReader.nextVector(doubleColVector, isNull, batchSize);
-
- convertVector(doubleColVector, timestampColVector, batchSize);
+ timestampColVector.changeCalendar(useProlepticGregorian, true);
}
}
public static class TimestampFromDoubleTreeReader extends ConvertTreeReader {
- private DoubleTreeReader doubleTreeReader;
-
private DoubleColumnVector doubleColVector;
private TimestampColumnVector timestampColVector;
+ private final boolean useUtc;
+ private final TimeZone local;
+ private final boolean useProlepticGregorian;
+ private final boolean fileUsedProlepticGregorian;
TimestampFromDoubleTreeReader(int columnId, TypeDescription fileType,
- Context context) throws IOException {
+ Context context, TreeReader fromReader) throws IOException {
super(columnId);
- doubleTreeReader = new DoubleTreeReader(columnId);
- setConvertTreeReader(doubleTreeReader);
+ setConvertTreeReader(fromReader);
+ useUtc = context.getUseUTCTimestamp();
+ local = useUtc ? TimeZone.getTimeZone("UTC") : TimeZone.getDefault();
+ useProlepticGregorian = context.useProlepticGregorian();
+ fileUsedProlepticGregorian = context.fileUsedProlepticGregorian();
}
@Override
public void setConvertVectorElement(int elementNum) {
- double doubleValue = doubleColVector.vector[elementNum];
- Timestamp timestampValue = TimestampUtils.doubleToTimestamp(doubleValue);
- // The TimestampColumnVector will set the entry to null when a null timestamp is passed in.
- timestampColVector.set(elementNum, timestampValue);
+ double seconds = doubleColVector.vector[elementNum];
+ if (!useUtc) {
+ seconds = SerializationUtils.convertFromUtc(local, seconds);
+ }
+ // overflow
+ double doubleMillis = seconds * 1000;
+ long millis = Math.round(doubleMillis);
+ if (doubleMillis > Long.MAX_VALUE || doubleMillis < Long.MIN_VALUE ||
+ ((millis >= 0) != (doubleMillis >= 0))) {
+ timestampColVector.time[elementNum] = 0L;
+ timestampColVector.nanos[elementNum] = 0;
+ timestampColVector.isNull[elementNum] = true;
+ timestampColVector.noNulls = false;
+ } else {
+ timestampColVector.time[elementNum] = millis;
+ timestampColVector.nanos[elementNum] =
+ (int) Math.floorMod(millis, 1000) * 1_000_000;
+ }
}
@Override
@@ -1908,10 +1577,12 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
doubleColVector = new DoubleColumnVector();
timestampColVector = (TimestampColumnVector) previousVector;
}
+ timestampColVector.changeCalendar(fileUsedProlepticGregorian, false);
// Read present/isNull stream
- doubleTreeReader.nextVector(doubleColVector, isNull, batchSize);
+ convertTreeReader.nextVector(doubleColVector, isNull, batchSize);
convertVector(doubleColVector, timestampColVector, batchSize);
+ timestampColVector.changeCalendar(useProlepticGregorian, true);
}
}
@@ -1923,6 +1594,10 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
private final int scale;
private DecimalColumnVector decimalColVector;
private TimestampColumnVector timestampColVector;
+ private final boolean useUtc;
+ private final TimeZone local;
+ private final boolean useProlepticGregorian;
+ private final boolean fileUsedProlepticGregorian;
TimestampFromDecimalTreeReader(int columnId, TypeDescription fileType,
Context context) throws IOException {
@@ -1931,15 +1606,27 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
this.scale = fileType.getScale();
decimalTreeReader = new DecimalTreeReader(columnId, precision, scale, context);
setConvertTreeReader(decimalTreeReader);
+ useUtc = context.getUseUTCTimestamp();
+ local = useUtc ? TimeZone.getTimeZone("UTC") : TimeZone.getDefault();
+ useProlepticGregorian = context.useProlepticGregorian();
+ fileUsedProlepticGregorian = context.fileUsedProlepticGregorian();
}
@Override
public void setConvertVectorElement(int elementNum) {
- Timestamp timestampValue =
- TimestampUtils.decimalToTimestamp(
- decimalColVector.vector[elementNum].getHiveDecimal());
- // The TimestampColumnVector will set the entry to null when a null timestamp is passed in.
- timestampColVector.set(elementNum, timestampValue);
+ Instant t = decimalToInstant(decimalColVector, elementNum);
+ if (t == null) {
+ timestampColVector.noNulls = false;
+ timestampColVector.isNull[elementNum] = true;
+ } else if (!useUtc) {
+ long millis = t.toEpochMilli();
+ timestampColVector.time[elementNum] =
+ SerializationUtils.convertFromUtc(local, millis);
+ timestampColVector.nanos[elementNum] = t.getNano();
+ } else {
+ timestampColVector.time[elementNum] = t.toEpochMilli();
+ timestampColVector.nanos[elementNum] = t.getNano();
+ }
}
@Override
@@ -1951,10 +1638,12 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
decimalColVector = new DecimalColumnVector(precision, scale);
timestampColVector = (TimestampColumnVector) previousVector;
}
+ timestampColVector.changeCalendar(fileUsedProlepticGregorian, false);
// Read present/isNull stream
decimalTreeReader.nextVector(decimalColVector, isNull, batchSize);
convertVector(decimalColVector, timestampColVector, batchSize);
+ timestampColVector.changeCalendar(useProlepticGregorian, true);
}
}
@@ -1964,22 +1653,34 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
private BytesColumnVector bytesColVector;
private TimestampColumnVector timestampColVector;
+ private final DateTimeFormatter formatter;
+ private final boolean useProlepticGregorian;
TimestampFromStringGroupTreeReader(int columnId, TypeDescription fileType, Context context)
throws IOException {
super(columnId);
stringGroupTreeReader = getStringGroupTreeReader(columnId, fileType, context);
setConvertTreeReader(stringGroupTreeReader);
+ useProlepticGregorian = context.useProlepticGregorian();
+ Chronology chronology = useProlepticGregorian
+ ? IsoChronology.INSTANCE
+ : HybridChronology.INSTANCE;
+ formatter = TIMESTAMP_FORMAT
+ .withZone(context.getUseUTCTimestamp() ?
+ ZoneId.of("UTC") :
+ ZoneId.systemDefault())
+ .withChronology(chronology);
}
@Override
public void setConvertVectorElement(int elementNum) throws IOException {
- String stringValue =
- stringFromBytesColumnVectorEntry(bytesColVector, elementNum);
- Timestamp timestampValue = parseTimestampFromString(stringValue);
- if (timestampValue != null) {
- timestampColVector.set(elementNum, timestampValue);
- } else {
+ String str = SerializationUtils.bytesVectorToString(bytesColVector,
+ elementNum);
+ try {
+ Instant instant = Instant.from(formatter.parse(str));
+ timestampColVector.time[elementNum] = instant.toEpochMilli();
+ timestampColVector.nanos[elementNum] = instant.getNano();
+ } catch (DateTimeParseException e) {
timestampColVector.noNulls = false;
timestampColVector.isNull[elementNum] = true;
}
@@ -1998,6 +1699,7 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
stringGroupTreeReader.nextVector(bytesColVector, isNull, batchSize);
convertVector(bytesColVector, timestampColVector, batchSize);
+ timestampColVector.changeCalendar(useProlepticGregorian, false);
}
}
@@ -2007,19 +1709,28 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
private LongColumnVector longColVector;
private TimestampColumnVector timestampColVector;
+ private final boolean useUtc;
+ private final TimeZone local;
+ private final boolean useProlepticGregorian;
TimestampFromDateTreeReader(int columnId, TypeDescription fileType,
Context context) throws IOException {
super(columnId);
dateTreeReader = new DateTreeReader(columnId, context);
setConvertTreeReader(dateTreeReader);
+ useUtc = context.getUseUTCTimestamp();
+ local = useUtc ? TimeZone.getTimeZone("UTC") : TimeZone.getDefault();
+ useProlepticGregorian = context.useProlepticGregorian();
}
@Override
public void setConvertVectorElement(int elementNum) {
- long millis =
- DateWritable.daysToMillis((int) longColVector.vector[elementNum]);
- timestampColVector.set(elementNum, new Timestamp(millis));
+ long days = longColVector.vector[elementNum];
+ long millis = days * 24 * 60 * 60 * 1000;
+ timestampColVector.time[elementNum] = useUtc
+ ? millis
+ : SerializationUtils.convertFromUtc(local, millis);
+ timestampColVector.nanos[elementNum] = 0;
}
@Override
@@ -2028,13 +1739,14 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
final int batchSize) throws IOException {
if (longColVector == null) {
// Allocate column vector for file; cast column vector for reader.
- longColVector = new LongColumnVector();
+ longColVector = new DateColumnVector();
timestampColVector = (TimestampColumnVector) previousVector;
}
// Read present/isNull stream
dateTreeReader.nextVector(longColVector, isNull, batchSize);
convertVector(longColVector, timestampColVector, batchSize);
+ timestampColVector.changeCalendar(useProlepticGregorian, false);
}
}
@@ -2044,21 +1756,24 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
private BytesColumnVector bytesColVector;
private LongColumnVector longColVector;
+ private DateColumnVector dateColumnVector;
+ private final boolean useProlepticGregorian;
DateFromStringGroupTreeReader(int columnId, TypeDescription fileType, Context context)
throws IOException {
super(columnId);
stringGroupTreeReader = getStringGroupTreeReader(columnId, fileType, context);
setConvertTreeReader(stringGroupTreeReader);
+ useProlepticGregorian = context.useProlepticGregorian();
}
@Override
public void setConvertVectorElement(int elementNum) throws IOException {
String stringValue =
- stringFromBytesColumnVectorEntry(bytesColVector, elementNum);
- Date dateValue = parseDateFromString(stringValue);
+ SerializationUtils.bytesVectorToString(bytesColVector, elementNum);
+ Integer dateValue = DateUtils.parseDate(stringValue, useProlepticGregorian);
if (dateValue != null) {
- longColVector.vector[elementNum] = DateWritable.dateToDays(dateValue);
+ longColVector.vector[elementNum] = dateValue;
} else {
longColVector.noNulls = false;
longColVector.isNull[elementNum] = true;
@@ -2073,11 +1788,23 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
// Allocate column vector for file; cast column vector for reader.
bytesColVector = new BytesColumnVector();
longColVector = (LongColumnVector) previousVector;
+ if (longColVector instanceof DateColumnVector) {
+ dateColumnVector = (DateColumnVector) longColVector;
+ } else {
+ dateColumnVector = null;
+ if (useProlepticGregorian) {
+ throw new IllegalArgumentException("Can't use LongColumnVector with" +
+ " proleptic Gregorian dates.");
+ }
+ }
}
// Read present/isNull stream
stringGroupTreeReader.nextVector(bytesColVector, isNull, batchSize);
convertVector(bytesColVector, longColVector, batchSize);
+ if (dateColumnVector != null) {
+ dateColumnVector.changeCalendar(useProlepticGregorian, false);
+ }
}
}
@@ -2087,19 +1814,26 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
private TimestampColumnVector timestampColVector;
private LongColumnVector longColVector;
+ private final ZoneId local;
+ private final boolean useProlepticGregorian;
DateFromTimestampTreeReader(int columnId, Context context) throws IOException {
super(columnId);
timestampTreeReader = new TimestampTreeReader(columnId, context);
setConvertTreeReader(timestampTreeReader);
+ boolean useUtc = context.getUseUTCTimestamp();
+ local = useUtc ? ZoneId.of("UTC") : ZoneId.systemDefault();
+ useProlepticGregorian = context.useProlepticGregorian();
}
@Override
public void setConvertVectorElement(int elementNum) throws IOException {
- Date dateValue =
- DateWritable.timeToDate(TimestampUtils.millisToSeconds(
- timestampColVector.asScratchTimestamp(elementNum).getTime()));
- longColVector.vector[elementNum] = DateWritable.dateToDays(dateValue);
+ LocalDate day = LocalDate.from(
+ Instant.ofEpochSecond(
+ Math.floorDiv(timestampColVector.time[elementNum], 1000),
+ timestampColVector.nanos[elementNum])
+ .atZone(local));
+ longColVector.vector[elementNum] = day.toEpochDay();
}
@Override
@@ -2110,11 +1844,19 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
// Allocate column vector for file; cast column vector for reader.
timestampColVector = new TimestampColumnVector();
longColVector = (LongColumnVector) previousVector;
+ if (useProlepticGregorian && !(longColVector instanceof DateColumnVector)) {
+ throw new IllegalArgumentException("Can't use LongColumnVector with" +
+ " proleptic Gregorian dates.");
+ }
}
// Read present/isNull stream
timestampTreeReader.nextVector(timestampColVector, isNull, batchSize);
convertVector(timestampColVector, longColVector, batchSize);
+ if (longColVector instanceof DateColumnVector) {
+ ((DateColumnVector) longColVector)
+ .changeCalendar(useProlepticGregorian, false);
+ }
}
}
@@ -2159,9 +1901,6 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
context);
case FLOAT:
- return new FloatFromAnyIntegerTreeReader(columnId, fileType,
- context);
-
case DOUBLE:
return new DoubleFromAnyIntegerTreeReader(columnId, fileType,
context);
@@ -2192,57 +1931,12 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
}
}
- private static TreeReader createFloatConvertTreeReader(int columnId,
- TypeDescription fileType,
- TypeDescription readerType,
- Context context) throws IOException {
-
- // CONVERT from FLOAT to schema type.
- switch (readerType.getCategory()) {
-
- case BOOLEAN:
- case BYTE:
- case SHORT:
- case INT:
- case LONG:
- return new AnyIntegerFromFloatTreeReader(columnId, readerType);
-
- case FLOAT:
- throw new IllegalArgumentException("No conversion of type " +
- readerType.getCategory() + " to self needed");
-
- case DOUBLE:
- return new DoubleFromFloatTreeReader(columnId);
-
- case DECIMAL:
- return new DecimalFromFloatTreeReader(columnId, readerType);
-
- case STRING:
- case CHAR:
- case VARCHAR:
- return new StringGroupFromFloatTreeReader(columnId, readerType, context);
-
- case TIMESTAMP:
- return new TimestampFromFloatTreeReader(columnId, readerType, context);
-
- // Not currently supported conversion(s):
- case BINARY:
- case DATE:
-
- case STRUCT:
- case LIST:
- case MAP:
- case UNION:
- default:
- throw new IllegalArgumentException("Unsupported type " +
- readerType.getCategory());
- }
- }
-
private static TreeReader createDoubleConvertTreeReader(int columnId,
TypeDescription fileType,
TypeDescription readerType,
Context context) throws IOException {
+ TreeReader fromReader = fileType.getCategory() == Category.DOUBLE
+ ? new DoubleTreeReader(columnId) : new FloatTreeReader(columnId);
// CONVERT from DOUBLE to schema type.
switch (readerType.getCategory()) {
@@ -2252,25 +1946,26 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
case SHORT:
case INT:
case LONG:
- return new AnyIntegerFromDoubleTreeReader(columnId, readerType);
+ return new AnyIntegerFromDoubleTreeReader(columnId, readerType, fromReader);
case FLOAT:
- return new FloatFromDoubleTreeReader(columnId);
+ return new FloatFromDoubleTreeReader(columnId, fromReader);
case DOUBLE:
- throw new IllegalArgumentException("No conversion of type " +
- readerType.getCategory() + " to self needed");
+ return fromReader;
case DECIMAL:
- return new DecimalFromDoubleTreeReader(columnId, readerType);
+ return new DecimalFromDoubleTreeReader(columnId, readerType, fromReader);
case STRING:
case CHAR:
case VARCHAR:
- return new StringGroupFromDoubleTreeReader(columnId, readerType, context);
+ return new StringGroupFromDoubleTreeReader(columnId, readerType, context,
+ fromReader);
case TIMESTAMP:
- return new TimestampFromDoubleTreeReader(columnId, readerType, context);
+ return new TimestampFromDoubleTreeReader(columnId, readerType, context,
+ fromReader);
// Not currently supported conversion(s):
case BINARY:
@@ -2302,8 +1997,6 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
return new AnyIntegerFromDecimalTreeReader(columnId, fileType, readerType, context);
case FLOAT:
- return new FloatFromDecimalTreeReader(columnId, fileType, readerType, context);
-
case DOUBLE:
return new DoubleFromDecimalTreeReader(columnId, fileType, context);
@@ -2348,8 +2041,6 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
return new AnyIntegerFromStringGroupTreeReader(columnId, fileType, readerType, context);
case FLOAT:
- return new FloatFromStringGroupTreeReader(columnId, fileType, context);
-
case DOUBLE:
return new DoubleFromStringGroupTreeReader(columnId, fileType, context);
@@ -2403,8 +2094,6 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
return new AnyIntegerFromStringGroupTreeReader(columnId, fileType, readerType, context);
case FLOAT:
- return new FloatFromStringGroupTreeReader(columnId, fileType, context);
-
case DOUBLE:
return new DoubleFromStringGroupTreeReader(columnId, fileType, context);
@@ -2457,8 +2146,6 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
return new AnyIntegerFromStringGroupTreeReader(columnId, fileType, readerType, context);
case FLOAT:
- return new FloatFromStringGroupTreeReader(columnId, fileType, context);
-
case DOUBLE:
return new DoubleFromStringGroupTreeReader(columnId, fileType, context);
@@ -2511,8 +2198,6 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
return new AnyIntegerFromTimestampTreeReader(columnId, readerType, context);
case FLOAT:
- return new FloatFromTimestampTreeReader(columnId, context);
-
case DOUBLE:
return new DoubleFromTimestampTreeReader(columnId, context);
@@ -2765,8 +2450,6 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
return createAnyIntegerConvertTreeReader(columnId, fileType, readerType, context);
case FLOAT:
- return createFloatConvertTreeReader(columnId, fileType, readerType, context);
-
case DOUBLE:
return createDoubleConvertTreeReader(columnId, fileType, readerType, context);
diff --git a/java/core/src/java/org/apache/orc/impl/DateUtils.java b/java/core/src/java/org/apache/orc/impl/DateUtils.java
index 8ac574c..0b7592c 100644
--- a/java/core/src/java/org/apache/orc/impl/DateUtils.java
+++ b/java/core/src/java/org/apache/orc/impl/DateUtils.java
@@ -17,11 +17,15 @@
*/
package org.apache.orc.impl;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.TimeZone;
+import org.threeten.extra.chrono.HybridChronology;
+
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.ZoneId;
+import java.time.chrono.IsoChronology;
+import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeParseException;
+import java.time.temporal.TemporalAccessor;
import java.util.concurrent.TimeUnit;
/**
@@ -36,41 +40,39 @@ import java.util.concurrent.TimeUnit;
* old dates.
*/
public class DateUtils {
- private static SimpleDateFormat createFormatter(String fmt,
- GregorianCalendar calendar) {
- SimpleDateFormat result = new SimpleDateFormat(fmt);
- result.setCalendar(calendar);
- return result;
- }
-
- private static final String DATE = "yyyy-MM-dd";
- private static final String TIME = DATE + " HH:mm:ss";
- private static final TimeZone UTC = TimeZone.getTimeZone("UTC");
- private static final GregorianCalendar HYBRID = new GregorianCalendar();
- private static final ThreadLocal<SimpleDateFormat> HYBRID_DATE_FORMAT =
- ThreadLocal.withInitial(() -> createFormatter(DATE, HYBRID));
- private static final ThreadLocal<SimpleDateFormat> HYBRID_TIME_FORMAT =
- ThreadLocal.withInitial(() -> createFormatter(TIME, HYBRID));
+ private static final ZoneId UTC = ZoneId.of("UTC");
+ private static final ZoneId LOCAL = ZoneId.systemDefault();
private static final long SWITCHOVER_MILLIS;
private static final long SWITCHOVER_DAYS;
- private static final GregorianCalendar PROLEPTIC = new GregorianCalendar();
- private static final ThreadLocal<SimpleDateFormat> PROLEPTIC_DATE_FORMAT =
- ThreadLocal.withInitial(() -> createFormatter(DATE, PROLEPTIC));
- private static final ThreadLocal<SimpleDateFormat> PROLEPTIC_TIME_FORMAT =
- ThreadLocal.withInitial(() -> createFormatter(TIME, PROLEPTIC));
+ private static final DateTimeFormatter HYBRID_DATE_FORMAT =
+ ConvertTreeReaderFactory.DATE_FORMAT
+ .withChronology(HybridChronology.INSTANCE)
+ .withZone(UTC);
+ private static final DateTimeFormatter PROLEPTIC_DATE_FORMAT =
+ DateTimeFormatter.ISO_LOCAL_DATE
+ .withChronology(IsoChronology.INSTANCE)
+ .withZone(UTC);
+ private static final DateTimeFormatter HYBRID_UTC_TIME_FORMAT =
+ ConvertTreeReaderFactory.TIMESTAMP_FORMAT
+ .withChronology(HybridChronology.INSTANCE)
+ .withZone(UTC);
+ private static final DateTimeFormatter HYBRID_LOCAL_TIME_FORMAT =
+ ConvertTreeReaderFactory.TIMESTAMP_FORMAT
+ .withChronology(HybridChronology.INSTANCE)
+ .withZone(LOCAL);
+ private static final DateTimeFormatter PROLEPTIC_UTC_TIME_FORMAT =
+ ConvertTreeReaderFactory.TIMESTAMP_FORMAT
+ .withChronology(IsoChronology.INSTANCE)
+ .withZone(UTC);
+ private static final DateTimeFormatter PROLEPTIC_LOCAL_TIME_FORMAT =
+ ConvertTreeReaderFactory.TIMESTAMP_FORMAT
+ .withChronology(IsoChronology.INSTANCE)
+ .withZone(LOCAL);
static {
- HYBRID.setTimeZone(UTC);
- PROLEPTIC.setTimeZone(UTC);
- PROLEPTIC.setGregorianChange(new Date(Long.MIN_VALUE));
-
// Get the last day where the two calendars agree with each other.
- try {
- SWITCHOVER_MILLIS = HYBRID_DATE_FORMAT.get().parse("1582-10-15").getTime();
- SWITCHOVER_DAYS = TimeUnit.MILLISECONDS.toDays(SWITCHOVER_MILLIS);
- } catch (ParseException e) {
- throw new IllegalArgumentException("Can't parse switch over date", e);
- }
+ SWITCHOVER_DAYS = LocalDate.from(HYBRID_DATE_FORMAT.parse("1582-10-15")).toEpochDay();
+ SWITCHOVER_MILLIS = TimeUnit.DAYS.toMillis(SWITCHOVER_DAYS);
}
/**
@@ -82,14 +84,8 @@ public class DateUtils {
public static int convertDateToProleptic(int hybrid) {
int proleptic = hybrid;
if (hybrid < SWITCHOVER_DAYS) {
- String dateStr = HYBRID_DATE_FORMAT.get().format(
- new Date(TimeUnit.DAYS.toMillis(hybrid)));
- try {
- proleptic = (int) TimeUnit.MILLISECONDS.toDays(
- PROLEPTIC_DATE_FORMAT.get().parse(dateStr).getTime());
- } catch (ParseException e) {
- throw new IllegalArgumentException("Can't parse " + dateStr, e);
- }
+ String dateStr = HYBRID_DATE_FORMAT.format(LocalDate.ofEpochDay(proleptic));
+ proleptic = (int) LocalDate.from(PROLEPTIC_DATE_FORMAT.parse(dateStr)).toEpochDay();
}
return proleptic;
}
@@ -103,55 +99,28 @@ public class DateUtils {
public static int convertDateToHybrid(int proleptic) {
int hyrbid = proleptic;
if (proleptic < SWITCHOVER_DAYS) {
- String dateStr = PROLEPTIC_DATE_FORMAT.get().format(
- new Date(TimeUnit.DAYS.toMillis(proleptic)));
- try {
- hyrbid = (int) TimeUnit.MILLISECONDS.toDays(
- HYBRID_DATE_FORMAT.get().parse(dateStr).getTime());
- } catch (ParseException e) {
- throw new IllegalArgumentException("Can't parse " + dateStr, e);
- }
+ String dateStr = PROLEPTIC_DATE_FORMAT.format(LocalDate.ofEpochDay(proleptic));
+ hyrbid = (int) LocalDate.from(HYBRID_DATE_FORMAT.parse(dateStr)).toEpochDay();
}
return hyrbid;
}
- public static int convertDate(int original,
- boolean fromProleptic,
- boolean toProleptic) {
- if (fromProleptic != toProleptic) {
- return toProleptic
- ? convertDateToProleptic(original)
- : convertDateToHybrid(original);
- } else {
- return original;
- }
- }
-
- public static long convertTime(long original,
- boolean fromProleptic,
- boolean toProleptic) {
- if (fromProleptic != toProleptic) {
- return toProleptic
- ? convertTimeToProleptic(original)
- : convertTimeToHybrid(original);
- } else {
- return original;
- }
- }
/**
* Convert epoch millis from the hybrid Julian/Gregorian calendar to the
* proleptic Gregorian.
* @param hybrid millis of epoch in the hybrid Julian/Gregorian
+ * @param useUtc use UTC instead of local
* @return millis of epoch in the proleptic Gregorian
*/
- public static long convertTimeToProleptic(long hybrid) {
+ public static long convertTimeToProleptic(long hybrid, boolean useUtc) {
long proleptic = hybrid;
if (hybrid < SWITCHOVER_MILLIS) {
- String dateStr = HYBRID_TIME_FORMAT.get().format(new Date(hybrid));
- try {
- proleptic = PROLEPTIC_TIME_FORMAT.get().parse(dateStr).getTime();
- } catch (ParseException e) {
- throw new IllegalArgumentException("Can't parse " + dateStr, e);
+ if (useUtc) {
+ String dateStr = HYBRID_UTC_TIME_FORMAT.format(Instant.ofEpochMilli(hybrid));
+ proleptic = Instant.from(PROLEPTIC_UTC_TIME_FORMAT.parse(dateStr)).toEpochMilli();
+ } else {
+ String dateStr = HYBRID_LOCAL_TIME_FORMAT.format(Instant.ofEpochMilli(hybrid));
+ proleptic = Instant.from(PROLEPTIC_LOCAL_TIME_FORMAT.parse(dateStr)).toEpochMilli();
}
}
return proleptic;
@@ -161,21 +130,86 @@ public class DateUtils {
* Convert epoch millis from the proleptic Gregorian calendar to the hybrid
* Julian/Gregorian.
* @param proleptic millis of epoch in the proleptic Gregorian
+ * @param useUtc use UTC instead of local
* @return millis of epoch in the hybrid Julian/Gregorian
*/
- public static long convertTimeToHybrid(long proleptic) {
+ public static long convertTimeToHybrid(long proleptic, boolean useUtc) {
long hybrid = proleptic;
if (proleptic < SWITCHOVER_MILLIS) {
- String dateStr = PROLEPTIC_TIME_FORMAT.get().format(new Date(proleptic));
- try {
- hybrid = HYBRID_TIME_FORMAT.get().parse(dateStr).getTime();
- } catch (ParseException e) {
- throw new IllegalArgumentException("Can't parse " + dateStr, e);
+ if (useUtc) {
+ String dateStr = PROLEPTIC_UTC_TIME_FORMAT.format(Instant.ofEpochMilli(hybrid));
+ hybrid = Instant.from(HYBRID_UTC_TIME_FORMAT.parse(dateStr)).toEpochMilli();
+ } else {
+ String dateStr = PROLEPTIC_LOCAL_TIME_FORMAT.format(Instant.ofEpochMilli(hybrid));
+ hybrid = Instant.from(HYBRID_LOCAL_TIME_FORMAT.parse(dateStr)).toEpochMilli();
}
}
return hybrid;
}
+
+ public static int convertDate(int original,
+ boolean fromProleptic,
+ boolean toProleptic) {
+ if (fromProleptic != toProleptic) {
+ return toProleptic
+ ? convertDateToProleptic(original)
+ : convertDateToHybrid(original);
+ } else {
+ return original;
+ }
+ }
+
+ public static long convertTime(long original,
+ boolean fromProleptic,
+ boolean toProleptic,
+ boolean useUtc) {
+ if (fromProleptic != toProleptic) {
+ return toProleptic
+ ? convertTimeToProleptic(original, useUtc)
+ : convertTimeToHybrid(original, useUtc);
+ } else {
+ return original;
+ }
+ }
+
+ public static Integer parseDate(String date, boolean fromProleptic) {
+ try {
+ TemporalAccessor time = (fromProleptic ? PROLEPTIC_DATE_FORMAT : HYBRID_DATE_FORMAT).parse(date);
+ return (int) LocalDate.from(time).toEpochDay();
+ } catch (DateTimeParseException e) {
+ return null;
+ }
+ }
+
+ public static String printDate(int date, boolean fromProleptic) {
+ return (fromProleptic ? PROLEPTIC_DATE_FORMAT : HYBRID_DATE_FORMAT)
+ .format(LocalDate.ofEpochDay(date));
+ }
+
+ public static DateTimeFormatter getTimeFormat(boolean useProleptic,
+ boolean useUtc) {
+ if (useProleptic) {
+ return useUtc ? PROLEPTIC_UTC_TIME_FORMAT : PROLEPTIC_LOCAL_TIME_FORMAT;
+ } else {
+ return useUtc ? HYBRID_UTC_TIME_FORMAT : HYBRID_LOCAL_TIME_FORMAT;
+ }
+ }
+
+ public static Long parseTime(String date, boolean fromProleptic, boolean useUtc) {
+ try {
+ TemporalAccessor time = getTimeFormat(fromProleptic, useUtc).parse(date);
+ return Instant.from(time).toEpochMilli();
+ } catch (DateTimeParseException e) {
+ return null;
+ }
+ }
+
+ public static String printTime(long millis, boolean fromProleptic,
+ boolean useUtc) {
+ return getTimeFormat(fromProleptic, useUtc).format(Instant.ofEpochMilli(millis));
+ }
+
private DateUtils() {
throw new UnsupportedOperationException();
}
diff --git a/java/core/src/java/org/apache/orc/impl/SerializationUtils.java b/java/core/src/java/org/apache/orc/impl/SerializationUtils.java
index 3bed475..701341e 100644
--- a/java/core/src/java/org/apache/orc/impl/SerializationUtils.java
+++ b/java/core/src/java/org/apache/orc/impl/SerializationUtils.java
@@ -18,11 +18,14 @@
package org.apache.orc.impl;
+import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector;
+
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigInteger;
+import java.nio.charset.StandardCharsets;
import java.util.TimeZone;
public final class SerializationUtils {
@@ -1321,4 +1324,30 @@ public final class SerializationUtils {
int offset = local.getOffset(time);
return time + offset;
}
+ /**
+ * Convert a UTC time to a local timezone
+ * @param local the local timezone
+ * @param time the number of seconds since 1970
+ * @return the converted timestamp
+ */
+ public static double convertFromUtc(TimeZone local, double time) {
+ int offset = local.getOffset((long) (time*1000) - local.getRawOffset());
+ return time - offset / 1000.0;
+ }
+
+ /**
+ * Convert a bytes vector element into a String.
+ * @param vector the vector to use
+ * @param elementNum the element number to stringify
+ * @return a string or null if the value was null
+ */
+ public static String bytesVectorToString(BytesColumnVector vector,
+ int elementNum) {
+ if (vector.isRepeating) {
+ elementNum = 0;
+ }
+ return vector.noNulls || !vector.isNull[elementNum] ?
+ new String(vector.vector[elementNum], vector.start[elementNum],
+ vector.length[elementNum], StandardCharsets.UTF_8) : null;
+ }
}
diff --git a/java/core/src/java/org/apache/orc/impl/WriterImpl.java b/java/core/src/java/org/apache/orc/impl/WriterImpl.java
index 7eea7f7..6859c87 100644
--- a/java/core/src/java/org/apache/orc/impl/WriterImpl.java
+++ b/java/core/src/java/org/apache/orc/impl/WriterImpl.java
@@ -543,11 +543,9 @@ public class WriterImpl implements WriterInternal, MemoryManager.Callback {
rawDataSize = computeRawDataSize();
// serialize the types
writeTypes(builder, schema);
- if (hasDateOrTime(schema)) {
- builder.setCalendar(useProlepticGregorian
+ builder.setCalendar(useProlepticGregorian
? OrcProto.CalendarKind.PROLEPTIC_GREGORIAN
: OrcProto.CalendarKind.JULIAN_GREGORIAN);
- }
// add the stripe information
for(OrcProto.StripeInformation stripe: stripes) {
builder.addStripes(stripe);
diff --git a/java/core/src/java/org/threeten/extra/chrono/HybridChronology.java b/java/core/src/java/org/threeten/extra/chrono/HybridChronology.java
new file mode 100644
index 0000000..eee9fe6
--- /dev/null
+++ b/java/core/src/java/org/threeten/extra/chrono/HybridChronology.java
@@ -0,0 +1,455 @@
+/*
+ * 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.
+ */
+package org.threeten.extra.chrono;
+
+import java.io.Serializable;
+import java.time.Clock;
+import java.time.DateTimeException;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.ZoneId;
+import java.time.chrono.AbstractChronology;
+import java.time.chrono.ChronoLocalDateTime;
+import java.time.chrono.ChronoZonedDateTime;
+import java.time.chrono.Chronology;
+import java.time.chrono.Era;
+import java.time.chrono.IsoChronology;
+import java.time.format.ResolverStyle;
+import java.time.temporal.ChronoField;
+import java.time.temporal.TemporalAccessor;
+import java.time.temporal.TemporalField;
+import java.time.temporal.ValueRange;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * The Julian-Gregorian hybrid calendar system.
+ * <p>
+ * The British calendar system follows the rules of the Julian calendar
+ * until 1752 and the rules of the Gregorian (ISO) calendar since then.
+ * The Julian differs from the Gregorian only in terms of the leap year rule.
+ * <p>
+ * The Julian and Gregorian calendar systems are linked to Rome and the Vatican
+ * with the Julian preceding the Gregorian. The Gregorian was introduced to
+ * handle the drift of the seasons through the year due to the inaccurate
+ * Julian leap year rules. When first introduced by the Vatican in 1582,
+ * the cutover resulted in a "gap" of 10 days.
+ * <p>
+ * While the calendar was introduced in 1582, it was not adopted everywhere.
+ * Britain did not adopt it until the 1752, when Wednesday 2nd September 1752
+ * was followed by Thursday 14th September 1752.
+ * <p>
+ * This chronology implements the proleptic Julian calendar system followed by
+ * the proleptic Gregorian calendar system (identical to the ISO calendar system).
+ * Dates are aligned such that {@code 0001-01-01 (British)} is {@code 0000-12-30 (ISO)}.
+ * <p>
+ * This class implements a calendar where January 1st is the start of the year.
+ * The history of the start of the year is complex and using the current standard
+ * is the most consistent.
+ * <p>
+ * The eras of this calendar system are defined by {@link JulianEra} to avoid unnecessary duplication.
+ * <p>
+ * The fields are defined as follows:
+ * <ul>
+ * <li>era - There are two eras, the current 'Anno Domini' (AD) and the previous era 'Before Christ' (BC).
+ * <li>year-of-era - The year-of-era for the current era increases uniformly from the epoch at year one.
+ * For the previous era the year increases from one as time goes backwards.
+ * <li>proleptic-year - The proleptic year is the same as the year-of-era for the
+ * current era. For the previous era, years have zero, then negative values.
+ * <li>month-of-year - There are 12 months in a year, numbered from 1 to 12.
+ * <li>day-of-month - There are between 28 and 31 days in each month, numbered from 1 to 31.
+ * Months 4, 6, 9 and 11 have 30 days, Months 1, 3, 5, 7, 8, 10 and 12 have 31 days.
+ * Month 2 has 28 days, or 29 in a leap year.
+ * The cutover month, September 1752, has a value range from 1 to 30, but a length of 19.
+ * <li>day-of-year - There are 365 days in a standard year and 366 in a leap year.
+ * The days are numbered from 1 to 365 or 1 to 366.
+ * The cutover year 1752 has values from 1 to 355 and a length of 355 days.
+ * </ul>
+ *
+ * <h3>Implementation Requirements</h3>
+ * This class is immutable and thread-safe.
+ */
+public final class HybridChronology
+ extends AbstractChronology
+ implements Serializable {
+
+ /**
+ * Singleton instance for the Coptic chronology.
+ */
+ public static final HybridChronology INSTANCE = new HybridChronology();
+ /**
+ * The cutover date, October 15, 1582.
+ */
+ public static final LocalDate CUTOVER = LocalDate.of(1582, 10, 15);
+ /**
+ * The number of cutover days.
+ */
+ static final int CUTOVER_DAYS = 10;
+ /**
+ * The cutover year.
+ */
+ static final int CUTOVER_YEAR = 1582;
+
+ /**
+ * Serialization version.
+ */
+ private static final long serialVersionUID = 87235724675472658L;
+ /**
+ * Range of day-of-year.
+ */
+ static final ValueRange DOY_RANGE = ValueRange.of(1, 355, 366);
+ /**
+ * Range of aligned-week-of-month.
+ */
+ static final ValueRange ALIGNED_WOM_RANGE = ValueRange.of(1, 3, 5);
+ /**
+ * Range of aligned-week-of-year.
+ */
+ static final ValueRange ALIGNED_WOY_RANGE = ValueRange.of(1, 51, 53);
+ /**
+ * Range of proleptic-year.
+ */
+ static final ValueRange YEAR_RANGE = ValueRange.of(-999_998, 999_999);
+ /**
+ * Range of year.
+ */
+ static final ValueRange YOE_RANGE = ValueRange.of(1, 999_999);
+ /**
+ * Range of proleptic month.
+ */
+ static final ValueRange PROLEPTIC_MONTH_RANGE = ValueRange.of(-999_998 * 12L, 999_999 * 12L + 11);
+
+ /**
+ * Private constructor, that is public to satisfy the {@code ServiceLoader}.
+ * @deprecated Use the singleton {@link #INSTANCE} instead.
+ */
+ @Deprecated
+ public HybridChronology() {
+ }
+
+ /**
+ * Resolve singleton.
+ *
+ * @return the singleton instance, not null
+ */
+ private Object readResolve() {
+ return INSTANCE;
+ }
+
+ //-------------------------------------------------------------------------
+ /**
+ * Gets the cutover date between the Julian and Gregorian calendar.
+ * <p>
+ * The date returned is the first date that the Gregorian (ISO) calendar applies,
+ * which is Thursday 14th September 1752.
+ *
+ * @return the first date after the cutover, not null
+ */
+ public LocalDate getCutover() {
+ return CUTOVER;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Gets the ID of the chronology - 'Hybrid'.
+ * <p>
+ * The ID uniquely identifies the {@code Chronology}.
+ * It can be used to lookup the {@code Chronology} using {@link Chronology#of(String)}.
+ *
+ * @return the chronology ID - 'Hybrid'
+ * @see #getCalendarType()
+ */
+ @Override
+ public String getId() {
+ return "Hybrid";
+ }
+
+ /**
+ * Gets the calendar type of the underlying calendar system, which returns null.
+ * <p>
+ * The <em>Unicode Locale Data Markup Language (LDML)</em> specification
+ * does not define an identifier for this calendar system, thus null is returned.
+ *
+ * @return the calendar system type, null
+ * @see #getId()
+ */
+ @Override
+ public String getCalendarType() {
+ return null;
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Obtains a local date in British Cutover calendar system from the
+ * era, year-of-era, month-of-year and day-of-month fields.
+ * <p>
+ * Dates in the middle of the cutover gap, such as the 10th September 1752,
+ * will not throw an exception. Instead, the date will be treated as a Julian date
+ * and converted to an ISO date, with the day of month shifted by 11 days.
+ *
+ * @param era the British Cutover era, not null
+ * @param yearOfEra the year-of-era
+ * @param month the month-of-year
+ * @param dayOfMonth the day-of-month
+ * @return the British Cutover local date, not null
+ * @throws DateTimeException if unable to create the date
+ * @throws ClassCastException if the {@code era} is not a {@code JulianEra}
+ */
+ @Override
+ public HybridDate date(Era era, int yearOfEra, int month, int dayOfMonth) {
+ return date(prolepticYear(era, yearOfEra), month, dayOfMonth);
+ }
+
+ /**
+ * Obtains a local date in British Cutover calendar system from the
+ * proleptic-year, month-of-year and day-of-month fields.
+ * <p>
+ * Dates in the middle of the cutover gap, such as the 10th September 1752,
+ * will not throw an exception. Instead, the date will be treated as a Julian date
+ * and converted to an ISO date, with the day of month shifted by 11 days.
+ *
+ * @param prolepticYear the proleptic-year
+ * @param month the month-of-year
+ * @param dayOfMonth the day-of-month
+ * @return the British Cutover local date, not null
+ * @throws DateTimeException if unable to create the date
+ */
+ @Override
+ public HybridDate date(int prolepticYear, int month, int dayOfMonth) {
+ return HybridDate.of(prolepticYear, month, dayOfMonth);
+ }
+
+ /**
+ * Obtains a local date in British Cutover calendar system from the
+ * era, year-of-era and day-of-year fields.
+ * <p>
+ * The day-of-year takes into account the cutover, thus there are only 355 days in 1752.
+ *
+ * @param era the British Cutover era, not null
+ * @param yearOfEra the year-of-era
+ * @param dayOfYear the day-of-year
+ * @return the British Cutover local date, not null
+ * @throws DateTimeException if unable to create the date
+ * @throws ClassCastException if the {@code era} is not a {@code JulianEra}
+ */
+ @Override
+ public HybridDate dateYearDay(Era era, int yearOfEra, int dayOfYear) {
+ return dateYearDay(prolepticYear(era, yearOfEra), dayOfYear);
+ }
+
+ /**
+ * Obtains a local date in British Cutover calendar system from the
+ * proleptic-year and day-of-year fields.
+ * <p>
+ * The day-of-year takes into account the cutover, thus there are only 355 days in 1752.
+ *
+ * @param prolepticYear the proleptic-year
+ * @param dayOfYear the day-of-year
+ * @return the British Cutover local date, not null
+ * @throws DateTimeException if unable to create the date
+ */
+ @Override
+ public HybridDate dateYearDay(int prolepticYear, int dayOfYear) {
+ return HybridDate.ofYearDay(prolepticYear, dayOfYear);
+ }
+
+ /**
+ * Obtains a local date in the British Cutover calendar system from the epoch-day.
+ *
+ * @param epochDay the epoch day
+ * @return the British Cutover local date, not null
+ * @throws DateTimeException if unable to create the date
+ */
+ @Override // override with covariant return type
+ public HybridDate dateEpochDay(long epochDay) {
+ return HybridDate.ofEpochDay(epochDay);
+ }
+
+ //-------------------------------------------------------------------------
+ /**
+ * Obtains the current British Cutover local date from the system clock in the default time-zone.
+ * <p>
+ * This will query the {@link Clock#systemDefaultZone() system clock} in the default
+ * time-zone to obtain the current date.
+ * <p>
+ * Using this method will prevent the ability to use an alternate clock for testing
+ * because the clock is hard-coded.
+ *
+ * @return the current British Cutover local date using the system clock and default time-zone, not null
+ * @throws DateTimeException if unable to create the date
+ */
+ @Override // override with covariant return type
+ public HybridDate dateNow() {
+ return HybridDate.now();
+ }
+
+ /**
+ * Obtains the current British Cutover local date from the system clock in the specified time-zone.
+ * <p>
+ * This will query the {@link Clock#system(ZoneId) system clock} to obtain the current date.
+ * Specifying the time-zone avoids dependence on the default time-zone.
+ * <p>
+ * Using this method will prevent the ability to use an alternate clock for testing
+ * because the clock is hard-coded.
+ *
+ * @param zone the zone ID to use, not null
+ * @return the current British Cutover local date using the system clock, not null
+ * @throws DateTimeException if unable to create the date
+ */
+ @Override // override with covariant return type
+ public HybridDate dateNow(ZoneId zone) {
+ return HybridDate.now(zone);
+ }
+
+ /**
+ * Obtains the current British Cutover local date from the specified clock.
+ * <p>
+ * This will query the specified clock to obtain the current date - today.
+ * Using this method allows the use of an alternate clock for testing.
+ * The alternate clock may be introduced using {@link Clock dependency injection}.
+ *
+ * @param clock the clock to use, not null
+ * @return the current British Cutover local date, not null
+ * @throws DateTimeException if unable to create the date
+ */
+ @Override // override with covariant return type
+ public HybridDate dateNow(Clock clock) {
+ return HybridDate.now(clock);
+ }
+
+ //-------------------------------------------------------------------------
+ /**
+ * Obtains a British Cutover local date from another date-time object.
+ *
+ * @param temporal the date-time object to convert, not null
+ * @return the British Cutover local date, not null
+ * @throws DateTimeException if unable to create the date
+ */
+ @Override
+ public HybridDate date(TemporalAccessor temporal) {
+ return HybridDate.from(temporal);
+ }
+
+ /**
+ * Obtains a British Cutover local date-time from another date-time object.
+ *
+ * @param temporal the date-time object to convert, not null
+ * @return the British Cutover local date-time, not null
+ * @throws DateTimeException if unable to create the date-time
+ */
+ @Override
+ @SuppressWarnings("unchecked")
+ public ChronoLocalDateTime<HybridDate> localDateTime(TemporalAccessor temporal) {
+ return (ChronoLocalDateTime<HybridDate>) super.localDateTime(temporal);
+ }
+
+ /**
+ * Obtains a British Cutover zoned date-time from another date-time object.
+ *
+ * @param temporal the date-time object to convert, not null
+ * @return the British Cutover zoned date-time, not null
+ * @throws DateTimeException if unable to create the date-time
+ */
+ @Override
+ @SuppressWarnings("unchecked")
+ public ChronoZonedDateTime<HybridDate> zonedDateTime(TemporalAccessor temporal) {
+ return (ChronoZonedDateTime<HybridDate>) super.zonedDateTime(temporal);
+ }
+
+ /**
+ * Obtains a British Cutover zoned date-time in this chronology from an {@code Instant}.
+ *
+ * @param instant the instant to create the date-time from, not null
+ * @param zone the time-zone, not null
+ * @return the British Cutover zoned date-time, not null
+ * @throws DateTimeException if the result exceeds the supported range
+ */
+ @Override
+ @SuppressWarnings("unchecked")
+ public ChronoZonedDateTime<HybridDate> zonedDateTime(Instant instant, ZoneId zone) {
+ return (ChronoZonedDateTime<HybridDate>) super.zonedDateTime(instant, zone);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Checks if the specified year is a leap year.
+ * <p>
+ * The result will return the same as {@link JulianChronology#isLeapYear(long)} for
+ * year 1752 and earlier, and {@link IsoChronology#isLeapYear(long)} otherwise.
+ * This method does not validate the year passed in, and only has a
+ * well-defined result for years in the supported range.
+ *
+ * @param prolepticYear the proleptic-year to check, not validated for range
+ * @return true if the year is a leap year
+ */
+ @Override
+ public boolean isLeapYear(long prolepticYear) {
+ if (prolepticYear <= CUTOVER_YEAR) {
+ return JulianChronology.INSTANCE.isLeapYear(prolepticYear);
+ }
+ return IsoChronology.INSTANCE.isLeapYear(prolepticYear);
+ }
+
+ @Override
+ public int prolepticYear(Era era, int yearOfEra) {
+ if (era instanceof JulianEra == false) {
+ throw new ClassCastException("Era must be JulianEra");
+ }
+ return (era == JulianEra.AD ? yearOfEra : 1 - yearOfEra);
+ }
+
+ @Override
+ public JulianEra eraOf(int eraValue) {
+ return JulianEra.of(eraValue);
+ }
+
+ @Override
+ public List<Era> eras() {
+ return Arrays.<Era>asList(JulianEra.values());
+ }
+
+ //-----------------------------------------------------------------------
+ @Override
+ public ValueRange range(ChronoField field) {
+ switch (field) {
+ case DAY_OF_YEAR:
+ return DOY_RANGE;
+ case ALIGNED_WEEK_OF_MONTH:
+ return ALIGNED_WOM_RANGE;
+ case ALIGNED_WEEK_OF_YEAR:
+ return ALIGNED_WOY_RANGE;
+ case PROLEPTIC_MONTH:
+ return PROLEPTIC_MONTH_RANGE;
+ case YEAR_OF_ERA:
+ return YOE_RANGE;
+ case YEAR:
+ return YEAR_RANGE;
+ default:
+ break;
+ }
+ return field.range();
+ }
+
+ //-----------------------------------------------------------------------
+ @Override // override for return type
+ public HybridDate resolveDate(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
+ return (HybridDate) super.resolveDate(fieldValues, resolverStyle);
+ }
+
+}
diff --git a/java/core/src/java/org/threeten/extra/chrono/HybridDate.java b/java/core/src/java/org/threeten/extra/chrono/HybridDate.java
new file mode 100644
index 0000000..c2f87c5
--- /dev/null
+++ b/java/core/src/java/org/threeten/extra/chrono/HybridDate.java
@@ -0,0 +1,537 @@
+/*
+ * 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.
+ */
+package org.threeten.extra.chrono;
+
+import static org.threeten.extra.chrono.HybridChronology.CUTOVER;
+import static org.threeten.extra.chrono.HybridChronology.CUTOVER_DAYS;
+import static org.threeten.extra.chrono.HybridChronology.CUTOVER_YEAR;
+
+import java.io.Serializable;
+import java.time.Clock;
+import java.time.DateTimeException;
+import java.time.LocalDate;
+import java.time.LocalTime;
+import java.time.ZoneId;
+import java.time.chrono.ChronoLocalDate;
+import java.time.chrono.ChronoLocalDateTime;
+import java.time.chrono.ChronoPeriod;
+import java.time.temporal.ChronoField;
+import java.time.temporal.Temporal;
+import java.time.temporal.TemporalAccessor;
+import java.time.temporal.TemporalAdjuster;
+import java.time.temporal.TemporalAmount;
+import java.time.temporal.TemporalField;
+import java.time.temporal.TemporalQueries;
+import java.time.temporal.TemporalQuery;
+import java.time.temporal.TemporalUnit;
+import java.time.temporal.ValueRange;
+import java.util.Objects;
+
+/**
+ * A date in the British Cutover calendar system.
+ * <p>
+ * This date operates using the {@linkplain HybridChronology British Cutover calendar}.
+ *
+ * <h3>Implementation Requirements</h3>
+ * This class is immutable and thread-safe.
+ * <p>
+ * This class must be treated as a value type. Do not synchronize, rely on the
+ * identity hash code or use the distinction between equals() and ==.
+ */
+public final class HybridDate
+ extends AbstractDate
+ implements ChronoLocalDate, Serializable {
+ /**
+ * Serialization version.
+ */
+ private static final long serialVersionUID = -9626278512674L;
+ /**
+ * The underlying date.
+ */
+ private final LocalDate isoDate;
+ /**
+ * The underlying Julian date if before the cutover.
+ */
+ private final transient JulianDate julianDate;
+
+ //-----------------------------------------------------------------------
+ /**
+ * Obtains the current {@code HybridDate} from the system clock in the default time-zone.
+ * <p>
+ * This will query the {@link Clock#systemDefaultZone() system clock} in the default
+ * time-zone to obtain the current date.
+ * <p>
+ * Using this method will prevent the ability to use an alternate clock for testing
+ * because the clock is hard-coded.
+ *
+ * @return the current date using the system clock and default time-zone, not null
+ */
+ public static HybridDate now() {
+ return now(Clock.systemDefaultZone());
+ }
+
+ /**
+ * Obtains the current {@code HybridDate} from the system clock in the specified time-zone.
+ * <p>
+ * This will query the {@link Clock#system(ZoneId) system clock} to obtain the current date.
+ * Specifying the time-zone avoids dependence on the default time-zone.
+ * <p>
+ * Using this method will prevent the ability to use an alternate clock for testing
+ * because the clock is hard-coded.
+ *
+ * @param zone the zone ID to use, not null
+ * @return the current date using the system clock, not null
+ */
+ public static HybridDate now(ZoneId zone) {
+ return now(Clock.system(zone));
+ }
+
+ /**
+ * Obtains the current {@code HybridDate} from the specified clock.
+ * <p>
+ * This will query the specified clock to obtain the current date - today.
+ * Using this method allows the use of an alternate clock for testing.
+ * The alternate clock may be introduced using {@linkplain Clock dependency injection}.
+ *
+ * @param clock the clock to use, not null
+ * @return the current date, not null
+ * @throws DateTimeException if the current date cannot be obtained
+ */
+ public static HybridDate now(Clock clock) {
+ return new HybridDate(LocalDate.now(clock));
+ }
+
+ /**
+ * Obtains a {@code HybridDate} representing a date in the British Cutover calendar
+ * system from the proleptic-year, month-of-year and day-of-month fields.
+ * <p>
+ * This returns a {@code HybridDate} with the specified fields.
+ * <p>
+ * Dates in the middle of the cutover gap, such as the 10th September 1752,
+ * will not throw an exception. Instead, the date will be treated as a Julian date
+ * and converted to an ISO date, with the day of month shifted by 11 days.
+ * <p>
+ * Invalid dates, such as September 31st will throw an exception.
+ *
+ * @param prolepticYear the British Cutover proleptic-year
+ * @param month the British Cutover month-of-year, from 1 to 12
+ * @param dayOfMonth the British Cutover day-of-month, from 1 to 31
+ * @return the date in British Cutover calendar system, not null
+ * @throws DateTimeException if the value of any field is out of range,
+ * or if the day-of-month is invalid for the month-year
+ */
+ public static HybridDate of(int prolepticYear, int month, int dayOfMonth) {
+ return HybridDate.create(prolepticYear, month, dayOfMonth);
+ }
+
+ /**
+ * Obtains a {@code HybridDate} from a temporal object.
+ * <p>
+ * This obtains a date in the British Cutover calendar system based on the specified temporal.
+ * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
+ * which this factory converts to an instance of {@code HybridDate}.
+ * <p>
+ * The conversion uses the {@link ChronoField#EPOCH_DAY EPOCH_DAY}
+ * field, which is standardized across calendar systems.
+ * <p>
+ * This method matches the signature of the functional interface {@link TemporalQuery}
+ * allowing it to be used as a query via method reference, {@code HybridDate::from}.
+ *
+ * @param temporal the temporal object to convert, not null
+ * @return the date in British Cutover calendar system, not null
+ * @throws DateTimeException if unable to convert to a {@code HybridDate}
+ */
+ public static HybridDate from(TemporalAccessor temporal) {
+ if (temporal instanceof HybridDate) {
+ return (HybridDate) temporal;
+ }
+ return new HybridDate(LocalDate.from(temporal));
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Obtains a {@code HybridDate} representing a date in the British Cutover calendar
+ * system from the proleptic-year and day-of-year fields.
+ * <p>
+ * This returns a {@code HybridDate} with the specified fields.
+ * The day must be valid for the year, otherwise an exception will be thrown.
+ *
+ * @param prolepticYear the British Cutover proleptic-year
+ * @param dayOfYear the British Cutover day-of-year, from 1 to 366
+ * @return the date in British Cutover calendar system, not null
+ * @throws DateTimeException if the value of any field is out of range,
+ * or if the day-of-year is invalid for the year
+ */
+ static HybridDate ofYearDay(int prolepticYear, int dayOfYear) {
+ if (prolepticYear < CUTOVER_YEAR || (prolepticYear == CUTOVER_YEAR && dayOfYear <= 246)) {
+ JulianDate julian = JulianDate.ofYearDay(prolepticYear, dayOfYear);
+ return new HybridDate(julian);
+ } else if (prolepticYear == CUTOVER_YEAR) {
+ LocalDate iso = LocalDate.ofYearDay(prolepticYear, dayOfYear + CUTOVER_DAYS);
+ return new HybridDate(iso);
+ } else {
+ LocalDate iso = LocalDate.ofYearDay(prolepticYear, dayOfYear);
+ return new HybridDate(iso);
+ }
+ }
+
+ /**
+ * Obtains a {@code HybridDate} representing a date in the British Cutover calendar
+ * system from the epoch-day.
+ *
+ * @param epochDay the epoch day to convert based on 1970-01-01 (ISO)
+ * @return the date in British Cutover calendar system, not null
+ * @throws DateTimeException if the epoch-day is out of range
+ */
+ static HybridDate ofEpochDay(final long epochDay) {
+ return new HybridDate(LocalDate.ofEpochDay(epochDay));
+ }
+
+ /**
+ * Creates a {@code HybridDate} validating the input.
+ *
+ * @param prolepticYear the British Cutover proleptic-year
+ * @param month the British Cutover month-of-year, from 1 to 12
+ * @param dayOfMonth the British Cutover day-of-month, from 1 to 31
+ * @return the date in British Cutover calendar system, not null
+ * @throws DateTimeException if the value of any field is out of range,
+ * or if the day-of-month is invalid for the month-year
+ */
+ static HybridDate create(int prolepticYear, int month, int dayOfMonth) {
+ if (prolepticYear < CUTOVER_YEAR) {
+ JulianDate julian = JulianDate.of(prolepticYear, month, dayOfMonth);
+ return new HybridDate(julian);
+ } else {
+ LocalDate iso = LocalDate.of(prolepticYear, month, dayOfMonth);
+ if (iso.isBefore(CUTOVER)) {
+ JulianDate julian = JulianDate.of(prolepticYear, month, dayOfMonth);
+ return new HybridDate(julian);
+ }
+ return new HybridDate(iso);
+ }
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Creates an instance from an ISO date.
+ *
+ * @param isoDate the standard local date, not null
+ */
+ HybridDate(LocalDate isoDate) {
+ Objects.requireNonNull(isoDate, "isoDate");
+ this.isoDate = isoDate;
+ this.julianDate = (isoDate.isBefore(CUTOVER) ? JulianDate.from(isoDate) : null);
+ }
+
+ /**
+ * Creates an instance from a Julian date.
+ *
+ * @param julianDate the Julian date before the cutover, not null
+ */
+ HybridDate(JulianDate julianDate) {
+ Objects.requireNonNull(julianDate, "julianDate");
+ this.isoDate = LocalDate.from(julianDate);
+ this.julianDate = (isoDate.isBefore(CUTOVER) ? julianDate : null);
+ }
+
+ /**
+ * Validates the object.
+ *
+ * @return the resolved date, not null
+ */
+ private Object readResolve() {
+ return new HybridDate(isoDate);
+ }
+
+ //-----------------------------------------------------------------------
+ private boolean isCutoverYear() {
+ return isoDate.getYear() == CUTOVER_YEAR && isoDate.getDayOfYear() > CUTOVER_DAYS;
+ }
+
+ private boolean isCutoverMonth() {
+ return isoDate.getYear() == CUTOVER_YEAR && isoDate.getMonthValue() == 9 && isoDate.getDayOfMonth() > CUTOVER_DAYS;
+ }
+
+ //-------------------------------------------------------------------------
+ @Override
+ int getAlignedDayOfWeekInMonth() {
+ if (isCutoverMonth() && julianDate == null) {
+ return ((getDayOfMonth() - 1 - CUTOVER_DAYS) % lengthOfWeek()) + 1;
+ }
+ return super.getAlignedDayOfWeekInMonth();
+ }
+
+ @Override
+ int getAlignedWeekOfMonth() {
+ if (isCutoverMonth() && julianDate == null) {
+ return ((getDayOfMonth() - 1 - CUTOVER_DAYS) / lengthOfWeek()) + 1;
+ }
+ return super.getAlignedWeekOfMonth();
+ }
+
+ @Override
+ int getProlepticYear() {
+ return (julianDate != null ? julianDate.getProlepticYear() : isoDate.getYear());
+ }
+
+ @Override
+ int getMonth() {
+ return (julianDate != null ? julianDate.getMonth() : isoDate.getMonthValue());
+ }
+
+ @Override
+ int getDayOfMonth() {
+ return (julianDate != null ? julianDate.getDayOfMonth() : isoDate.getDayOfMonth());
+ }
+
+ @Override
+ int getDayOfYear() {
+ if (julianDate != null) {
+ return julianDate.getDayOfYear();
+ }
+ if (isoDate.getYear() == CUTOVER_YEAR) {
+ return isoDate.getDayOfYear() - CUTOVER_DAYS;
+ }
+ return isoDate.getDayOfYear();
+ }
+
+ @Override
+ public ValueRange rangeChrono(ChronoField field) {
+ switch (field) {
+ case DAY_OF_MONTH:
+ // short length, but value range still 1 to 30
+ if (isCutoverMonth()) {
+ return ValueRange.of(1, 30);
+ }
+ return ValueRange.of(1, lengthOfMonth());
+ case DAY_OF_YEAR:
+ // 1 to 355 in cutover year, otherwise 1 to 365/366
+ return ValueRange.of(1, lengthOfYear());
+ case ALIGNED_WEEK_OF_MONTH:
+ // 1 to 3 in cutover month, otherwise 1 to 4/5
+ return rangeAlignedWeekOfMonth();
+ case ALIGNED_WEEK_OF_YEAR:
+ // 1 to 51 in cutover year, otherwise 1 to 53
+ if (isCutoverYear()) {
+ return ValueRange.of(1, 51);
+ }
+ return ChronoField.ALIGNED_WEEK_OF_YEAR.range();
+ default:
+ return getChronology().range(field);
+ }
+ }
+
+ @Override
+ ValueRange rangeAlignedWeekOfMonth() {
+ if (isCutoverMonth()) {
+ return ValueRange.of(1, 3);
+ }
+ return ValueRange.of(1, getMonth() == 2 && isLeapYear() == false ? 4 : 5);
+ }
+
+ @Override
+ HybridDate resolvePrevious(int year, int month, int dayOfMonth) {
+ switch (month) {
+ case 2:
+ dayOfMonth = Math.min(dayOfMonth, getChronology().isLeapYear(year) ? 29 : 28);
+ break;
+ case 4:
+ case 6:
+ case 9:
+ case 11:
+ dayOfMonth = Math.min(dayOfMonth, 30);
+ break;
+ default:
+ break;
+ }
+ return create(year, month, dayOfMonth);
+ }
+
+ //-----------------------------------------------------------------------
+ /**
+ * Gets the chronology of this date, which is the British Cutover calendar system.
+ * <p>
+ * The {@code Chronology} represents the calendar system in use.
+ * The era and other fields in {@link ChronoField} are defined by the chronology.
+ *
+ * @return the British Cutover chronology, not null
+ */
+ @Override
+ public HybridChronology getChronology() {
+ return HybridChronology.INSTANCE;
+ }
+
+ /**
+ * Gets the era applicable at this date.
+ * <p>
+ * The British Cutover calendar system has two eras, 'AD' and 'BC',
+ * defined by {@link JulianEra}.
+ *
+ * @return the era applicable at this date, not null
+ */
+ @Override
+ public JulianEra getEra() {
+ return (getProlepticYear() >= 1 ? JulianEra.AD : JulianEra.BC);
+ }
+
+ /**
+ * Returns the length of the month represented by this date.
+ * <p>
+ * This returns the length of the month in days.
+ * This takes into account the cutover, returning 19 in September 1752.
+ *
+ * @return the length of the month in days, from 19 to 31
+ */
+ @Override
+ public int lengthOfMonth() {
+ if (isCutoverMonth()) {
+ return 19;
+ }
+ return (julianDate != null ? julianDate.lengthOfMonth() : isoDate.lengthOfMonth());
+ }
+
+ /**
+ * Returns the length of the year represented by this date.
+ * <p>
+ * This returns the length of the year in days.
+ * This takes into account the cutover, returning 355 in 1752.
+ *
+ * @return the length of the month in days, from 19 to 31
+ */
+ @Override
+ public int lengthOfYear() {
+ if (isCutoverYear()) {
+ return 355;
+ }
+ return (julianDate != null ? julianDate.lengthOfYear() : isoDate.lengthOfYear());
+ }
+
+ //-------------------------------------------------------------------------
+ @Override
+ public HybridDate with(TemporalAdjuster adjuster) {
+ return (HybridDate) adjuster.adjustInto(this);
+ }
+
+ @Override
+ public HybridDate with(TemporalField field, long newValue) {
+ return (HybridDate) super.with(field, newValue);
+ }
+
+ //-----------------------------------------------------------------------
+ @Override
+ public HybridDate plus(TemporalAmount amount) {
+ return (HybridDate) amount.addTo(this);
+ }
+
+ @Override
+ public HybridDate plus(long amountToAdd, TemporalUnit unit) {
+ return (HybridDate) super.plus(amountToAdd, unit);
+ }
+
+ @Override
+ public HybridDate minus(TemporalAmount amount) {
+ return (HybridDate) amount.subtractFrom(this);
+ }
+
+ @Override
+ public HybridDate minus(long amountToSubtract, TemporalUnit unit) {
+ return (amountToSubtract == Long.MIN_VALUE ? plus(Long.MAX_VALUE, unit).plus(1, unit) : plus(-amountToSubtract, unit));
+ }
+
+ //-------------------------------------------------------------------------
+ @Override // for covariant return type
+ @SuppressWarnings("unchecked")
+ public ChronoLocalDateTime<HybridDate> atTime(LocalTime localTime) {
+ return (ChronoLocalDateTime<HybridDate>) super.atTime(localTime);
+ }
+
+ @Override
+ public long until(Temporal endExclusive, TemporalUnit unit) {
+ return super.until(HybridDate.from(endExclusive), unit);
+ }
+
+ @Override
+ public ChronoPeriod until(ChronoLocalDate endDateExclusive) {
+ HybridDate end = HybridDate.from(endDateExclusive);
+ long totalMonths = end.getProlepticMonth() - this.getProlepticMonth(); // safe
+ int days = end.getDayOfMonth() - this.getDayOfMonth();
+ if (totalMonths == 0 && isCutoverMonth()) {
+ if (julianDate != null && end.julianDate == null) {
+ days -= CUTOVER_DAYS;
+ } else if (julianDate == null && end.julianDate != null) {
+ days += CUTOVER_DAYS;
+ }
+ } else if (totalMonths > 0) {
+ if (julianDate != null && end.julianDate == null) {
+ AbstractDate calcDate = this.plusMonths(totalMonths);
+ days = (int) (end.toEpochDay() - calcDate.toEpochDay()); // safe
+ }
+ if (days < 0) {
+ totalMonths--;
+ AbstractDate calcDate = this.plusMonths(totalMonths);
+ days = (int) (end.toEpochDay() - calcDate.toEpochDay()); // safe
+ }
+ } else if (totalMonths < 0 && days > 0) {
+ totalMonths++;
+ AbstractDate calcDate = this.plusMonths(totalMonths);
+ days = (int) (end.toEpochDay() - calcDate.toEpochDay()); // safe
+ }
+ int years = Math.toIntExact(totalMonths / lengthOfYearInMonths()); // safe
+ int months = (int) (totalMonths % lengthOfYearInMonths()); // safe
+ return getChronology().period(years, months, days);
+ }
+
+ //-----------------------------------------------------------------------
+ @Override
+ public long toEpochDay() {
+ return isoDate.toEpochDay();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <R> R query(TemporalQuery<R> query) {
+ if (query == TemporalQueries.localDate()) {
+ return (R) isoDate;
+ }
+ return super.query(query);
+ }
+
+ //-------------------------------------------------------------------------
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof HybridDate) {
+ HybridDate otherDate = (HybridDate) obj;
+ return this.isoDate.equals(otherDate.isoDate);
+ }
+ return false;
+ }
+
+ /**
+ * A hash code for this date.
+ *
+ * @return a suitable hash code based only on the Chronology and the date
+ */
+ @Override
+ public int hashCode() {
+ return getChronology().getId().hashCode() ^ isoDate.hashCode();
+ }
+
+}
diff --git a/java/core/src/test/org/apache/orc/TestProlepticConversions.java b/java/core/src/test/org/apache/orc/TestProlepticConversions.java
index 4d18412..8320058 100644
--- a/java/core/src/test/org/apache/orc/TestProlepticConversions.java
+++ b/java/core/src/test/org/apache/orc/TestProlepticConversions.java
@@ -20,9 +20,14 @@ package org.apache.orc;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hive.ql.exec.vector.BytesColumnVector;
import org.apache.hadoop.hive.ql.exec.vector.DateColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.Decimal64ColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.DoubleColumnVector;
+import org.apache.hadoop.hive.ql.exec.vector.LongColumnVector;
import org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector;
import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatch;
+import org.apache.orc.impl.DateUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -31,6 +36,7 @@ import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.io.File;
+import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
@@ -43,6 +49,10 @@ import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+/**
+ * This class tests all of the combinations of reading and writing the hybrid
+ * and proleptic calendars.
+ */
@RunWith(Parameterized.class)
public class TestProlepticConversions {
@@ -174,4 +184,180 @@ public class TestProlepticConversions {
}
}
}
+
+ /**
+ * Test all of the type conversions from/to date.
+ */
+ @Test
+ public void testSchemaEvolutionDate() throws Exception {
+ TypeDescription schema = TypeDescription.fromString(
+ "struct<d2s:date,d2t:date,s2d:string,t2d:timestamp>");
+ try (Writer writer = OrcFile.createWriter(testFilePath,
+ OrcFile.writerOptions(conf)
+ .setSchema(schema)
+ .fileSystem(fs)
+ .setProlepticGregorian(writerProlepticGregorian)
+ .useUTCTimestamp(true))) {
+ VectorizedRowBatch batch = schema.createRowBatchV2();
+ batch.size = 1024;
+ DateColumnVector d2s = (DateColumnVector) batch.cols[0];
+ DateColumnVector d2t = (DateColumnVector) batch.cols[1];
+ BytesColumnVector s2d = (BytesColumnVector) batch.cols[2];
+ TimestampColumnVector t2d = (TimestampColumnVector) batch.cols[3];
+ d2s.changeCalendar(writerProlepticGregorian, false);
+ d2t.changeCalendar(writerProlepticGregorian, false);
+ t2d.changeCalendar(writerProlepticGregorian, false);
+ GregorianCalendar cal = writerProlepticGregorian ? PROLEPTIC : HYBRID;
+ SimpleDateFormat dateFormat = createParser("yyyy-MM-dd", cal);
+ SimpleDateFormat timeFormat = createParser("yyyy-MM-dd HH:mm:ss", cal);
+ for(int r=0; r < batch.size; ++r) {
+ String date = String.format("%04d-01-23", r * 2 + 1);
+ String time = String.format("%04d-03-21 %02d:12:34", 2 * r + 1, r % 24);
+ d2s.vector[r] = TimeUnit.MILLISECONDS.toDays(dateFormat.parse(date).getTime());
+ d2t.vector[r] = d2s.vector[r];
+ s2d.setVal(r, date.getBytes(StandardCharsets.UTF_8));
+ t2d.time[r] = timeFormat.parse(time).getTime();
+ t2d.nanos[r] = 0;
+ }
+ writer.addRowBatch(batch);
+ }
+ TypeDescription readerSchema = TypeDescription.fromString(
+ "struct<d2s:string,d2t:timestamp,s2d:date,t2d:date>");
+ try (Reader reader = OrcFile.createReader(testFilePath,
+ OrcFile.readerOptions(conf)
+ .filesystem(fs)
+ .convertToProlepticGregorian(readerProlepticGregorian)
+ .useUTCTimestamp(true));
+ RecordReader rows = reader.rows(reader.options()
+ .schema(readerSchema))) {
+ assertEquals(writerProlepticGregorian, reader.writerUsedProlepticGregorian());
+ VectorizedRowBatch batch = readerSchema.createRowBatchV2();
+ BytesColumnVector d2s = (BytesColumnVector) batch.cols[0];
+ TimestampColumnVector d2t = (TimestampColumnVector) batch.cols[1];
+ DateColumnVector s2d = (DateColumnVector) batch.cols[2];
+ DateColumnVector t2d = (DateColumnVector) batch.cols[3];
+ GregorianCalendar cal = readerProlepticGregorian ? PROLEPTIC : HYBRID;
+ SimpleDateFormat dateFormat = createParser("yyyy-MM-dd", cal);
+ SimpleDateFormat timeFormat = createParser("yyyy-MM-dd HH:mm:ss", cal);
+
+ // Check the data
+ assertTrue(rows.nextBatch(batch));
+ assertEquals(1024, batch.size);
+ // Ensure the column vectors are using the right calendar
+ assertEquals(readerProlepticGregorian, d2t.usingProlepticCalendar());
+ assertEquals(readerProlepticGregorian, s2d.isUsingProlepticCalendar());
+ assertEquals(readerProlepticGregorian, t2d.isUsingProlepticCalendar());
+ for(int r=0; r < batch.size; ++r) {
+ String expectedD1 = String.format("%04d-01-23", 2 * r + 1);
+ String expectedD2 = expectedD1 + " 00:00:00";
+ String expectedT = String.format("%04d-03-21", 2 * r + 1);
+ assertEquals("row " + r, expectedD1, d2s.toString(r));
+ assertEquals("row " + r, expectedD2, timeFormat.format(d2t.asScratchTimestamp(r)));
+ assertEquals("row " + r, expectedD1, DateUtils.printDate((int) s2d.vector[r],
+ readerProlepticGregorian));
+ assertEquals("row " + r, expectedT, dateFormat.format(
+ new Date(TimeUnit.DAYS.toMillis(t2d.vector[r]))));
+ }
+ assertEquals(false, rows.nextBatch(batch));
+ }
+ }
+
+ /**
+ * Test all of the type conversions from/to timestamp, except for date,
+ * which was handled above.
+ */
+ @Test
+ public void testSchemaEvolutionTimestamp() throws Exception {
+ TypeDescription schema = TypeDescription.fromString(
+ "struct<t2i:timestamp,t2d:timestamp,t2D:timestamp,t2s:timestamp,"
+ + "i2t:bigint,d2t:decimal(18,2),D2t:double,s2t:string>");
+ try (Writer writer = OrcFile.createWriter(testFilePath,
+ OrcFile.writerOptions(conf)
+ .setSchema(schema)
+ .fileSystem(fs)
+ .setProlepticGregorian(writerProlepticGregorian)
+ .useUTCTimestamp(true))) {
+ VectorizedRowBatch batch = schema.createRowBatchV2();
+ batch.size = 1024;
+ TimestampColumnVector t2i = (TimestampColumnVector) batch.cols[0];
+ TimestampColumnVector t2d = (TimestampColumnVector) batch.cols[1];
+ TimestampColumnVector t2D = (TimestampColumnVector) batch.cols[2];
+ TimestampColumnVector t2s = (TimestampColumnVector) batch.cols[3];
+ LongColumnVector i2t = (LongColumnVector) batch.cols[4];
+ Decimal64ColumnVector d2t = (Decimal64ColumnVector) batch.cols[5];
+ DoubleColumnVector D2t = (DoubleColumnVector) batch.cols[6];
+ BytesColumnVector s2t = (BytesColumnVector) batch.cols[7];
+
+ t2i.changeCalendar(writerProlepticGregorian, false);
+ t2d.changeCalendar(writerProlepticGregorian, false);
+ t2D.changeCalendar(writerProlepticGregorian, false);
+ t2s.changeCalendar(writerProlepticGregorian, false);
+
+ for(int r=0; r < batch.size; ++r) {
+ String time = String.format("%04d-03-21 %02d:12:34.12", 2 * r + 1, r % 24);
+ long millis = DateUtils.parseTime(time, writerProlepticGregorian, true);
+ int nanos = (int) Math.floorMod(millis, 1000) * 1_000_000;
+ t2i.time[r] = millis;
+ t2i.nanos[r] = nanos;
+ t2d.time[r] = millis;
+ t2d.nanos[r] = nanos;
+ t2D.time[r] = millis;
+ t2D.nanos[r] = nanos;
+ t2s.time[r] = millis;
+ t2s.nanos[r] = nanos;
+ i2t.vector[r] = millis;
+ d2t.vector[r] = Math.floorDiv(millis, 10);
+ D2t.vector[r] = millis / 1000.0;
+ s2t.setVal(r, time.getBytes(StandardCharsets.UTF_8));
+ }
+ writer.addRowBatch(batch);
+ }
+ TypeDescription readerSchema = TypeDescription.fromString(
+ "struct<i2t:timestamp,d2t:timestamp,D2t:timestamp,s2t:timestamp,"
+ + "t2i:bigint,t2d:decimal(18,2),t2D:double,t2s:string>");
+ try (Reader reader = OrcFile.createReader(testFilePath,
+ OrcFile.readerOptions(conf)
+ .filesystem(fs)
+ .convertToProlepticGregorian(readerProlepticGregorian)
+ .useUTCTimestamp(true));
+ RecordReader rows = reader.rows(reader.options()
+ .schema(readerSchema))) {
+ assertEquals(writerProlepticGregorian, reader.writerUsedProlepticGregorian());
+ VectorizedRowBatch batch = readerSchema.createRowBatchV2();
+ TimestampColumnVector i2t = (TimestampColumnVector) batch.cols[0];
+ TimestampColumnVector d2t = (TimestampColumnVector) batch.cols[1];
+ TimestampColumnVector D2t = (TimestampColumnVector) batch.cols[2];
+ TimestampColumnVector s2t = (TimestampColumnVector) batch.cols[3];
+ LongColumnVector t2i = (LongColumnVector) batch.cols[4];
+ Decimal64ColumnVector t2d = (Decimal64ColumnVector) batch.cols[5];
+ DoubleColumnVector t2D = (DoubleColumnVector) batch.cols[6];
+ BytesColumnVector t2s = (BytesColumnVector) batch.cols[7];
+
+ // Check the data
+ assertTrue(rows.nextBatch(batch));
+ assertEquals(1024, batch.size);
+ // Ensure the column vectors are using the right calendar
+ assertEquals(readerProlepticGregorian, i2t.usingProlepticCalendar());
+ assertEquals(readerProlepticGregorian, d2t.usingProlepticCalendar());
+ assertEquals(readerProlepticGregorian, D2t.usingProlepticCalendar());
+ assertEquals(readerProlepticGregorian, s2t.usingProlepticCalendar());
+ for(int r=0; r < batch.size; ++r) {
+ String time = String.format("%04d-03-21 %02d:12:34.12", 2 * r + 1, r % 24);
+ long millis = DateUtils.parseTime(time, readerProlepticGregorian, true);
+ assertEquals("row " + r, time,
+ DateUtils.printTime(i2t.time[r], readerProlepticGregorian, true));
+ assertEquals("row " + r, time,
+ DateUtils.printTime(d2t.time[r], readerProlepticGregorian, true));
+ assertEquals("row " + r, time,
+ DateUtils.printTime(D2t.time[r], readerProlepticGregorian, true));
+ assertEquals("row " + r, time,
+ DateUtils.printTime(s2t.time[r], readerProlepticGregorian, true));
+ assertEquals("row " + r, Math.floorDiv(millis, 1000), t2i.vector[r]);
+ assertEquals("row " + r, millis/10, t2d.vector[r]);
+ assertEquals("row " + r, millis/1000.0, t2D.vector[r], 0.1);
+ assertEquals("row " + r, time, t2s.toString(r));
+ }
+ assertEquals(false, rows.nextBatch(batch));
+ }
+ }
}
diff --git a/java/core/src/test/org/apache/orc/impl/TestDateUtils.java b/java/core/src/test/org/apache/orc/impl/TestDateUtils.java
new file mode 100644
index 0000000..5c75a1d
--- /dev/null
+++ b/java/core/src/test/org/apache/orc/impl/TestDateUtils.java
@@ -0,0 +1,60 @@
+/*
+ * 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.
+ */
+
+package org.apache.orc.impl;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestDateUtils {
+ /**
+ * Test case for DateColumnVector's changeCalendar
+ * epoch days, hybrid representation, proleptic representation
+ * 16768: hybrid: 2015-11-29 proleptic: 2015-11-29
+ * -141418: hybrid: 1582-10-24 proleptic: 1582-10-24
+ * -141427: hybrid: 1582-10-15 proleptic: 1582-10-15
+ * -141428: hybrid: 1582-10-04 proleptic: 1582-10-14
+ * -141430: hybrid: 1582-10-02 proleptic: 1582-10-12
+ * -141437: hybrid: 1582-09-25 proleptic: 1582-10-05
+ * -141438: hybrid: 1582-09-24 proleptic: 1582-10-04
+ * -499952: hybrid: 0601-03-04 proleptic: 0601-03-07
+ * -499955: hybrid: 0601-03-01 proleptic: 0601-03-04
+ * @throws Exception
+ */
+ @Test
+ public void testConversion() throws Exception {
+ checkConversion(16768, "2015-11-29", "2015-11-29");
+ checkConversion(-141418, "1582-10-24", "1582-10-24");
+ checkConversion(-141427, "1582-10-15", "1582-10-15");
+ checkConversion(-141428, "1582-10-04", "1582-10-14");
+ checkConversion(-141430, "1582-10-02", "1582-10-12");
+ checkConversion(-141437, "1582-09-25", "1582-10-05");
+ checkConversion(-499952, "0601-03-04", "0601-03-07");
+ checkConversion(-499955, "0601-03-01", "0601-03-04");
+ }
+
+ void checkConversion(int dayOfEpoch, String hybrid, String proleptic) {
+ String result = DateUtils.printDate(dayOfEpoch, false);
+ assertEquals("day " + dayOfEpoch, hybrid, result);
+ assertEquals(dayOfEpoch, (int) DateUtils.parseDate(result, false));
+ result = DateUtils.printDate(dayOfEpoch, true);
+ assertEquals("day " + dayOfEpoch, proleptic, result);
+ assertEquals(dayOfEpoch, (int) DateUtils.parseDate(result, true));
+ }
+}
diff --git a/java/core/src/test/org/apache/orc/impl/TestSchemaEvolution.java b/java/core/src/test/org/apache/orc/impl/TestSchemaEvolution.java
index 0f0e93b..2dd0633 100644
--- a/java/core/src/test/org/apache/orc/impl/TestSchemaEvolution.java
+++ b/java/core/src/test/org/apache/orc/impl/TestSchemaEvolution.java
@@ -1,4 +1,4 @@
-/**
+/*
* 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
@@ -23,11 +23,19 @@ import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeFormatterBuilder;
+import java.time.temporal.ChronoField;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.TimeZone;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
@@ -351,7 +359,7 @@ public class TestSchemaEvolution {
RecordReader rows = reader.rows(reader.options().schema(schemaOnRead));
batch = schemaOnRead.createRowBatch();
rows.nextBatch(batch);
- assertEquals(74.72, ((DoubleColumnVector) batch.cols[0]).vector[0], 0.00000000001);
+ assertEquals(74.72, ((DoubleColumnVector) batch.cols[0]).vector[0], 0.00001);
rows.close();
}
@@ -639,18 +647,27 @@ public class TestSchemaEvolution {
TimestampColumnVector tcv = new TimestampColumnVector(1024);
batch.cols[0] = tcv;
batch.reset();
- batch.size = 1;
+ batch.size = 3;
tcv.time[0] = 74000L;
+ tcv.nanos[0] = 123456789;
+ tcv.time[1] = 123000L;
+ tcv.nanos[1] = 456000000;
+ tcv.time[2] = 987000;
+ tcv.nanos[2] = 0;
writer.addRowBatch(batch);
writer.close();
Reader reader = OrcFile.createReader(testFilePath,
OrcFile.readerOptions(conf).filesystem(fs));
- TypeDescription schemaOnRead = TypeDescription.createDecimal().withPrecision(38).withScale(1);
+ TypeDescription schemaOnRead = TypeDescription.createDecimal().withPrecision(38).withScale(9);
RecordReader rows = reader.rows(reader.options().schema(schemaOnRead));
batch = schemaOnRead.createRowBatch();
- rows.nextBatch(batch);
- assertEquals("74", ((DecimalColumnVector) batch.cols[0]).vector[0].toString());
+ assertEquals(true, rows.nextBatch(batch));
+ assertEquals(3, batch.size);
+ DecimalColumnVector dcv = (DecimalColumnVector) batch.cols[0];
+ assertEquals("74.123456789", dcv.vector[0].toString());
+ assertEquals("123.456", dcv.vector[1].toString());
+ assertEquals("987", dcv.vector[2].toString());
rows.close();
}
@@ -682,6 +699,40 @@ public class TestSchemaEvolution {
}
@Test
+ public void testTimestampToStringEvolution() throws Exception {
+ testFilePath = new Path(workDir, "TestOrcFile." +
+ testCaseName.getMethodName() + ".orc");
+ TypeDescription schema = TypeDescription.fromString("timestamp");
+ Writer writer = OrcFile.createWriter(testFilePath,
+ OrcFile.writerOptions(conf).setSchema(schema).stripeSize(100000)
+ .bufferSize(10000).useUTCTimestamp(true));
+ VectorizedRowBatch batch = schema.createRowBatchV2();
+ TimestampColumnVector tcv = (TimestampColumnVector) batch.cols[0];
+ batch.size = 3;
+ tcv.time[0] = 74000L;
+ tcv.nanos[0] = 123456789;
+ tcv.time[1] = 123000L;
+ tcv.nanos[1] = 456000000;
+ tcv.time[2] = 987000;
+ tcv.nanos[2] = 0;
+ writer.addRowBatch(batch);
+ writer.close();
+
+ schema = TypeDescription.fromString("string");
+ Reader reader = OrcFile.createReader(testFilePath,
+ OrcFile.readerOptions(conf).filesystem(fs));
+ RecordReader rows = reader.rows(reader.options().schema(schema));
+ batch = schema.createRowBatchV2();
+ BytesColumnVector bcv = (BytesColumnVector) batch.cols[0];
+ assertEquals(true, rows.nextBatch(batch));
+ assertEquals(3, batch.size);
+ assertEquals("1970-01-01 00:01:14.123456789", bcv.toString(0));
+ assertEquals("1970-01-01 00:02:03.456", bcv.toString(1));
+ assertEquals("1970-01-01 00:16:27", bcv.toString(2));
+ rows.close();
+ }
+
+ @Test
public void testSafePpdEvaluation() throws IOException {
TypeDescription fileStruct1 = TypeDescription.createStruct()
.addField("f1", TypeDescription.createInt())
@@ -1219,6 +1270,7 @@ public class TestSchemaEvolution {
original = fileType.getChildren().get(1);
assertSame(original, mapped);
}
+
@Test
public void testCaseMismatchInReaderAndWriterSchema() {
TypeDescription fileType =
@@ -1651,6 +1703,622 @@ public class TestSchemaEvolution {
assertEquals(null, evo.getFileType(4));
}
+ // These are helper methods that pull some of the common code into one
+ // place.
+
+ static String decimalTimestampToString(long centiseconds, ZoneId zone) {
+ int nano = (int) (Math.floorMod(centiseconds, 100) * 10_000_000);
+ return timestampToString(centiseconds * 10, nano, zone);
+ }
+
+ static String doubleTimestampToString(double seconds, ZoneId zone) {
+ long sec = (long) Math.floor(seconds);
+ int nano = 1_000_000 * (int) Math.round((seconds - sec) * 1000);
+ return timestampToString(sec * 1000, nano, zone);
+ }
+
+ static String timestampToString(long millis, int nanos, ZoneId zone) {
+ return timestampToString(Instant.ofEpochSecond(Math.floorDiv(millis, 1000),
+ nanos), zone);
+ }
+
+ static String longTimestampToString(long millis, ZoneId zone) {
+ return timestampToString(Instant.ofEpochMilli(millis), zone);
+ }
+
+ static String timestampToString(Instant time, ZoneId zone) {
+ return time.atZone(zone)
+ .format(INSTANT_TIMESTAMP_FORMAT);
+ }
+
+ static void writeTimestampDataFile(Path path,
+ Configuration conf,
+ ZoneId writerZone,
+ DateTimeFormatter formatter,
+ String[] values) throws IOException {
+ TimeZone oldDefault = TimeZone.getDefault();
+ try {
+ TimeZone.setDefault(TimeZone.getTimeZone(writerZone));
+ TypeDescription fileSchema =
+ TypeDescription.fromString("struct<t1:timestamp>");
+ Writer writer = OrcFile.createWriter(path,
+ OrcFile.writerOptions(conf).setSchema(fileSchema).stripeSize(10000));
+ VectorizedRowBatch batch = fileSchema.createRowBatch(1024);
+ TimestampColumnVector t1 = (TimestampColumnVector) batch.cols[0];
+ for (int r = 0; r < values.length; ++r) {
+ int row = batch.size++;
+ Instant t = Instant.from(formatter.parse(values[r]));
+ t1.time[row] = t.toEpochMilli();
+ t1.nanos[row] = t.getNano();
+ if (batch.size == 1024) {
+ writer.addRowBatch(batch);
+ batch.reset();
+ }
+ }
+ if (batch.size != 0) {
+ writer.addRowBatch(batch);
+ }
+ writer.close();
+ } finally {
+ TimeZone.setDefault(oldDefault);
+ }
+ }
+
+ /**
+ * Tests the various conversions from timestamp and timestamp with local
+ * timezone.
+ *
+ * It writes an ORC file with timestamp and timestamp with local time zone
+ * and then reads it back in with each of the relevant types.
+ *
+ * This test test both with and without the useUtc flag.
+ *
+ * It uses Australia/Sydney and America/New_York because they both have
+ * DST and they move in opposite directions on different days. Thus, we
+ * end up with four sets of offsets.
+ *
+ * Picking the 27th of the month puts it around when DST changes.
+ */
+ @Test
+ public void testEvolutionFromTimestamp() throws Exception {
+ // The number of rows in the file that we test with.
+ final int VALUES = 1024;
+ // The different timezones that we'll use for this test.
+ final ZoneId UTC = ZoneId.of("UTC");
+ final ZoneId WRITER_ZONE = ZoneId.of("America/New_York");
+ final ZoneId READER_ZONE = ZoneId.of("Australia/Sydney");
+
+ final TimeZone oldDefault = TimeZone.getDefault();
+
+ // generate the timestamps to use
+ String[] timeStrings = new String[VALUES];
+ for(int r=0; r < timeStrings.length; ++r) {
+ timeStrings[r] = String.format("%04d-%02d-27 23:45:56.7",
+ 2000 + (r / 12), (r % 12) + 1);
+ }
+
+ final DateTimeFormatter WRITER_FORMAT =
+ ConvertTreeReaderFactory.TIMESTAMP_FORMAT.withZone(WRITER_ZONE);
+
+ writeTimestampDataFile(testFilePath, conf, WRITER_ZONE, WRITER_FORMAT, timeStrings);
+
+ try {
+ TimeZone.setDefault(TimeZone.getTimeZone(READER_ZONE));
+ OrcFile.ReaderOptions options = OrcFile.readerOptions(conf);
+ Reader.Options rowOptions = new Reader.Options();
+
+ try (Reader reader = OrcFile.createReader(testFilePath, options)) {
+
+ // test conversion to long
+ TypeDescription readerSchema = TypeDescription.fromString("struct<t1:bigint>");
+ try (RecordReader rows = reader.rows(rowOptions.schema(readerSchema))) {
+ VectorizedRowBatch batch = readerSchema.createRowBatch(VALUES);
+ LongColumnVector t1 = (LongColumnVector) batch.cols[0];
+ int current = 0;
+ for (int r = 0; r < VALUES; ++r) {
+ if (current == batch.size) {
+ assertEquals("row " + r, true, rows.nextBatch(batch));
+ current = 0;
+ }
+ assertEquals("row " + r, (timeStrings[r] + " " +
+ READER_ZONE.getId()).replace(".7 ", " "),
+ longTimestampToString(t1.vector[current] * 1000, READER_ZONE));
+ current += 1;
+ }
+ assertEquals(false, rows.nextBatch(batch));
+ }
+
+ // test conversion to decimal
+ readerSchema = TypeDescription.fromString("struct<t1:decimal(14,2)>");
+ try (RecordReader rows = reader.rows(rowOptions.schema(readerSchema))) {
+ VectorizedRowBatch batch = readerSchema.createRowBatchV2();
+ Decimal64ColumnVector t1 = (Decimal64ColumnVector) batch.cols[0];
+ int current = 0;
+ for (int r = 0; r < VALUES; ++r) {
+ if (current == batch.size) {
+ assertEquals("row " + r, true, rows.nextBatch(batch));
+ current = 0;
+ }
+ assertEquals("row " + r, timeStrings[r] + " " + READER_ZONE.getId(),
+ decimalTimestampToString(t1.vector[current], READER_ZONE));
+ current += 1;
+ }
+ assertEquals(false, rows.nextBatch(batch));
+ }
+
+ // test conversion to double
+ readerSchema = TypeDescription.fromString("struct<t1:double>");
+ try (RecordReader rows = reader.rows(rowOptions.schema(readerSchema))) {
+ VectorizedRowBatch batch = readerSchema.createRowBatchV2();
+ DoubleColumnVector t1 = (DoubleColumnVector) batch.cols[0];
+ int current = 0;
+ for (int r = 0; r < VALUES; ++r) {
+ if (current == batch.size) {
+ assertEquals("row " + r, true, rows.nextBatch(batch));
+ current = 0;
+ }
+ assertEquals("row " + r, timeStrings[r] + " " + READER_ZONE.getId(),
+ doubleTimestampToString(t1.vector[current], READER_ZONE));
+ current += 1;
+ }
+ assertEquals(false, rows.nextBatch(batch));
+ }
+
+ // test conversion to date
+ readerSchema = TypeDescription.fromString("struct<t1:date>");
+ try (RecordReader rows = reader.rows(rowOptions.schema(readerSchema))) {
+ VectorizedRowBatch batch = readerSchema.createRowBatchV2();
+ LongColumnVector t1 = (LongColumnVector) batch.cols[0];
+ int current = 0;
+ for (int r = 0; r < VALUES; ++r) {
+ if (current == batch.size) {
+ assertEquals("row " + r, true, rows.nextBatch(batch));
+ current = 0;
+ }
+ String date = timeStrings[r].substring(0, 10);
+ assertEquals("row " + r, date,
+ ConvertTreeReaderFactory.DATE_FORMAT.format(
+ LocalDate.ofEpochDay(t1.vector[current])));
+ current += 1;
+ }
+ assertEquals(false, rows.nextBatch(batch));
+ }
+
+ // test conversion to string
+ readerSchema = TypeDescription.fromString("struct<t1:string>");
+ try (RecordReader rows = reader.rows(rowOptions.schema(readerSchema))) {
+ VectorizedRowBatch batch = readerSchema.createRowBatch(VALUES);
+ BytesColumnVector bytesT1 = (BytesColumnVector) batch.cols[0];
+ int current = 0;
+ for (int r = 0; r < VALUES; ++r) {
+ if (current == batch.size) {
+ assertEquals("row " + r, true, rows.nextBatch(batch));
+ current = 0;
+ }
+ assertEquals("row " + r, timeStrings[r], bytesT1.toString(current));
+ current += 1;
+ }
+ assertEquals(false, rows.nextBatch(batch));
+ }
+ }
+
+ // Now test using UTC as local
+ options.useUTCTimestamp(true);
+ try (Reader reader = OrcFile.createReader(testFilePath, options)) {
+ DateTimeFormatter UTC_FORMAT =
+ ConvertTreeReaderFactory.TIMESTAMP_FORMAT.withZone(UTC);
+
+ // test conversion to int in UTC
+ TypeDescription readerSchema =
+ TypeDescription.fromString("struct<t1:bigint>");
+ try (RecordReader rows = reader.rows(rowOptions.schema(readerSchema))) {
+ VectorizedRowBatch batch = readerSchema.createRowBatch(VALUES);
+ LongColumnVector t1 = (LongColumnVector) batch.cols[0];
+ int current = 0;
+ for (int r = 0; r < VALUES; ++r) {
+ if (current == batch.size) {
+ assertEquals("row " + r, true, rows.nextBatch(batch));
+ current = 0;
+ }
+ // differs from master because of the change to standardize
+ assertEquals("row " + r, (timeStrings[r] + " " +
+ UTC.getId()).replace(".7 ", " "),
+ longTimestampToString(t1.vector[current] * 1000, UTC));
+ current += 1;
+ }
+ assertEquals(false, rows.nextBatch(batch));
+ }
+
+ // test conversion to decimal
+ readerSchema = TypeDescription.fromString("struct<t1:decimal(14,2)>");
+ try (RecordReader rows = reader.rows(rowOptions.schema(readerSchema))) {
+ VectorizedRowBatch batch = readerSchema.createRowBatchV2();
+ Decimal64ColumnVector t1 = (Decimal64ColumnVector) batch.cols[0];
+ int current = 0;
+ for (int r = 0; r < VALUES; ++r) {
+ if (current == batch.size) {
+ assertEquals("row " + r, true, rows.nextBatch(batch));
+ current = 0;
+ }
+ assertEquals("row " + r, timeStrings[r] + " " + UTC.getId(),
+ decimalTimestampToString(t1.vector[current], UTC));
+ current += 1;
+ }
+ assertEquals(false, rows.nextBatch(batch));
+ }
+
+ // test conversion to double
+ readerSchema = TypeDescription.fromString("struct<t1:double>");
+ try (RecordReader rows = reader.rows(rowOptions.schema(readerSchema))) {
+ VectorizedRowBatch batch = readerSchema.createRowBatchV2();
+ DoubleColumnVector t1 = (DoubleColumnVector) batch.cols[0];
+ int current = 0;
+ for (int r = 0; r < VALUES; ++r) {
+ if (current == batch.size) {
+ assertEquals("row " + r, true, rows.nextBatch(batch));
+ current = 0;
+ }
+ assertEquals("row " + r, timeStrings[r] + " " + UTC.getId(),
+ doubleTimestampToString(t1.vector[current], UTC));
+ current += 1;
+ }
+ assertEquals(false, rows.nextBatch(batch));
+ }
+
+ // test conversion to date
+ readerSchema = TypeDescription.fromString("struct<t1:date>");
+ try (RecordReader rows = reader.rows(rowOptions.schema(readerSchema))) {
+ VectorizedRowBatch batch = readerSchema.createRowBatchV2();
+ LongColumnVector t1 = (LongColumnVector) batch.cols[0];
+ int current = 0;
+ for (int r = 0; r < VALUES; ++r) {
+ if (current == batch.size) {
+ assertEquals("row " + r, true, rows.nextBatch(batch));
+ current = 0;
+ }
+ String date = timeStrings[r].substring(0, 10);
+ assertEquals("row " + r, date,
+ ConvertTreeReaderFactory.DATE_FORMAT.format(
+ LocalDate.ofEpochDay(t1.vector[current])));
+ current += 1;
+ }
+ assertEquals(false, rows.nextBatch(batch));
+ }
+
+ // test conversion to string in UTC
+ readerSchema = TypeDescription.fromString("struct<t1:string>");
+ try (RecordReader rows = reader.rows(rowOptions.schema(readerSchema))) {
+ VectorizedRowBatch batch = readerSchema.createRowBatch(VALUES);
+ BytesColumnVector bytesT1 = (BytesColumnVector) batch.cols[0];
+ int current = 0;
+ for (int r = 0; r < VALUES; ++r) {
+ if (current == batch.size) {
+ assertEquals("row " + r, true, rows.nextBatch(batch));
+ current = 0;
+ }
+ assertEquals("row " + r, timeStrings[r], bytesT1.toString(current));
+ current += 1;
+ }
+ assertEquals(false, rows.nextBatch(batch));
+ }
+ }
+ } finally {
+ TimeZone.setDefault(oldDefault);
+ }
+ }
+
+ /**
+ * The format for converting from/to string/timestamp with local time zone.
+ * Eg. "2019-07-09 13:11:00 America/Los_Angeles"
+ */
+ static final DateTimeFormatter INSTANT_TIMESTAMP_FORMAT =
+ new DateTimeFormatterBuilder()
+ .append(ConvertTreeReaderFactory.TIMESTAMP_FORMAT)
+ .appendPattern(" VV")
+ .toFormatter();
+
+ static void writeEvolutionToTimestamp(Path path,
+ Configuration conf,
+ ZoneId writerZone,
+ String[] values) throws IOException {
+ TypeDescription fileSchema =
+ TypeDescription.fromString("struct<l1:bigint," +
+ "t1:tinyint," +
+ "d1:decimal(14,2)," +
+ "dbl1:double," +
+ "dt1:date," +
+ "s1:string>");
+ ZoneId UTC = ZoneId.of("UTC");
+ DateTimeFormatter UTC_FORMAT = ConvertTreeReaderFactory.TIMESTAMP_FORMAT
+ .withZone(UTC);
+ DateTimeFormatter UTC_DATE = ConvertTreeReaderFactory.DATE_FORMAT
+ .withZone(UTC);
+ Writer writer = OrcFile.createWriter(path,
+ OrcFile.writerOptions(conf).setSchema(fileSchema).stripeSize(10000));
+ VectorizedRowBatch batch = fileSchema.createRowBatchV2();
+ int batchSize = batch.getMaxSize();
+ LongColumnVector l1 = (LongColumnVector) batch.cols[0];
+ LongColumnVector t1 = (LongColumnVector) batch.cols[1];
+ Decimal64ColumnVector d1 = (Decimal64ColumnVector) batch.cols[2];
+ DoubleColumnVector dbl1 = (DoubleColumnVector) batch.cols[3];
+ LongColumnVector dt1 = (LongColumnVector) batch.cols[4];
+ BytesColumnVector s1 = (BytesColumnVector) batch.cols[5];
+ for (int r = 0; r < values.length; ++r) {
+ int row = batch.size++;
+ Instant utcTime = Instant.from(UTC_FORMAT.parse(values[r]));
+ // changed from master for * 1000
+ l1.vector[row] = utcTime.getEpochSecond() * 1000;
+ t1.vector[row] = r % 128;
+ // balance out the 2 digits of scale
+ d1.vector[row] = utcTime.toEpochMilli() / 10;
+ // convert to double
+ dbl1.vector[row] = utcTime.toEpochMilli() / 1000.0;
+ // convert to date
+ dt1.vector[row] = UTC_DATE.parse(values[r].substring(0, 10))
+ .getLong(ChronoField.EPOCH_DAY);
+ // set the strings
+ s1.setVal(row, values[r].getBytes(StandardCharsets.UTF_8));
+
+ if (batch.size == batchSize) {
+ writer.addRowBatch(batch);
+ batch.reset();
+ }
+ }
+ if (batch.size != 0) {
+ writer.addRowBatch(batch);
+ }
+ writer.close();
+ }
+
+ /**
+ * Tests the various conversions to timestamp.
+ *
+ * It writes an ORC file with two longs, two decimals, and two strings and
+ * then reads it back with the types converted to timestamp and timestamp
+ * with local time zone.
+ *
+ * This test is run both with and without setting the useUtc flag.
+ *
+ * It uses Australia/Sydney and America/New_York because they both have
+ * DST and they move in opposite directions on different days. Thus, we
+ * end up with four sets of offsets.
+ */
+ @Test
+ public void testEvolutionToTimestamp() throws Exception {
+ // The number of rows in the file that we test with.
+ final int VALUES = 1024;
+ // The different timezones that we'll use for this test.
+ final ZoneId WRITER_ZONE = ZoneId.of("America/New_York");
+ final ZoneId READER_ZONE = ZoneId.of("Australia/Sydney");
+
+ final TimeZone oldDefault = TimeZone.getDefault();
+ final ZoneId UTC = ZoneId.of("UTC");
+
+ // generate the timestamps to use
+ String[] timeStrings = new String[VALUES];
+ for(int r=0; r < timeStrings.length; ++r) {
+ timeStrings[r] = String.format("%04d-%02d-27 12:34:56.1",
+ 1960 + (r / 12), (r % 12) + 1);
+ }
+
+ writeEvolutionToTimestamp(testFilePath, conf, WRITER_ZONE, timeStrings);
+
+ try {
+ TimeZone.setDefault(TimeZone.getTimeZone(READER_ZONE));
+
+ // test timestamp, timestamp with local time zone to long
+ TypeDescription readerSchema = TypeDescription.fromString(
+ "struct<l1:timestamp," +
+ "t1:timestamp," +
+ "d1:timestamp," +
+ "dbl1:timestamp," +
+ "dt1:timestamp," +
+ "s1:timestamp>");
+ VectorizedRowBatch batch = readerSchema.createRowBatchV2();
+ TimestampColumnVector l1 = (TimestampColumnVector) batch.cols[0];
+ TimestampColumnVector t1 = (TimestampColumnVector) batch.cols[1];
+ TimestampColumnVector d1 = (TimestampColumnVector) batch.cols[2];
+ TimestampColumnVector dbl1 = (TimestampColumnVector) batch.cols[3];
+ TimestampColumnVector dt1 = (TimestampColumnVector) batch.cols[4];
+ TimestampColumnVector s1 = (TimestampColumnVector) batch.cols[5];
+ OrcFile.ReaderOptions options = OrcFile.readerOptions(conf);
+ Reader.Options rowOptions = new Reader.Options().schema(readerSchema);
+ int offset = READER_ZONE.getRules().getOffset(Instant.ofEpochSecond(0, 0)).getTotalSeconds();
+ try (Reader reader = OrcFile.createReader(testFilePath, options);
+ RecordReader rows = reader.rows(rowOptions)) {
+ int current = 0;
+ for (int r = 0; r < VALUES; ++r) {
+ if (current == batch.size) {
+ assertEquals("row " + r, true, rows.nextBatch(batch));
+ current = 0;
+ }
+
+ String expected1 = timeStrings[r] + " " + READER_ZONE.getId();
+ String midnight = timeStrings[r].substring(0, 10) + " 00:00:00";
+ String expectedDate1 = midnight + " " + READER_ZONE.getId();
+
+ assertEquals("row " + r, expected1.replace(".1 ", " "),
+ timestampToString(l1.time[current], l1.nanos[current], READER_ZONE));
+
+ assertEquals("row " + r, timestampToString(-offset * 1000, (r % 128) * 1000000, READER_ZONE),
+ timestampToString(t1.time[current], t1.nanos[current], READER_ZONE));
+
+ assertEquals("row " + r, expected1,
+ timestampToString(d1.time[current], d1.nanos[current], READER_ZONE));
+
+ assertEquals("row " + r, expected1,
+ timestampToString(dbl1.time[current], dbl1.nanos[current], READER_ZONE));
+
+ assertEquals("row " + r, expectedDate1,
+ timestampToString(dt1.time[current], dt1.nanos[current], READER_ZONE));
+
+ assertEquals("row " + r, expected1,
+ timestampToString(s1.time[current], s1.nanos[current], READER_ZONE));
+
+ current += 1;
+ }
+ assertEquals(false, rows.nextBatch(batch));
+ }
+
+ // try the tests with useUtc set on
+ options.useUTCTimestamp(true);
+ try (Reader reader = OrcFile.createReader(testFilePath, options);
+ RecordReader rows = reader.rows(rowOptions)) {
+ int current = 0;
+ for (int r = 0; r < VALUES; ++r) {
+ if (current == batch.size) {
+ assertEquals("row " + r, true, rows.nextBatch(batch));
+ current = 0;
+ }
+
+ String expected1 = timeStrings[r] + " " + UTC.getId();
+ String expected2 = timeStrings[r] + " " + WRITER_ZONE.getId();
+ String midnight = timeStrings[r].substring(0, 10) + " 00:00:00";
+ String expectedDate = midnight + " " + UTC.getId();
+
+ assertEquals("row " + r, expected1.replace(".1 ", " "),
+ timestampToString(l1.time[current], l1.nanos[current], UTC));
+
+ assertEquals("row " + r, expected1,
+ timestampToString(d1.time[current], d1.nanos[current], UTC));
+
+ assertEquals("row " + r, expected1,
+ timestampToString(dbl1.time[current], dbl1.nanos[current], UTC));
+
+ assertEquals("row " + r, expectedDate,
+ timestampToString(dt1.time[current], dt1.nanos[current], UTC));
+
+ assertEquals("row " + r, expected1,
+ timestampToString(s1.time[current], s1.nanos[current], UTC));
+ current += 1;
+ }
+ assertEquals(false, rows.nextBatch(batch));
+ }
+ } finally {
+ TimeZone.setDefault(oldDefault);
+ }
+ }
+
+ @Test
+ public void doubleToTimeStampOverflow() throws Exception {
+ floatAndDoubleToTimeStampOverflow("double",
+ 340282347000000000000000000000000000000000.0,
+ 1e16,
+ 9223372036854778.0,
+ 9000000000000000.1,
+ 10000000000.0,
+ 10000000.123,
+ -1000000.123,
+ -10000000000.0,
+ -9000000000000000.1,
+ -9223372036854778.0,
+ -1e16,
+ -340282347000000000000000000000000000000000.0);
+ }
+
+ @Test
+ public void floatToTimeStampPositiveOverflow() throws Exception {
+ floatAndDoubleToTimeStampOverflow("float",
+ 340282347000000000000000000000000000000000.0,
+ 1e16,
+ 9223372036854778.0,
+ 9000000000000000.1,
+ 10000000000.0,
+ 10000000.123,
+ -1000000.123,
+ -10000000000.0,
+ -9000000000000000.1,
+ -9223372036854778.0,
+ -1e16,
+ -340282347000000000000000000000000000000000.0);
+ }
+
+ private void floatAndDoubleToTimeStampOverflow(String typeInFileSchema,
+ double... values) throws Exception {
+ boolean isFloat = typeInFileSchema.equals("float");
+ TypeDescription fileSchema =
+ TypeDescription.fromString(String.format("struct<c1:%s>", typeInFileSchema));
+ Writer writer = OrcFile.createWriter(testFilePath,
+ OrcFile.writerOptions(conf)
+ .setSchema(fileSchema)
+ .stripeSize(10000)
+ .useUTCTimestamp(true));
+
+ VectorizedRowBatch batch = fileSchema.createRowBatchV2();
+ DoubleColumnVector fl1 = (DoubleColumnVector) batch.cols[0];
+
+ for (double v : values) {
+ int row = batch.size++;
+ fl1.vector[row] = v;
+
+ if (batch.size == batch.getMaxSize()) {
+ writer.addRowBatch(batch);
+ batch.reset();
+ }
+ }
+ if (batch.size != 0) {
+ writer.addRowBatch(batch);
+ }
+ writer.close();
+
+ TypeDescription readerSchema = TypeDescription.fromString("struct<c1:timestamp>");
+ VectorizedRowBatch batchTimeStamp = readerSchema.createRowBatchV2();
+ TimestampColumnVector t1 = (TimestampColumnVector) batchTimeStamp.cols[0];
+
+ OrcFile.ReaderOptions options = OrcFile
+ .readerOptions(conf)
+ .useUTCTimestamp(true);
+
+ try (Reader reader = OrcFile.createReader(testFilePath, options);
+ RecordReader rows = reader.rows(reader.options().schema(readerSchema))) {
+ int value = 0;
+ while (value < values.length) {
+ assertTrue("value " + value, rows.nextBatch(batchTimeStamp));
+ for(int row=0; row < batchTimeStamp.size; ++row) {
+ double expected = values[value + row];
+ String rowName = String.format("value %d", value + row);
+ boolean isPositive = ((long)Math.floor(expected) * 1000) >= 0;
+ if (expected * 1000 < Long.MIN_VALUE ||
+ expected * 1000 > Long.MAX_VALUE ||
+ ((expected >= 0) != isPositive)) {
+ assertFalse(rowName, t1.noNulls);
+ assertTrue(rowName, t1.isNull[row]);
+ } else {
+ double actual = Math.floorDiv(t1.time[row], 1000) +
+ t1.nanos[row] / 1_000_000_000.0;
+ assertEquals(rowName, expected, actual,
+ Math.abs(expected * (isFloat ? 0.000001 : 0.0000000000000001)));
+ assertFalse(rowName, t1.isNull[row]);
+ assertTrue(String.format(
+ "%s nanos should be 0 to 1,000,000,000 instead it's: %d",
+ rowName, t1.nanos[row]),
+ t1.nanos[row] >= 0 && t1.nanos[row] < 1_000_000_000);
+ }
+ }
+ value += batchTimeStamp.size;
+ }
+ assertFalse(rows.nextBatch(batchTimeStamp));
+ }
+ }
+
+ @Test
+ public void testCheckAcidSchema() {
+ String ccSchema = "struct<operation:int,originalTransaction:bigint,bucket:int," +
+ "rowId:bigint,currentTransaction:bigint," +
+ "row:struct<a:int,b:int>>";
+ String lcSchema = "struct<operation:int,originaltransaction:bigint,bucket:int," +
+ "rowid:bigint,currenttransaction:bigint," +
+ "row:struct<a:int,b:int>>";
+
+ TypeDescription typeCamelCaseColumns = TypeDescription.fromString(ccSchema);
+ TypeDescription typeLowerCaseColumns = TypeDescription.fromString(lcSchema);
+ SchemaEvolution evoCc = new SchemaEvolution(typeCamelCaseColumns, null, options);
+ SchemaEvolution evoLc = new SchemaEvolution(typeLowerCaseColumns, null, options);
+
+ assertTrue("Schema (" + ccSchema +") was found to be non-acid ", evoCc.isAcid());
+ assertTrue("Schema (" + lcSchema +") was found to be non-acid ", evoLc.isAcid());
+ }
+
@Test
public void testAcidReaderSchema() {
String acidSchema = "struct<operation:int,originalTransaction:bigint,bucket:int," +
diff --git a/java/pom.xml b/java/pom.xml
index 6d1c696..6afb0f8 100644
--- a/java/pom.xml
+++ b/java/pom.xml
@@ -657,6 +657,11 @@
<artifactId>threetenbp</artifactId>
<version>1.3.5</version>
</dependency>
+ <dependency>
+ <groupId>org.threeten</groupId>
+ <artifactId>threeten-extra</artifactId>
+ <version>1.5.0</version>
+ </dependency>
<!-- test inter-project -->
<dependency>
diff --git a/java/tools/src/test/resources/orc-file-dump-bloomfilter.out b/java/tools/src/test/resources/orc-file-dump-bloomfilter.out
index ddcf385..8479ee7 100644
--- a/java/tools/src/test/resources/orc-file-dump-bloomfilter.out
+++ b/java/tools/src/test/resources/orc-file-dump-bloomfilter.out
@@ -173,7 +173,7 @@ Stripes:
Entry 0: numHashFunctions: 4 bitCount: 6272 popCount: 138 loadFactor: 0.022 expectedFpp: 2.343647E-7
Stripe level merge: numHashFunctions: 4 bitCount: 6272 popCount: 138 loadFactor: 0.022 expectedFpp: 2.343647E-7
-File length: 272503 bytes
+File length: 272505 bytes
Padding length: 0 bytes
Padding ratio: 0%
________________________________________________________________________________________________________________________
diff --git a/java/tools/src/test/resources/orc-file-dump-bloomfilter2.out b/java/tools/src/test/resources/orc-file-dump-bloomfilter2.out
index 6e55f1e..13ac53e 100644
--- a/java/tools/src/test/resources/orc-file-dump-bloomfilter2.out
+++ b/java/tools/src/test/resources/orc-file-dump-bloomfilter2.out
@@ -188,7 +188,7 @@ Stripes:
Entry 0: numHashFunctions: 7 bitCount: 9600 popCount: 4948 loadFactor: 0.5154 expectedFpp: 0.00966294
Stripe level merge: numHashFunctions: 7 bitCount: 9600 popCount: 4948 loadFactor: 0.5154 expectedFpp: 0.00966294
-File length: 332564 bytes
+File length: 332566 bytes
Padding length: 0 bytes
Padding ratio: 0%
________________________________________________________________________________________________________________________
diff --git a/java/tools/src/test/resources/orc-file-dump-dictionary-threshold.out b/java/tools/src/test/resources/orc-file-dump-dictionary-threshold.out
index 64dcefc..103b4c0 100644
--- a/java/tools/src/test/resources/orc-file-dump-dictionary-threshold.out
+++ b/java/tools/src/test/resources/orc-file-dump-dictionary-threshold.out
@@ -184,7 +184,7 @@ Stripes:
Row group indices for column 3:
Entry 0: count: 1000 hasNull: false min: Darkness,-230-368-488-586-862-930-1686-2044-2636-2652-2872-3108-3162-3192-3404-3442-3508-3542-3550-3712-3980-4146-4204-4336-4390-4418-4424-4490-4512-4650-4768-4924-4950-5210-5524-5630-5678-5710-5758-5952-6238-6252-6300-6366-6668-6712-6926-6942-7100-7194-7802-8030-8452-8608-8640-8862-8868-9134-9234-9412-9602-9608-9642-9678-9740-9780-10426-10510-10514-10706-10814-10870-10942-11028-11244-11326-11462-11496-11656-11830-12022-12178-12418-12832-133 [...]
-File length: 2217710 bytes
+File length: 2217712 bytes
Padding length: 0 bytes
Padding ratio: 0%
________________________________________________________________________________________________________________________
diff --git a/java/tools/src/test/resources/orc-file-dump.json b/java/tools/src/test/resources/orc-file-dump.json
index 0db1ccf..1e5d39b 100644
--- a/java/tools/src/test/resources/orc-file-dump.json
+++ b/java/tools/src/test/resources/orc-file-dump.json
@@ -1367,7 +1367,7 @@
}]
}
],
- "fileLength": 272486,
+ "fileLength": 272488,
"paddingLength": 0,
"paddingRatio": 0,
"status": "OK"
diff --git a/java/tools/src/test/resources/orc-file-dump.out b/java/tools/src/test/resources/orc-file-dump.out
index f601edd..6e73629 100644
--- a/java/tools/src/test/resources/orc-file-dump.out
+++ b/java/tools/src/test/resources/orc-file-dump.out
@@ -189,7 +189,7 @@ Stripes:
Row group indices for column 3:
Entry 0: count: 1000 hasNull: false min: Darkness, max: worst sum: 3866 positions: 0,0,0
-File length: 271047 bytes
+File length: 271049 bytes
Padding length: 0 bytes
Padding ratio: 0%
diff --git a/java/tools/src/test/resources/orc-file-has-null.out b/java/tools/src/test/resources/orc-file-has-null.out
index 70e2081..348ca44 100644
--- a/java/tools/src/test/resources/orc-file-has-null.out
+++ b/java/tools/src/test/resources/orc-file-has-null.out
@@ -106,7 +106,7 @@ Stripes:
Entry 3: count: 0 hasNull: true positions: 0,4,115,0,0,0,0
Entry 4: count: 0 hasNull: true positions: 0,6,110,0,0,0,0
-File length: 1842 bytes
+File length: 1844 bytes
Padding length: 0 bytes
Padding ratio: 0%
________________________________________________________________________________________________________________________