You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Apache Spark (Jira)" <ji...@apache.org> on 2020/10/13 13:22:00 UTC

[jira] [Assigned] (SPARK-33134) Incorrect nested complex JSON fields raise an exception

     [ https://issues.apache.org/jira/browse/SPARK-33134?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Apache Spark reassigned SPARK-33134:
------------------------------------

    Assignee:     (was: Apache Spark)

> Incorrect nested complex JSON fields raise an exception
> -------------------------------------------------------
>
>                 Key: SPARK-33134
>                 URL: https://issues.apache.org/jira/browse/SPARK-33134
>             Project: Spark
>          Issue Type: Improvement
>          Components: SQL
>    Affects Versions: 3.0.2, 3.1.0
>            Reporter: Maxim Gekk
>            Priority: Major
>
> The code below:
> {code:scala}
> val pokerhand_raw = Seq("""[{"cards": [11], "playerId": 583651}]""").toDF("events")
>     val event = new StructType()
>       .add("playerId", LongType)
>       .add("cards", ArrayType(
>         new StructType()
>           .add("id", LongType)
>           .add("rank", StringType)))
>     val pokerhand_events = pokerhand_raw
>       .select(explode(from_json($"events", ArrayType(event))).as("event"))
>     pokerhand_events.show
> {code}
> throw the exception in the PERMISSIVE mode (default):
> {code:java}
> Caused by: java.lang.ClassCastException: java.lang.Long cannot be cast to org.apache.spark.sql.catalyst.util.ArrayData
>   at org.apache.spark.sql.catalyst.expressions.BaseGenericInternalRow.getArray(rows.scala:48)
>   at org.apache.spark.sql.catalyst.expressions.BaseGenericInternalRow.getArray$(rows.scala:48)
>   at org.apache.spark.sql.catalyst.expressions.GenericInternalRow.getArray(rows.scala:195)
>   at org.apache.spark.sql.catalyst.expressions.JsonToStructs.$anonfun$converter$2(jsonExpressions.scala:560)
>   at org.apache.spark.sql.catalyst.expressions.JsonToStructs.nullSafeEval(jsonExpressions.scala:597)
>   at org.apache.spark.sql.catalyst.expressions.UnaryExpression.eval(Expression.scala:461)
>   at org.apache.spark.sql.catalyst.expressions.ExplodeBase.eval(generators.scala:313)
>   at org.apache.spark.sql.execution.GenerateExec.$anonfun$doExecute$8(GenerateExec.scala:108)
> {code}
> The same works in Spark 2.4:
> {code:scala}
> Welcome to
>       ____              __
>      / __/__  ___ _____/ /__
>     _\ \/ _ \/ _ `/ __/  '_/
>    /___/ .__/\_,_/_/ /_/\_\   version 2.4.6
>       /_/
> Using Scala version 2.11.12 (OpenJDK 64-Bit Server VM, Java 1.8.0_265)
> ...
> scala> pokerhand_events.show()
> +-----+
> |event|
> +-----+
> +-----+
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org