Skip to content

Commit

Permalink
map column would throw NPE if value is null
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-wang committed Jan 28, 2016
1 parent 3327fd2 commit 5b2d942
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -307,7 +307,7 @@ case class GetMapValue(child: Expression, key: Expression)
}
}

if ($found) {
if ($found && !$eval1.valueArray().isNullAt($index)) {
${ev.value} = ${ctx.getValue(eval1 + ".valueArray()", dataType, index)};
} else {
${ev.isNull} = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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""")
checkAnswer(sql("SELECT col1['abc'] FROM maptest"), Row("somestring"))
checkAnswer(sql("SELECT col1['cba'] FROM maptest"), Row(null))
}
}

0 comments on commit 5b2d942

Please sign in to comment.