You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hive.apache.org by "Hive QA (JIRA)" <ji...@apache.org> on 2013/10/11 13:24:42 UTC

[jira] [Commented] (HIVE-5520) Use factory methods to instantiate HiveDecimal instead of constructors

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

Hive QA commented on HIVE-5520:
-------------------------------



{color:red}Overall{color}: -1 at least one tests failed

Here are the results of testing the latest attachment:
https://issues.apache.org/jira/secure/attachment/12607950/HIVE-5520.patch

{color:red}ERROR:{color} -1 due to 2 failed/errored test(s), 4392 tests executed
*Failed tests:*
{noformat}
org.apache.hadoop.hive.cli.TestCliDriver.testCliDriver_decimal_precision
org.apache.hadoop.hive.cli.TestCliDriver.testCliDriver_decimal_udf
{noformat}

Test results: https://builds.apache.org/job/PreCommit-HIVE-Build/1106/testReport
Console output: https://builds.apache.org/job/PreCommit-HIVE-Build/1106/console

Messages:
{noformat}
Executing org.apache.hive.ptest.execution.PrepPhase
Executing org.apache.hive.ptest.execution.ExecutionPhase
Executing org.apache.hive.ptest.execution.ReportingPhase
Tests failed with: TestsFailedException: 2 tests failed
{noformat}

This message is automatically generated.

> 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.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)