You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by th...@apache.org on 2017/02/09 03:49:33 UTC
hive git commit: HIVE-15792 : Hive should raise SemanticException
when LPAD/RPAD pad character's length is 0 (Nanda Kumar via Thejas Nair)
Repository: hive
Updated Branches:
refs/heads/master 12f79a4b0 -> 27613f0c7
HIVE-15792 : Hive should raise SemanticException when LPAD/RPAD pad character's length is 0 (Nanda Kumar via Thejas Nair)
Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/27613f0c
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/27613f0c
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/27613f0c
Branch: refs/heads/master
Commit: 27613f0c730842b0a0d69d2fb4ad0eda6d947baf
Parents: 12f79a4
Author: Nanda kumar <na...@gmail.com>
Authored: Wed Feb 8 19:49:24 2017 -0800
Committer: Thejas M Nair <th...@hortonworks.com>
Committed: Wed Feb 8 19:49:24 2017 -0800
----------------------------------------------------------------------
.../hadoop/hive/ql/udf/generic/GenericUDFBasePad.java | 2 +-
.../hadoop/hive/ql/udf/generic/GenericUDFLpad.java | 9 ++++++---
.../hadoop/hive/ql/udf/generic/GenericUDFRpad.java | 8 ++++++--
.../hadoop/hive/ql/udf/generic/TestGenericUDFLpad.java | 9 +++++++--
.../hadoop/hive/ql/udf/generic/TestGenericUDFRpad.java | 11 +++++++----
ql/src/test/results/clientpositive/udf_lpad.q.out | 6 +++++-
ql/src/test/results/clientpositive/udf_rpad.q.out | 6 +++++-
7 files changed, 37 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hive/blob/27613f0c/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFBasePad.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFBasePad.java b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFBasePad.java
index f0b8e3b..f621715 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFBasePad.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFBasePad.java
@@ -66,7 +66,7 @@ public abstract class GenericUDFBasePad extends GenericUDF {
Text str = (Text) converter1.convert(valObject1);
IntWritable lenW = (IntWritable) converter2.convert(valObject2);
Text pad = (Text) converter3.convert(valObject3);
- if (str == null || pad == null || lenW == null) {
+ if (str == null || pad == null || lenW == null || pad.toString().isEmpty()) {
return null;
}
int len = lenW.get();
http://git-wip-us.apache.org/repos/asf/hive/blob/27613f0c/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFLpad.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFLpad.java b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFLpad.java
index 32b2ea2..9f75b66 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFLpad.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFLpad.java
@@ -19,7 +19,6 @@
package org.apache.hadoop.hive.ql.udf.generic;
import org.apache.hadoop.hive.ql.exec.Description;
-import org.apache.hadoop.io.Text;
/**
* UDFLpad.
@@ -29,10 +28,14 @@ import org.apache.hadoop.io.Text;
value = "_FUNC_(str, len, pad) - Returns str, left-padded with pad to a length of len",
extended = "If str is longer than len, the return value is shortened to "
+ "len characters.\n"
+ + "In case of empty pad string, the return value is null.\n"
+ "Example:\n"
+ " > SELECT _FUNC_('hi', 5, '??') FROM src LIMIT 1;\n"
- + " '???hi'"
- + " > SELECT _FUNC_('hi', 1, '??') FROM src LIMIT 1;\n" + " 'h'")
+ + " '???hi'\n"
+ + " > SELECT _FUNC_('hi', 1, '??') FROM src LIMIT 1;\n"
+ + " 'h'\n"
+ + " > SELECT _FUNC_('hi', 5, '') FROM src LIMIT 1;\n"
+ + " null")
public class GenericUDFLpad extends GenericUDFBasePad {
public GenericUDFLpad() {
super("lpad");
http://git-wip-us.apache.org/repos/asf/hive/blob/27613f0c/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFRpad.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFRpad.java b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFRpad.java
index a063b37..21d1cab 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFRpad.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFRpad.java
@@ -19,7 +19,6 @@
package org.apache.hadoop.hive.ql.udf.generic;
import org.apache.hadoop.hive.ql.exec.Description;
-import org.apache.hadoop.io.Text;
/**
* UDFRpad.
@@ -29,9 +28,14 @@ import org.apache.hadoop.io.Text;
"Returns str, right-padded with pad to a length of len",
extended = "If str is longer than len, the return value is shortened to "
+ "len characters.\n"
+ + "In case of empty pad string, the return value is null.\n"
+ "Example:\n"
+ " > SELECT _FUNC_('hi', 5, '??') FROM src LIMIT 1;\n"
- + " 'hi???'" + " > SELECT _FUNC_('hi', 1, '??') FROM src LIMIT 1;\n" + " 'h'")
+ + " 'hi???'\n"
+ + " > SELECT _FUNC_('hi', 1, '??') FROM src LIMIT 1;\n"
+ + " 'h'\n"
+ + " > SELECT _FUNC_('hi', 5, '') FROM src LIMIT 1;\n"
+ + " null")
public class GenericUDFRpad extends GenericUDFBasePad {
public GenericUDFRpad() {
super("rpad");
http://git-wip-us.apache.org/repos/asf/hive/blob/27613f0c/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFLpad.java
----------------------------------------------------------------------
diff --git a/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFLpad.java b/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFLpad.java
index f2d1fa9..9929215 100644
--- a/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFLpad.java
+++ b/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFLpad.java
@@ -43,6 +43,7 @@ public class TestGenericUDFLpad extends TestCase {
runAndVerify("hi", 1, "??", "h", udf);
runAndVerify("\uff48\uff49", 5, "\uff1f\uff1f", "\uff1f\uff1f\uff1f\uff48\uff49", udf);
runAndVerify("\uff48\uff49", 1, "\uff1f\uff1f", "\uff48", udf);
+ runAndVerify("hi", 3, "", null, udf);
}
private void runAndVerify(String str, int len, String pad, String expResult, GenericUDF udf)
@@ -51,7 +52,11 @@ public class TestGenericUDFLpad extends TestCase {
DeferredObject valueObj2 = new DeferredJavaObject(new IntWritable(len));
DeferredObject valueObj3 = new DeferredJavaObject(new Text(pad));
DeferredObject[] args = { valueObj1, valueObj2, valueObj3 };
- Text output = (Text) udf.evaluate(args);
- assertEquals("lpad() test ", expResult, output.toString());
+ Object output = udf.evaluate(args);
+ if(expResult != null) {
+ assertEquals("lpad() test ", expResult, output.toString());
+ } else {
+ assertNull("lpad() test ", output);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/hive/blob/27613f0c/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFRpad.java
----------------------------------------------------------------------
diff --git a/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFRpad.java b/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFRpad.java
index 62908fd..28c6818 100644
--- a/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFRpad.java
+++ b/ql/src/test/org/apache/hadoop/hive/ql/udf/generic/TestGenericUDFRpad.java
@@ -18,10 +18,8 @@
package org.apache.hadoop.hive.ql.udf.generic;
import org.apache.hadoop.hive.ql.metadata.HiveException;
-import org.apache.hadoop.hive.ql.udf.generic.GenericUDF;
import org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredJavaObject;
import org.apache.hadoop.hive.ql.udf.generic.GenericUDF.DeferredObject;
-import org.apache.hadoop.hive.ql.udf.generic.GenericUDFLpad;
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory;
import org.apache.hadoop.io.IntWritable;
@@ -43,6 +41,7 @@ public class TestGenericUDFRpad extends TestCase {
runAndVerify("hi", 1, "??", "h", udf);
runAndVerify("\uff48\uff49", 5, "\uff1f\uff1f", "\uff48\uff49\uff1f\uff1f\uff1f", udf);
runAndVerify("\uff48\uff49", 1, "\uff1f\uff1f", "\uff48", udf);
+ runAndVerify("hi", 3, "", null, udf);
}
private void runAndVerify(String str, int len, String pad, String expResult, GenericUDF udf)
@@ -51,7 +50,11 @@ public class TestGenericUDFRpad extends TestCase {
DeferredObject valueObj2 = new DeferredJavaObject(new IntWritable(len));
DeferredObject valueObj3 = new DeferredJavaObject(new Text(pad));
DeferredObject[] args = { valueObj1, valueObj2, valueObj3 };
- Text output = (Text) udf.evaluate(args);
- assertEquals("rpad() test ", expResult, output.toString());
+ Object output = udf.evaluate(args);
+ if(expResult != null) {
+ assertEquals("rpad() test ", expResult, output.toString());
+ } else {
+ assertNull("rpad() test ", output);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/hive/blob/27613f0c/ql/src/test/results/clientpositive/udf_lpad.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/udf_lpad.q.out b/ql/src/test/results/clientpositive/udf_lpad.q.out
index 7d7cc92..4dcb105 100644
--- a/ql/src/test/results/clientpositive/udf_lpad.q.out
+++ b/ql/src/test/results/clientpositive/udf_lpad.q.out
@@ -9,10 +9,14 @@ POSTHOOK: query: DESCRIBE FUNCTION EXTENDED lpad
POSTHOOK: type: DESCFUNCTION
lpad(str, len, pad) - Returns str, left-padded with pad to a length of len
If str is longer than len, the return value is shortened to len characters.
+In case of empty pad string, the return value is null.
Example:
> SELECT lpad('hi', 5, '??') FROM src LIMIT 1;
- '???hi' > SELECT lpad('hi', 1, '??') FROM src LIMIT 1;
+ '???hi'
+ > SELECT lpad('hi', 1, '??') FROM src LIMIT 1;
'h'
+ > SELECT lpad('hi', 5, '') FROM src LIMIT 1;
+ null
Function class:org.apache.hadoop.hive.ql.udf.generic.GenericUDFLpad
Function type:BUILTIN
PREHOOK: query: EXPLAIN SELECT
http://git-wip-us.apache.org/repos/asf/hive/blob/27613f0c/ql/src/test/results/clientpositive/udf_rpad.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/udf_rpad.q.out b/ql/src/test/results/clientpositive/udf_rpad.q.out
index bf77b7f..0a80f66 100644
--- a/ql/src/test/results/clientpositive/udf_rpad.q.out
+++ b/ql/src/test/results/clientpositive/udf_rpad.q.out
@@ -9,10 +9,14 @@ POSTHOOK: query: DESCRIBE FUNCTION EXTENDED rpad
POSTHOOK: type: DESCFUNCTION
rpad(str, len, pad) - Returns str, right-padded with pad to a length of len
If str is longer than len, the return value is shortened to len characters.
+In case of empty pad string, the return value is null.
Example:
> SELECT rpad('hi', 5, '??') FROM src LIMIT 1;
- 'hi???' > SELECT rpad('hi', 1, '??') FROM src LIMIT 1;
+ 'hi???'
+ > SELECT rpad('hi', 1, '??') FROM src LIMIT 1;
'h'
+ > SELECT rpad('hi', 5, '') FROM src LIMIT 1;
+ null
Function class:org.apache.hadoop.hive.ql.udf.generic.GenericUDFRpad
Function type:BUILTIN
PREHOOK: query: EXPLAIN SELECT