Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id CD849200C81 for ; Fri, 26 May 2017 19:32:10 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id CC27C160B9C; Fri, 26 May 2017 17:32:10 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D3EC1160BC7 for ; Fri, 26 May 2017 19:32:09 +0200 (CEST) Received: (qmail 9175 invoked by uid 500); 26 May 2017 17:32:08 -0000 Mailing-List: contact commits-help@hive.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: hive-dev@hive.apache.org Delivered-To: mailing list commits@hive.apache.org Received: (qmail 9123 invoked by uid 99); 26 May 2017 17:32:08 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 26 May 2017 17:32:08 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id C61FFE024D; Fri, 26 May 2017 17:32:08 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: omalley@apache.org To: commits@hive.apache.org Date: Fri, 26 May 2017 17:32:09 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [2/4] hive git commit: HIVE-15335: Fast Decimal (addendum) archived-at: Fri, 26 May 2017 17:32:11 -0000 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/c55ef22e Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/c55ef22e Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/c55ef22e Branch: refs/heads/branch-2.2 Commit: c55ef22e5eb7868e9c4fe8d5977c6c5124e36ef9 Parents: 9f8141b Author: Owen O'Malley Authored: Thu May 25 09:29:03 2017 -0700 Committer: Owen O'Malley Committed: Thu May 25 09:33: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/c55ef22e/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/c55ef22e/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; } /**