You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ha...@apache.org on 2013/10/28 19:38:35 UTC
svn commit: r1536476 [1/2] - in /hive/trunk/ql/src:
java/org/apache/hadoop/hive/ql/udf/ test/org/apache/hadoop/hive/ql/udf/
test/results/clientpositive/
Author: hashutosh
Date: Mon Oct 28 18:38:34 2013
New Revision: 1536476
URL: http://svn.apache.org/r1536476
Log:
HIVE-5656 : Hive produces unclear, confusing SemanticException when dealing with mod or pmod by zero (Xuefu Zhang via Ashutosh Chauhan)
Added:
hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/udf/TestUDFOPMod.java
hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/udf/TestUDFPosMod.java
Modified:
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPMod.java
hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFPosMod.java
hive/trunk/ql/src/test/results/clientpositive/vectorization_14.q.out
Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPMod.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPMod.java?rev=1536476&r1=1536475&r2=1536476&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPMod.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFOPMod.java Mon Oct 28 18:38:34 2013
@@ -61,7 +61,7 @@ public class UDFOPMod extends UDFBaseNum
public ByteWritable evaluate(ByteWritable a, ByteWritable b) {
// LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
// + b);
- if ((a == null) || (b == null)) {
+ if (a == null || b == null || b.get() == 0) {
return null;
}
@@ -73,7 +73,7 @@ public class UDFOPMod extends UDFBaseNum
public ShortWritable evaluate(ShortWritable a, ShortWritable b) {
// LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
// + b);
- if ((a == null) || (b == null)) {
+ if (a == null || b == null || b.get() == 0) {
return null;
}
@@ -85,7 +85,7 @@ public class UDFOPMod extends UDFBaseNum
public IntWritable evaluate(IntWritable a, IntWritable b) {
// LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
// + b);
- if ((a == null) || (b == null)) {
+ if (a == null || b == null || b.get() == 0) {
return null;
}
@@ -97,7 +97,7 @@ public class UDFOPMod extends UDFBaseNum
public LongWritable evaluate(LongWritable a, LongWritable b) {
// LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
// + b);
- if ((a == null) || (b == null)) {
+ if (a == null || b == null || b.get() == 0L) {
return null;
}
@@ -109,7 +109,7 @@ public class UDFOPMod extends UDFBaseNum
public FloatWritable evaluate(FloatWritable a, FloatWritable b) {
// LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
// + b);
- if ((a == null) || (b == null)) {
+ if (a == null || b == null || b.get() == 0.0f) {
return null;
}
@@ -121,7 +121,7 @@ public class UDFOPMod extends UDFBaseNum
public DoubleWritable evaluate(DoubleWritable a, DoubleWritable b) {
// LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
// + b);
- if ((a == null) || (b == null)) {
+ if (a == null || b == null || b.get() == 0.0) {
return null;
}
Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFPosMod.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFPosMod.java?rev=1536476&r1=1536475&r2=1536476&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFPosMod.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFPosMod.java Mon Oct 28 18:38:34 2013
@@ -47,7 +47,7 @@ public class UDFPosMod extends UDFBaseNu
public ByteWritable evaluate(ByteWritable a, ByteWritable b) {
// LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
// + b);
- if ((a == null) || (b == null)) {
+ if (a == null || b == null || b.get() == 0) {
return null;
}
@@ -59,7 +59,7 @@ public class UDFPosMod extends UDFBaseNu
public ShortWritable evaluate(ShortWritable a, ShortWritable b) {
// LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
// + b);
- if ((a == null) || (b == null)) {
+ if (a == null || b == null || b.get() == 0) {
return null;
}
@@ -71,7 +71,7 @@ public class UDFPosMod extends UDFBaseNu
public IntWritable evaluate(IntWritable a, IntWritable b) {
// LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
// + b);
- if ((a == null) || (b == null)) {
+ if (a == null || b == null || b.get() == 0) {
return null;
}
@@ -83,7 +83,7 @@ public class UDFPosMod extends UDFBaseNu
public LongWritable evaluate(LongWritable a, LongWritable b) {
// LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
// + b);
- if ((a == null) || (b == null)) {
+ if (a == null || b == null || b.get() == 0L) {
return null;
}
@@ -95,7 +95,7 @@ public class UDFPosMod extends UDFBaseNu
public FloatWritable evaluate(FloatWritable a, FloatWritable b) {
// LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
// + b);
- if ((a == null) || (b == null)) {
+ if (a == null || b == null || b.get() == 0.0f) {
return null;
}
@@ -107,7 +107,7 @@ public class UDFPosMod extends UDFBaseNu
public DoubleWritable evaluate(DoubleWritable a, DoubleWritable b) {
// LOG.info("Get input " + a.getClass() + ":" + a + " " + b.getClass() + ":"
// + b);
- if ((a == null) || (b == null)) {
+ if (a == null || b == null || b.get() == 0.0) {
return null;
}
Added: hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/udf/TestUDFOPMod.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/udf/TestUDFOPMod.java?rev=1536476&view=auto
==============================================================================
--- hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/udf/TestUDFOPMod.java (added)
+++ hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/udf/TestUDFOPMod.java Mon Oct 28 18:38:34 2013
@@ -0,0 +1,64 @@
+package org.apache.hadoop.hive.ql.udf;
+
+import org.apache.hadoop.hive.common.type.HiveDecimal;
+import org.apache.hadoop.hive.serde2.io.ByteWritable;
+import org.apache.hadoop.hive.serde2.io.DoubleWritable;
+import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable;
+import org.apache.hadoop.hive.serde2.io.ShortWritable;
+import org.apache.hadoop.io.FloatWritable;
+import org.apache.hadoop.io.IntWritable;
+import org.apache.hadoop.io.LongWritable;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestUDFOPMod {
+
+ UDFOPMod udf = new UDFOPMod();
+
+ @Test
+ public void testDivideByZero() {
+ // Byte
+ ByteWritable b1 = new ByteWritable((byte) 4);
+ ByteWritable b2 = new ByteWritable((byte) 0);
+ ByteWritable b3 = udf.evaluate(b1, b2);
+ Assert.assertNull(b3);
+
+ // Short
+ ShortWritable s1 = new ShortWritable((short) 4);
+ ShortWritable s2 = new ShortWritable((short) 0);
+ ShortWritable s3 = udf.evaluate(s1, s2);
+ Assert.assertNull(s3);
+
+ // Int
+ IntWritable i1 = new IntWritable(4);
+ IntWritable i2 = new IntWritable(0);
+ IntWritable i3 = udf.evaluate(i1, i2);
+ Assert.assertNull(i3);
+
+ // Long
+ LongWritable l1 = new LongWritable(4);
+ LongWritable l2 = new LongWritable(0L);
+ LongWritable l3 = udf.evaluate(l1, l2);
+ Assert.assertNull(l3);
+
+ // Double
+ FloatWritable f1 = new FloatWritable(4.5f);
+ FloatWritable f2 = new FloatWritable(0.0f);
+ FloatWritable f3 = udf.evaluate(f1, f2);
+ Assert.assertNull(f3);
+
+ // Double
+ DoubleWritable d1 = new DoubleWritable(4.5);
+ DoubleWritable d2 = new DoubleWritable(0.0);
+ DoubleWritable d3 = udf.evaluate(d1, d2);
+ Assert.assertNull(d3);
+
+ // Decimal
+ HiveDecimalWritable dec1 = new HiveDecimalWritable(HiveDecimal.create("4.5"));
+ HiveDecimalWritable dec2 = new HiveDecimalWritable(HiveDecimal.create("0"));
+ HiveDecimalWritable dec3 = udf.evaluate(dec1, dec2);
+ Assert.assertNull(dec3);
+ }
+
+}
Added: hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/udf/TestUDFPosMod.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/udf/TestUDFPosMod.java?rev=1536476&view=auto
==============================================================================
--- hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/udf/TestUDFPosMod.java (added)
+++ hive/trunk/ql/src/test/org/apache/hadoop/hive/ql/udf/TestUDFPosMod.java Mon Oct 28 18:38:34 2013
@@ -0,0 +1,64 @@
+package org.apache.hadoop.hive.ql.udf;
+
+import org.apache.hadoop.hive.common.type.HiveDecimal;
+import org.apache.hadoop.hive.serde2.io.ByteWritable;
+import org.apache.hadoop.hive.serde2.io.DoubleWritable;
+import org.apache.hadoop.hive.serde2.io.HiveDecimalWritable;
+import org.apache.hadoop.hive.serde2.io.ShortWritable;
+import org.apache.hadoop.io.FloatWritable;
+import org.apache.hadoop.io.IntWritable;
+import org.apache.hadoop.io.LongWritable;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestUDFPosMod {
+
+ UDFPosMod udf = new UDFPosMod();
+
+ @Test
+ public void testDivideByZero() {
+ // Byte
+ ByteWritable b1 = new ByteWritable((byte) 4);
+ ByteWritable b2 = new ByteWritable((byte) 0);
+ ByteWritable b3 = udf.evaluate(b1, b2);
+ Assert.assertNull(b3);
+
+ // Short
+ ShortWritable s1 = new ShortWritable((short) 4);
+ ShortWritable s2 = new ShortWritable((short) 0);
+ ShortWritable s3 = udf.evaluate(s1, s2);
+ Assert.assertNull(s3);
+
+ // Int
+ IntWritable i1 = new IntWritable(4);
+ IntWritable i2 = new IntWritable(0);
+ IntWritable i3 = udf.evaluate(i1, i2);
+ Assert.assertNull(i3);
+
+ // Long
+ LongWritable l1 = new LongWritable(4);
+ LongWritable l2 = new LongWritable(0L);
+ LongWritable l3 = udf.evaluate(l1, l2);
+ Assert.assertNull(l3);
+
+ // Double
+ FloatWritable f1 = new FloatWritable(4.5f);
+ FloatWritable f2 = new FloatWritable(0.0f);
+ FloatWritable f3 = udf.evaluate(f1, f2);
+ Assert.assertNull(f3);
+
+ // Double
+ DoubleWritable d1 = new DoubleWritable(4.5);
+ DoubleWritable d2 = new DoubleWritable(0.0);
+ DoubleWritable d3 = udf.evaluate(d1, d2);
+ Assert.assertNull(d3);
+
+ // Decimal
+ HiveDecimalWritable dec1 = new HiveDecimalWritable(HiveDecimal.create("4.5"));
+ HiveDecimalWritable dec2 = new HiveDecimalWritable(HiveDecimal.create("0"));
+ HiveDecimalWritable dec3 = udf.evaluate(dec1, dec2);
+ Assert.assertNull(dec3);
+ }
+
+}