hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kevinwilf...@apache.org
Subject svn commit: r1407320 - in /hive/trunk/ql/src: java/org/apache/hadoop/hive/ql/udf/ test/queries/clientpositive/ test/results/clientpositive/
Date Thu, 08 Nov 2012 23:57:08 GMT
Author: kevinwilfong
Date: Thu Nov  8 23:57:07 2012
New Revision: 1407320

URL: http://svn.apache.org/viewvc?rev=1407320&view=rev
Log:
HIVE-3675. NaN does not work correctly for round(n). (njain via kevinwilfong)

Added:
    hive/trunk/ql/src/test/queries/clientpositive/udf_round_2.q
    hive/trunk/ql/src/test/results/clientpositive/udf_round_2.q.out
Modified:
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRound.java
    hive/trunk/ql/src/test/results/clientpositive/udf4.q.out
    hive/trunk/ql/src/test/results/clientpositive/udf_round.q.out

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRound.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRound.java?rev=1407320&r1=1407319&r2=1407320&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRound.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFRound.java Thu Nov  8 23:57:07
2012
@@ -25,7 +25,6 @@ import org.apache.hadoop.hive.ql.exec.De
 import org.apache.hadoop.hive.ql.exec.UDF;
 import org.apache.hadoop.hive.serde2.io.DoubleWritable;
 import org.apache.hadoop.io.IntWritable;
