aboutsummaryrefslogtreecommitdiff
path: root/sql/core/src/test/scala
diff options
context:
space:
mode:
author岑玉海 <261810726@qq.com>2016-09-15 20:45:00 +0200
committerHerman van Hovell <hvanhovell@databricks.com>2016-09-15 20:45:00 +0200
commitfe767395ff46ee6236cf53aece85fcd61c0b49d3 (patch)
treec949f04e48ad9dba3fc9e2ccc7e46f453661e7ac /sql/core/src/test/scala
parentd403562eb4b5b1d804909861d3e8b75d8f6323b9 (diff)
downloadspark-fe767395ff46ee6236cf53aece85fcd61c0b49d3.tar.gz
spark-fe767395ff46ee6236cf53aece85fcd61c0b49d3.tar.bz2
spark-fe767395ff46ee6236cf53aece85fcd61c0b49d3.zip
[SPARK-17429][SQL] use ImplicitCastInputTypes with function Length
## What changes were proposed in this pull request? select length(11); select length(2.0); these sql will return errors, but hive is ok. this PR will support casting input types implicitly for function length the correct result is: select length(11) return 2 select length(2.0) return 3 Author: 岑玉海 <261810726@qq.com> Author: cenyuhai <cenyuhai@didichuxing.com> Closes #15014 from cenyuhai/SPARK-17429.
Diffstat (limited to 'sql/core/src/test/scala')
-rw-r--r--sql/core/src/test/scala/org/apache/spark/sql/StringFunctionsSuite.scala10
1 files changed, 6 insertions, 4 deletions
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/StringFunctionsSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/StringFunctionsSuite.scala
index 1cc77464b9..bcc2351049 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/StringFunctionsSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/StringFunctionsSuite.scala
@@ -330,7 +330,8 @@ class StringFunctionsSuite extends QueryTest with SharedSQLContext {
}
test("string / binary length function") {
- val df = Seq(("123", Array[Byte](1, 2, 3, 4), 123)).toDF("a", "b", "c")
+ val df = Seq(("123", Array[Byte](1, 2, 3, 4), 123, 2.0f, 3.015))
+ .toDF("a", "b", "c", "d", "e")
checkAnswer(
df.select(length($"a"), length($"b")),
Row(3, 4))
@@ -339,9 +340,10 @@ class StringFunctionsSuite extends QueryTest with SharedSQLContext {
df.selectExpr("length(a)", "length(b)"),
Row(3, 4))
- intercept[AnalysisException] {
- df.selectExpr("length(c)") // int type of the argument is unacceptable
- }
+ checkAnswer(
+ df.selectExpr("length(c)", "length(d)", "length(e)"),
+ Row(3, 3, 5)
+ )
}
test("initcap function") {