panbingkun commented on code in PR #40506:
URL: https://github.com/apache/spark/pull/40506#discussion_r1263225024
##########
sql/core/src/test/scala/org/apache/spark/sql/JsonFunctionsSuite.scala:
##########
@@ -1392,4 +1393,25 @@ class JsonFunctionsSuite extends QueryTest with
SharedSparkSession {
checkAnswer(df.selectExpr("json_object_keys(a)"), expected)
checkAnswer(df.select(json_object_keys($"a")), expected)
}
+
+ test("GET_JSON_OBJECT Codegen Support") {
+ withTempView("GetJsonObjectTable") {
+ val data = Seq(("1", """{"f1": "value1", "f5": 5.23}""")).toDF("key",
"jstring")
+ data.createOrReplaceTempView("GetJsonObjectTable")
+ val df = sql("SELECT key, get_json_object(jstring, '$.f1') FROM
GetJsonObjectTable")
+ val plan = df.queryExecution.executedPlan
+ assert(plan.isInstanceOf[WholeStageCodegenExec])
+ checkAnswer(df, Seq(Row("1", "value1")))
+ }
+ }
+
+ test("path is null") {
+ val df: DataFrame = Seq(("""{"name": "alice", "age": 5}""", "")).toDF("a",
"b")
+ checkAnswer(df.selectExpr("get_json_object(a, null)"), Row(null))
+ }
+
+ test("json is null") {
+ val df: DataFrame = Seq(("""{"name": "alice", "age": 5}""",
"")).toDF("a", "b")
+ checkAnswer(df.selectExpr("get_json_object(null, '$.name')"), Row(null))
Review Comment:
All Done.
--
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]