Skip to content

Commit

Permalink
Fix nullability of TryParseJson
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshRosen committed May 6, 2024
1 parent de8ba85 commit c41909c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ case class ParseJson(child: Expression, failOnError: Boolean = true)
"parseJson",
Seq(child, Literal(failOnError, BooleanType)),
inputTypes :+ BooleanType,
returnNullable = false)
returnNullable = !failOnError)

override def inputTypes: Seq[AbstractDataType] = StringType :: Nil

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,13 @@ class VariantExpressionSuite extends SparkFunSuite with ExpressionEvalHelper {
"Hello")
}

test("tryParseJson negative") {
checkEvaluation(
ParseJson(Literal("["), failOnError = false).replacement,
null
)
}

test("cast to variant") {
def check[T : TypeTag](input: T, expectedJson: String): Unit = {
val cast = Cast(Literal.create(input), VariantType, evalMode = EvalMode.ANSI)
Expand Down

0 comments on commit c41909c

Please sign in to comment.