aboutsummaryrefslogtreecommitdiff
path: root/sql/core/src
diff options
context:
space:
mode:
authorSandeep Singh <sandeep@techaddict.me>2016-07-22 10:05:21 +0800
committerWenchen Fan <wenchen@databricks.com>2016-07-22 10:05:21 +0800
commitdf2c6d59d0e1a3db9942dbc5e4993cf3babc2d60 (patch)
tree6802b7c39aa8dfb60ee31066939b0eef998183be /sql/core/src
parent46f80a307392bee6743e5847eb5243bf5fcd00a4 (diff)
downloadspark-df2c6d59d0e1a3db9942dbc5e4993cf3babc2d60.tar.gz
spark-df2c6d59d0e1a3db9942dbc5e4993cf3babc2d60.tar.bz2
spark-df2c6d59d0e1a3db9942dbc5e4993cf3babc2d60.zip
[SPARK-16287][SQL] Implement str_to_map SQL function
## What changes were proposed in this pull request? This PR adds `str_to_map` SQL function in order to remove Hive fallback. ## How was this patch tested? Pass the Jenkins tests with newly added. Author: Sandeep Singh <sandeep@techaddict.me> Closes #13990 from techaddict/SPARK-16287.
Diffstat (limited to 'sql/core/src')
-rw-r--r--sql/core/src/test/scala/org/apache/spark/sql/StringFunctionsSuite.scala23
1 files changed, 23 insertions, 0 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 f509551b1e..524926e1e9 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
@@ -384,4 +384,27 @@ class StringFunctionsSuite extends QueryTest with SharedSQLContext {
}.getMessage
assert(m.contains("Invalid number of arguments for function sentences"))
}
+
+ test("str_to_map function") {
+ val df1 = Seq(
+ ("a=1,b=2", "y"),
+ ("a=1,b=2,c=3", "y")
+ ).toDF("a", "b")
+
+ checkAnswer(
+ df1.selectExpr("str_to_map(a,',','=')"),
+ Seq(
+ Row(Map("a" -> "1", "b" -> "2")),
+ Row(Map("a" -> "1", "b" -> "2", "c" -> "3"))
+ )
+ )
+
+ val df2 = Seq(("a:1,b:2,c:3", "y")).toDF("a", "b")
+
+ checkAnswer(
+ df2.selectExpr("str_to_map(a)"),
+ Seq(Row(Map("a" -> "1", "b" -> "2", "c" -> "3")))
+ )
+
+ }
}