MaxGekk commented on issue #27836: [SPARK-31009][SQL] Support json_object_keys 
function
URL: https://github.com/apache/spark/pull/27836#issuecomment-602044002
 
 
   The function works for literals but I got NPE on a column with JSON objects:
   ```scala
     test("json_object_keys") {
       spark.sql("""select json_object_keys('{"a": 1, "b": 2, "c": 
3}')""").show(false)
       val df = Seq(
         """{"a":1}""",
         """{"a":1, "b":2}""",
         """{"a": 1, "b": 2, "c": 3}""").toDF("json")
       df.show(false)
       val dfKeys = df.selectExpr("json_object_keys(json)")
       dfKeys.show(false)
     }
   ```
   ```
   +------------------------------------------+
   |json_object_keys({"a": 1, "b": 2, "c": 3})|
   +------------------------------------------+
   |[a, b, c]                                 |
   +------------------------------------------+
   
   +------------------------+
   |json                    |
   +------------------------+
   |{"a":1}                 |
   |{"a":1, "b":2}          |
   |{"a": 1, "b": 2, "c": 3}|
   +------------------------+
   
   06:28:11.089 ERROR org.apache.spark.executor.Executor: Exception in task 0.0 
in stage 3.0 (TID 3)
   java.lang.NullPointerException
        at 
org.apache.spark.sql.catalyst.InternalRow$.$anonfun$getAccessor$16(InternalRow.scala:152)
   ...
   Caused by: java.lang.NullPointerException
        at 
org.apache.spark.sql.catalyst.InternalRow$.$anonfun$getAccessor$16(InternalRow.scala:152)
        at 
org.apache.spark.sql.catalyst.InternalRow$.$anonfun$getAccessor$16$adapted(InternalRow.scala:151)
        at 
org.apache.spark.sql.catalyst.expressions.BoundReference.eval(BoundAttribute.scala:41)
        at 
org.apache.spark.sql.catalyst.expressions.JsonObjectKeys.json$lzycompute(jsonExpressions.scala:812)
        at 
org.apache.spark.sql.catalyst.expressions.JsonObjectKeys.json(jsonExpressions.scala:812)
   ```

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to