-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-21677][SQL] json_tuple throws NullPointException when column is null as string type #18930
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
596c280
796041f
f07a9f7
ffa575a
5d71263
0078445
5c69df5
ab16929
e0e0c74
5191ed4
ff3b9da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2034,4 +2034,25 @@ class JsonSuite extends QueryTest with SharedSQLContext with TestJsonData { | |
| } | ||
| } | ||
| } | ||
|
|
||
| test("SPARK-21677: json_tuple throws NullPointException when column is null as string type") { | ||
| checkAnswer(sql( | ||
| """ | ||
| |SELECT json_tuple('{"a" : 1, "b" : 2}' | ||
| |, cast(NULL AS STRING), 'b' | ||
| |, cast(NULL AS STRING), 'a') | ||
| """.stripMargin), Row(null, "2", null, "1")) | ||
|
||
|
|
||
| // mixes constant field name and non constant one | ||
| withTempView("jsonTable") { | ||
| Seq(("""{"a": 1, "b": 2}""", "a", "b")) | ||
| .toDF("jsonField", "a", "b") | ||
| .createOrReplaceTempView("jsonTable") | ||
|
|
||
| checkAnswer( | ||
| sql("""SELECT json_tuple(jsonField, b, cast(NULL AS STRING), 'a') FROM jsonTable"""), | ||
|
||
| Row("2", null, "1") | ||
| ) | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we move this to
spark/sql/core/src/test/resources/sql-tests/inputs/json-functions.sqland/orspark/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/JsonExpressionsSuite.scala?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just an end-to-end test case. We also need to add unit test cases in
JsonExpressionsSuiteUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The end-to-end test at L2047 may not be able to move to
JsonExpressionsSuite. We can have some unit test cases similar to L2039 inJsonExpressionsSuiteas @gatorsmile suggested.It is also good to have this end-to-end tests in
json-functions.sql.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gatorsmile has added unit test case in
JsonExpressionsSuite@viirya also add end-to-end test in
json-functions.sql