You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by om...@apache.org on 2017/05/31 16:50:00 UTC
[8/8] hive git commit: HIVE-15335: Fast Decimal (addendum)
HIVE-15335: Fast Decimal (addendum)
Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/a046198c
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/a046198c
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/a046198c
Branch: refs/heads/branch-2.2
Commit: a046198cd41bbec7236ab2a19382fda62e41d4e0
Parents: 93c33ff
Author: Owen O'Malley <om...@apache.org>
Authored: Thu May 25 09:29:03 2017 -0700
Committer: Owen O'Malley <om...@apache.org>
Committed: Wed May 31 09:41:32 2017 -0700
----------------------------------------------------------------------
.../orc/impl/ConvertTreeReaderFactory.java | 50 ++------------------
.../hadoop/hive/ql/util/TimestampUtils.java | 36 ++++++--------
2 files changed, 19 insertions(+), 67 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hive/blob/a046198c/orc/src/java/org/apache/orc/impl/ConvertTreeReaderFactory.java
----------------------------------------------------------------------
diff --git a/orc/src/java/org/apache/orc/impl/ConvertTreeReaderFactory.java b/orc/src/java/org/apache/orc/impl/ConvertTreeReaderFactory.java
index a7c3380..2d293b5 100644
--- a/orc/src/java/org/apache/orc/impl/ConvertTreeReaderFactory.java
+++ b/orc/src/java/org/apache/orc/impl/ConvertTreeReaderFactory.java
@@ -613,53 +613,13 @@ public class ConvertTreeReaderFactory extends TreeReaderFactory {
@Override
public void setConvertVectorElement(int elementNum) throws IOException {
- HiveDecimalWritable decWritable = decimalColVector.vector[elementNum];
- long[] vector = longColVector.vector;
- Category readerCategory = readerType.getCategory();
-
- // Check to see if the decimal will fit in the Hive integer data type.
- // If not, set the element to null.
- boolean isInRange;
- switch (readerCategory) {
- case BOOLEAN:
- // No data loss for boolean.
- vector[elementNum] = decWritable.signum() == 0 ? 0 : 1;
- return;
- case BYTE:
- isInRange = decWritable.isByte();
- break;
- case SHORT:
- isInRange = decWritable.isShort();
- break;
- case INT:
- isInRange = decWritable.isInt();
- break;
- case LONG:
- isInRange = decWritable.isLong();
- break;
- default:
- throw new RuntimeException("Unexpected type kind " + readerCategory.name());
- }
- if (!isInRange) {
+ HiveDecimal decimalValue = decimalColVector.vector[elementNum].getHiveDecimal();
+ if (decimalValue.compareTo(DECIMAL_MAX_LONG) > 0 ||
+ decimalValue.compareTo(DECIMAL_MIN_LONG) < 0) {
longColVector.isNull[elementNum] = true;
longColVector.noNulls = false;
- return;
- }
- switch (readerCategory) {
- case BYTE:
- vector[elementNum] = decWritable.byteValue();
- break;
- case SHORT:
- vector[elementNum] = decWritable.shortValue();
- break;
- case INT:
- vector[elementNum] = decWritable.intValue();
- break;
- case LONG:
- vector[elementNum] = decWritable.longValue();
- break;
- default:
- throw new RuntimeException("Unexpected type kind " + readerCategory.name());
+ } else {
+ downCastAnyInteger(longColVector, elementNum, decimalValue.longValue(), readerType);
}
}
http://git-wip-us.apache.org/repos/asf/hive/blob/a046198c/storage-api/src/java/org/apache/hadoop/hive/ql/util/TimestampUtils.java
----------------------------------------------------------------------
diff --git a/storage-api/src/java/org/apache/hadoop/hive/ql/util/TimestampUtils.java b/storage-api/src/java/org/apache/hadoop/hive/ql/util/TimestampUtils.java
index dfc7272..c0e8a2e 100644
--- a/storage-api/src/java/org/apache/hadoop/hive/ql/util/TimestampUtils.java
+++ b/storage-api/src/java/org/apache/hadoop/hive/ql/util/TimestampUtils.java
@@ -76,32 +76,24 @@ public class TimestampUtils {
* @param dec
* @return
*/
- public static Timestamp decimalToTimestamp(HiveDecimal dec) {
+ public static Timestamp decimalToTimestamp(HiveDecimal d) {
+ try {
+ BigDecimal nanoInstant = d.bigDecimalValue().multiply(BILLION_BIG_DECIMAL);
+ int nanos = nanoInstant.remainder(BILLION_BIG_DECIMAL).intValue();
+ if (nanos < 0) {
+ nanos += 1000000000;
+ }
+ long seconds =
+ nanoInstant.subtract(new BigDecimal(nanos)).divide(BILLION_BIG_DECIMAL).longValue();
+ Timestamp t = new Timestamp(seconds * 1000);
+ t.setNanos(nanos);
- HiveDecimalWritable nanosWritable = new HiveDecimalWritable(dec);
- nanosWritable.mutateFractionPortion(); // Clip off seconds portion.
- nanosWritable.mutateScaleByPowerOfTen(9); // Bring nanoseconds into integer portion.
- if (!nanosWritable.isSet() || !nanosWritable.isInt()) {
+ return t;
+ } catch (NumberFormatException nfe) {
return null;
- }
- int nanos = nanosWritable.intValue();
- if (nanos < 0) {
- nanos += 1000000000;
- }
- nanosWritable.setFromLong(nanos);
-
- HiveDecimalWritable nanoInstant = new HiveDecimalWritable(dec);
- nanoInstant.mutateScaleByPowerOfTen(9);
-
- nanoInstant.mutateSubtract(nanosWritable);
- nanoInstant.mutateScaleByPowerOfTen(-9); // Back to seconds.
- if (!nanoInstant.isSet() || !nanoInstant.isLong()) {
+ } catch (IllegalArgumentException iae) {
return null;
}
- long seconds = nanoInstant.longValue();
- Timestamp t = new Timestamp(seconds * 1000);
- t.setNanos(nanos);
- return t;
}
/**