-import org.apache.hadoop.io.LongWritable;
 
 /**
  * UDFRound.
@@ -36,33 +35,34 @@ import org.apache.hadoop.io.LongWritable
     extended = "Example:\n"
     + "  > SELECT _FUNC_(12.3456, 1) FROM src LIMIT 1;\n" + "  12.3'")
 public class UDFRound extends UDF {
-  private DoubleWritable doubleWritable = new DoubleWritable();
-  private LongWritable longWritable = new LongWritable();
+  private final DoubleWritable doubleWritable = new DoubleWritable();
 
   public UDFRound() {
   }
 
-  public LongWritable evaluate(DoubleWritable n) {
+  private DoubleWritable evaluate(DoubleWritable n, int i) {
+    double d = n.get();
+    if (Double.isNaN(d) || Double.isInfinite(d)) {
+      doubleWritable.set(d);
+    } else {
+      doubleWritable.set(BigDecimal.valueOf(d).setScale(i,
+          RoundingMode.HALF_UP).doubleValue());
+    }
+    return doubleWritable;
+  }
+
+  public DoubleWritable evaluate(DoubleWritable n) {
     if (n == null) {
       return null;
     }
-    longWritable.set(BigDecimal.valueOf(n.get()).setScale(0,
-        RoundingMode.HALF_UP).longValue());
-    return longWritable;
+    return evaluate(n, 0);
   }
 
   public DoubleWritable evaluate(DoubleWritable n, IntWritable i) {
     if ((n == null) || (i == null)) {
       return null;
     }
-    double d = n.get();
-    if (Double.isNaN(d) || Double.isInfinite(d)) {
-      doubleWritable.set(d);
-    } else {
-      doubleWritable.set(BigDecimal.valueOf(d).setScale(i.get(),
-          RoundingMode.HALF_UP).doubleValue());
-    }
-    return doubleWritable;
+    return evaluate(n, i.get());
   }
 
 }

Added: hive/trunk/ql/src/test/queries/clientpositive/udf_round_2.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientpositive/udf_round_2.q?rev=1407320&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientpositive/udf_round_2.q (added)
+++ hive/trunk/ql/src/test/queries/clientpositive/udf_round_2.q Thu Nov  8 23:57:07 2012
@@ -0,0 +1,13 @@
+-- test for NaN (not-a-number) 
+create table tstTbl1(n double);
+
+insert overwrite table tstTbl1
+select 'NaN' from src limit 1;
+
+select * from tstTbl1;
+
+select round(n, 1) from tstTbl1;
+select round(n) from tstTbl1;
+
+-- test for Infinity
+select round(1/0), round(1/0, 2), round(1.0/0.0), round(1.0/0.0, 2) from src limit 1;

Modified: hive/trunk/ql/src/test/results/clientpositive/udf4.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/udf4.q.out?rev=1407320&r1=1407319&r2=1407320&view=diff
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/udf4.q.out (original)
+++ hive/trunk/ql/src/test/results/clientpositive/udf4.q.out Thu Nov  8 23:57:07 2012
@@ -36,11 +36,11 @@ STAGE PLANS:
             Select Operator
               expressions:
                     expr: round(1.0)
-                    type: bigint
+                    type: double
                     expr: round(1.5)
-                    type: bigint
+                    type: double
                     expr: round((- 1.5))
-                    type: bigint
+                    type: double
                     expr: floor(1.0)
                     type: bigint
                     expr: floor(1.5)
@@ -95,4 +95,4 @@ POSTHOOK: type: QUERY
 POSTHOOK: Input: default@dest1
 #### A masked pattern was here ####
 POSTHOOK: Lineage: dest1.c1 SIMPLE []
-1	2	-2	1	1	-2	1.0	NULL	0.0	1	2	-1	1	0.731057369148862	3	-3	3	-1	-2
+1.0	2.0	-2.0	1	1	-2	1.0	NULL	0.0	1	2	-1	1	0.731057369148862	3	-3	3	-1	-2

Modified: hive/trunk/ql/src/test/results/clientpositive/udf_round.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/udf_round.q.out?rev=1407320&r1=1407319&r2=1407320&view=diff
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/udf_round.q.out (original)
+++ hive/trunk/ql/src/test/results/clientpositive/udf_round.q.out Thu Nov  8 23:57:07 2012
@@ -40,7 +40,7 @@ FROM src LIMIT 1
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@src
 #### A masked pattern was here ####
-55555	55555.0	55555.0	55555.0	55555.0	55560.0	55600.0	56000.0	60000.0	100000.0	0.0	0.0	0.0
+55555.0	55555.0	55555.0	55555.0	55555.0	55560.0	55600.0	56000.0	60000.0	100000.0	0.0	0.0
0.0
 PREHOOK: query: SELECT
   round(125.315), round(125.315, 0),
   round(125.315, 1), round(125.315, 2), round(125.315, 3), round(125.315, 4),
@@ -63,7 +63,7 @@ FROM src LIMIT 1
 POSTHOOK: type: QUERY
 POSTHOOK: Input: default@src
 #### A masked pattern was here ####
-125	125.0	125.3	125.32	125.315	125.315	130.0	100.0	0.0	0.0	-125	-125.0	-125.3	-125.32	-125.315
-125.315	-130.0	-100.0	0.0	0.0
+125.0	125.0	125.3	125.32	125.315	125.315	130.0	100.0	0.0	0.0	-125.0	-125.0	-125.3	-125.32
-125.315	-125.315	-130.0	-100.0	0.0	0.0
 PREHOOK: query: SELECT
   round(3.141592653589793, -15), round(3.141592653589793, -16),
   round(3.141592653589793, -13), round(3.141592653589793, -14),

Added: hive/trunk/ql/src/test/results/clientpositive/udf_round_2.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/udf_round_2.q.out?rev=1407320&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/udf_round_2.q.out (added)
+++ hive/trunk/ql/src/test/results/clientpositive/udf_round_2.q.out Thu Nov  8 23:57:07 2012
@@ -0,0 +1,60 @@
+PREHOOK: query: -- test for NaN (not-a-number) 
+create table tstTbl1(n double)
+PREHOOK: type: CREATETABLE
+POSTHOOK: query: -- test for NaN (not-a-number) 
+create table tstTbl1(n double)
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: default@tstTbl1
+PREHOOK: query: insert overwrite table tstTbl1
+select 'NaN' from src limit 1
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src
+PREHOOK: Output: default@tsttbl1
+POSTHOOK: query: insert overwrite table tstTbl1
+select 'NaN' from src limit 1
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@src
+POSTHOOK: Output: default@tsttbl1
+POSTHOOK: Lineage: tsttbl1.n EXPRESSION []
+PREHOOK: query: select * from tstTbl1
+PREHOOK: type: QUERY
+PREHOOK: Input: default@tsttbl1
+#### A masked pattern was here ####
+POSTHOOK: query: select * from tstTbl1
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@tsttbl1
+#### A masked pattern was here ####
+POSTHOOK: Lineage: tsttbl1.n EXPRESSION []
+NaN
+PREHOOK: query: select round(n, 1) from tstTbl1
+PREHOOK: type: QUERY
+PREHOOK: Input: default@tsttbl1
+#### A masked pattern was here ####
+POSTHOOK: query: select round(n, 1) from tstTbl1
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@tsttbl1
+#### A masked pattern was here ####
+POSTHOOK: Lineage: tsttbl1.n EXPRESSION []
+NaN
+PREHOOK: query: select round(n) from tstTbl1
+PREHOOK: type: QUERY
+PREHOOK: Input: default@tsttbl1
+#### A masked pattern was here ####
+POSTHOOK: query: select round(n) from tstTbl1
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@tsttbl1
+#### A masked pattern was here ####
+POSTHOOK: Lineage: tsttbl1.n EXPRESSION []
+NaN
+PREHOOK: query: -- test for Infinity
+select round(1/0), round(1/0, 2), round(1.0/0.0), round(1.0/0.0, 2) from src limit 1
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src
+#### A masked pattern was here ####
+POSTHOOK: query: -- test for Infinity
+select round(1/0), round(1/0, 2), round(1.0/0.0), round(1.0/0.0, 2) from src limit 1
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@src
+#### A masked pattern was here ####
+POSTHOOK: Lineage: tsttbl1.n EXPRESSION []
+Infinity	Infinity	Infinity	Infinity



Mime
View raw message