hive-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hudson (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (HIVE-5520) Use factory methods to instantiate HiveDecimal instead of constructors
Date Mon, 14 Oct 2013 07:27:42 GMT

    [ https://issues.apache.org/jira/browse/HIVE-5520?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13793968#comment-13793968
] 

Hudson commented on HIVE-5520:
------------------------------

FAILURE: Integrated in Hive-trunk-hadoop1-ptest #204 (See [https://builds.apache.org/job/Hive-trunk-hadoop1-ptest/204/])
HIVE-5520 : Use factory methods to instantiate HiveDecimal instead of constructors (Xuefu
Zhang via Ashutosh Chauhan) (hashutosh: http://svn.apache.org/viewcvs.cgi/?root=Apache-SVN&view=rev&rev=1531781)
* /hive/trunk/common/src/java/org/apache/hadoop/hive/common/type/HiveDecimal.java
* /hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/io/orc/ColumnStatisticsImpl.java
* /hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/io/orc/RecordReaderImpl.java
* /hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPMinus.java
* /hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPMod.java
* /hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPMultiply.java
* /hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPPlus.java
* /hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFPosMod.java
* /hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFPower.java
* /hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRound.java
* /hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFAverage.java
* /hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDAFSum.java
* /hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/io/orc/TestOrcFile.java
* /hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/io/orc/TestOrcSerDeStats.java
* /hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/udf/TestGenericUDFAbs.java
* /hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/RegexSerDe.java
* /hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/binarysortable/BinarySortableSerDe.java
* /hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/io/HiveDecimalWritable.java
* /hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/lazy/LazyHiveDecimal.java
* /hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/JavaHiveDecimalObjectInspector.java
* /hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/PrimitiveObjectInspectorConverter.java
* /hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/PrimitiveObjectInspectorUtils.java
* /hive/trunk/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/primitive/WritableHiveDecimalObjectInspector.java
* /hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/binarysortable/TestBinarySortableSerDe.java
* /hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/io/TestTimestampWritable.java
* /hive/trunk/serde/src/test/org/apache/hadoop/hive/serde2/objectinspector/TestObjectInspectorConverters.java


> Use factory methods to instantiate HiveDecimal instead of constructors
> ----------------------------------------------------------------------
>
>                 Key: HIVE-5520
>                 URL: https://issues.apache.org/jira/browse/HIVE-5520
>             Project: Hive
>          Issue Type: Improvement
>          Components: Types
>    Affects Versions: 0.11.0
>            Reporter: Xuefu Zhang
>            Assignee: Xuefu Zhang
>             Fix For: 0.13.0
>
>         Attachments: HIVE-5520.1.patch, HIVE-5520.patch
>
>
> Currently HiveDecimal class provided a bunch of constructors that  unfortunately also
throws a runtime exception. For example,
> {code}
>  public HiveDecimal(BigInteger unscaled, int scale) {
>     bd = this.normalize(new BigDecimal(unscaled, scale), MAX_PRECISION, false);
>     if (bd == null) {
>      throw new NumberFormatException("Assignment would result in truncation");
>    }
> {code}
> As a result, it's hard for the caller to detect error occurrences and the error handling
is also complicated. In many cases, the error handling is omitted or missed. For instance,
> {code}
>          HiveDecimalWritable result = new HiveDecimalWritable(HiveDecimal.ZERO);
>         try {
>           result.set(aggregation.sum.divide(new HiveDecimal(aggregation.count)));
>         } catch (NumberFormatException e) {
>           result = null;
>         }
> {code} 
> Throwing runtime exception while expecting caller to catch seems anti-pattern. In the
case of constructor, factory class or methods seem more appropriate. With such a change, the
apis are cleaner, and the error handling is simplified.



--
This message was sent by Atlassian JIRA
(v6.1#6144)

Mime
View raw message