Review Board 1.7.22


HIVE-5655: Hive incorrecly handles divide-by-zero case

Review Request #14973 - Created Oct. 26, 2013 and updated

Xuefu Zhang
HIVE-5655
Reviewers
hive
brocknoland
hive-git
Now the behavior for double type is consistent with that for decimal type.
Added new test cases. Updated a few existing tests.
ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPDivide.java
Revision da01934 New Change
[20] 59 lines
[+20] [+] public class UDFOPDivide extends UDF {
60
  private final HiveDecimalWritable decimalWritable = new HiveDecimalWritable();
60
  private final HiveDecimalWritable decimalWritable = new HiveDecimalWritable();
61

    
   
61

   
62
  public DoubleWritable evaluate(DoubleWritable a, DoubleWritable b) {
62
  public DoubleWritable evaluate(DoubleWritable a, DoubleWritable b) {
63
    // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
63
    // LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
64
    // + b);
64
    // + b);
65
    if ((a == null) || (b == null)) {
65
    if (a == null || b == null || b.get() == 0.0) {
66
      return null;
66
      return null;
67
    }
67
    }
68

    
   
68

   
69
    doubleWritable.set(a.get() / b.get());
69
    doubleWritable.set(a.get() / b.get());
70
    return doubleWritable;
70
    return doubleWritable;
[+20] [20] 20 lines
ql/src/test/org/apache/hadoop/hive/ql/udf/TestUDFOPDivide.java
New File
 
ql/src/test/results/beelinepositive/udf_round.q.out
Revision 9faa1f8 New Change
 
ql/src/test/results/clientpositive/udf_round.q.out
Revision db87fe6 New Change
 
ql/src/test/results/clientpositive/udf_round_2.q.out
Revision 457d074 New Change
 
ql/src/test/results/clientpositive/vectorization_13.q.out
Revision f327566 New Change
 
ql/src/test/results/clientpositive/vectorization_short_regress.q.out
Revision 68a05b2 New Change
 
  1. ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPDivide.java: Loading...
  2. ql/src/test/org/apache/hadoop/hive/ql/udf/TestUDFOPDivide.java: Loading...
  3. ql/src/test/results/beelinepositive/udf_round.q.out: Loading...
  4. ql/src/test/results/clientpositive/udf_round.q.out: Loading...
  5. ql/src/test/results/clientpositive/udf_round_2.q.out: Loading...
  6. ql/src/test/results/clientpositive/vectorization_13.q.out: Loading...
  7. ql/src/test/results/clientpositive/vectorization_short_regress.q.out: Loading...