cloud-fan commented on code in PR #46141:
URL: https://github.com/apache/spark/pull/46141#discussion_r1574060791
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/variant/variantExpressions.scala:
##########
@@ -75,6 +75,36 @@ case class ParseJson(child: Expression)
copy(child = newChild)
}
+// scalastyle:off line.size.limit
+@ExpressionDescription(
+ usage = "_FUNC_(jsonStr) - Parse a JSON string as an Variant value. Returns
null when the string is not valid JSON value.",
+ examples = """
+ Examples:
+ > SELECT _FUNC_('{"a":1,"b":0.8}');
+ {"a":1,"b":0.8}
+ """,
+ since = "4.0.0",
+ group = "variant_funcs"
+)
+// scalastyle:on line.size.limit
+case class TryParseJson(expr: Expression, replacement: Expression)
+ extends RuntimeReplaceable with InheritAnalysisRules {
+ def this(child: Expression) = this(child, TryEval(ParseJson(child)))
Review Comment:
I'm not a big fan of the `TryEval` approach, as it's more like a temporary
workaround. See this TODO:
https://github.com/apache/spark/blob/master/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/TryEval.scala#L83
The issue is, `TryEval` swallows all the exceptions, including the ones from
inputs. e.g. `try_parse_json(a function that produces JSON string but fails)`
should still fail.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]