aboutsummaryrefslogtreecommitdiff
path: root/sql/core
diff options
context:
space:
mode:
authorDongjoon Hyun <dongjoon@apache.org>2016-04-05 13:31:00 -0700
committerMichael Armbrust <michael@databricks.com>2016-04-05 13:31:00 -0700
commitc59abad052b7beec4ef550049413e95578e545be (patch)
treeb3415705f58670b8bb78f485d8a5e8b90e7d5174 /sql/core
parent9ee5c257176d5c7989031d260e74e3eca530c120 (diff)
downloadspark-c59abad052b7beec4ef550049413e95578e545be.tar.gz
spark-c59abad052b7beec4ef550049413e95578e545be.tar.bz2
spark-c59abad052b7beec4ef550049413e95578e545be.zip
[SPARK-14402][SQL] initcap UDF doesn't match Hive/Oracle behavior in lowercasing rest of string
## What changes were proposed in this pull request? Current, SparkSQL `initCap` is using `toTitleCase` function. However, `UTF8String.toTitleCase` implementation changes only the first letter and just copy the other letters: e.g. sParK --> SParK. This is the correct implementation `toTitleCase`. ``` hive> select initcap('sParK'); Spark ``` ``` scala> sql("select initcap('sParK')").head res0: org.apache.spark.sql.Row = [SParK] ``` This PR updates the implementation of `initcap` using `toLowerCase` and `toTitleCase`. ## How was this patch tested? Pass the Jenkins tests (including new testcase). Author: Dongjoon Hyun <dongjoon@apache.org> Closes #12175 from dongjoon-hyun/SPARK-14402.
Diffstat (limited to 'sql/core')
-rw-r--r--sql/core/src/test/scala/org/apache/spark/sql/StringFunctionsSuite.scala6
1 files changed, 3 insertions, 3 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 e2090b0a83..6809f26968 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
@@ -272,12 +272,12 @@ class StringFunctionsSuite extends QueryTest with SharedSQLContext {
}
test("initcap function") {
- val df = Seq(("ab", "a B")).toDF("l", "r")
+ val df = Seq(("ab", "a B", "sParK")).toDF("x", "y", "z")
checkAnswer(
- df.select(initcap($"l"), initcap($"r")), Row("Ab", "A B"))
+ df.select(initcap($"x"), initcap($"y"), initcap($"z")), Row("Ab", "A B", "Spark"))
checkAnswer(
- df.selectExpr("InitCap(l)", "InitCap(r)"), Row("Ab", "A B"))
+ df.selectExpr("InitCap(x)", "InitCap(y)", "InitCap(z)"), Row("Ab", "A B", "Spark"))
}
test("number format function") {