-
Notifications
You must be signed in to change notification settings - Fork 28.1k
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
[SPARK-13056][SQL] map column would throw NPE if value is null #10964
Changes from 1 commit
5b2d942
2244999
bf429ca
21f29a5
898cf20
d77013f
5b83626
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 |
---|---|---|
|
@@ -278,7 +278,7 @@ case class GetMapValue(child: Expression, key: Expression) | |
} | ||
} | ||
|
||
if (!found) { | ||
if (!found || map.valueArray().isNullAt(i)) { | ||
null | ||
} else { | ||
map.valueArray().get(i, dataType) | ||
|
@@ -307,7 +307,7 @@ case class GetMapValue(child: Expression, key: Expression) | |
} | ||
} | ||
|
||
if ($found) { | ||
if ($found && !$eval1.valueArray().isNullAt($index)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we assign |
||
${ev.value} = ${ctx.getValue(eval1 + ".valueArray()", dataType, index)}; | ||
} else { | ||
${ev.isNull} = true; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1463,4 +1463,11 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils with TestHiveSingleton { | |
|FROM (SELECT '{"f1": "value1", "f2": 12}' json, 'hello' as str) test | ||
""".stripMargin), Row("value1", "12", BigDecimal("3.14"), "hello")) | ||
} | ||
|
||
test("SPARK-13056: Null in map value causes NPE") { | ||
Seq((1, "abc=somestring,cba")).toDF("key", "value").registerTempTable("mapsrc") | ||
sql("""CREATE TABLE maptest AS SELECT str_to_map(value, ",", "=") as col1 FROM mapsrc""") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
checkAnswer(sql("SELECT col1['abc'] FROM maptest"), Row("somestring")) | ||
checkAnswer(sql("SELECT col1['cba'] FROM maptest"), Row(null)) | ||
} | ||
} |
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.
just realized the
GetArrayItem
also need to add null check for interpreted versioneval
, can you also fix that please?