Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/13990#discussion_r70562486
--- Diff:
sql/core/src/test/scala/org/apache/spark/sql/StringFunctionsSuite.scala ---
@@ -384,4 +384,39 @@ 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")))
+ )
+
+ // All arguments should be string literals.
+ val m1 = intercept[AnalysisException]{
+ sql("select str_to_map('a:1,b:2,c:3',null,null)").collect()
--- End diff --
What's hive's behaviour about this? Does hive reject null delimiters either?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]