Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

from_json throws exception when the json's structure only partially matches the provided schema #10901

Open
Feng-Jiang28 opened this issue May 27, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@Feng-Jiang28
Copy link
Collaborator

Feng-Jiang28 commented May 27, 2024

from_json function parses a column containing JSON data using a StructType object based on a provided schema, throws an exception, when the json's structure only partially matches the shema.

CPU:

cala>     import org.apache.spark.sql.types.{ArrayType, IntegerType, LongType, MapType, StringType, StructType}
scala>     import org.apache.spark.sql.functions.{from_json, to_json}
scala>     import org.apache.spark.sql.{Row}
scala>           val st = new StructType().add("c1", LongType).add("c2", ArrayType(new StructType().add("c3", LongType).add("c4", StringType)))
scala>     val df1 = Seq("""{"c2": [19], "c1": 123456}""").toDF("c0")
scala>     df1.write.mode("OVERWRITE").parquet("TEMP")                                                           
scala>           val df2 = spark.read.parquet("TEMP")
scala>     df2.select(from_json($"c0", st)).show()
+--------------+
| from_json(c0)|
+--------------+
|{123456, null}|
+--------------+

GPU:

$SPARK_HOME/bin/spark-shell --master local[*] --jars ${SPARK_RAPIDS_PLUGIN_JAR} --conf spark.plugins=com.nvidia.spark.SQLPlugin --conf spark.rapids.sql.enabled=true --conf spark.rapids.sql.explain=ALL --driver-java-options '-ea -Duser.timezone=UTC ' --conf spark.rapids.sql.expression.JsonTuple=true --conf spark.rapids.sql.expression.GetJsonObject=true --conf spark.rapids.sql.expression.JsonToStructs=true --conf spark.rapids.sql.expression.StructsToJson=true

scala>     import org.apache.spark.sql.types.{ArrayType, IntegerType, LongType, MapType, StringType, StructType}
scala>     import org.apache.spark.sql.functions.{from_json, to_json}
scala>     import org.apache.spark.sql.{Row}
scala>           val st = new StructType().add("c1", LongType).add("c2", ArrayType(new StructType().add("c3", LongType).add("c4", StringType)))
scala>     val df1 = Seq("""{"c2": [19], "c1": 123456}""").toDF("c0")
scala>     df1.write.mode("OVERWRITE").parquet("TEMP")                                                                              
scala>           val df2 = spark.read.parquet("TEMP")
scala>     df2.select(from_json($"c0", st)).show()
24/05/27 03:36:48 WARN GpuOverrides: 
!Exec <CollectLimitExec> cannot run on GPU because the Exec CollectLimitExec has been disabled, and is disabled by default because Collect Limit replacement can be slower on the GPU, if huge number of rows in a batch it could help by limiting the number of rows transferred from GPU to CPU. Set spark.rapids.sql.exec.CollectLimitExec to true if you wish to enable it
  @Partitioning <SinglePartition$> could run on GPU
  *Exec <ProjectExec> will run on GPU
    *Expression <Alias> cast(from_json(StructField(c1,LongType,true), StructField(c2,ArrayType(StructType(StructField(c3,LongType,true),StructField(c4,StringType,true)),true),true), c0#7, Some(UTC)) as string) AS from_json(c0)#13 will run on GPU
      *Expression <Cast> cast(from_json(StructField(c1,LongType,true), StructField(c2,ArrayType(StructType(StructField(c3,LongType,true),StructField(c4,StringType,true)),true),true), c0#7, Some(UTC)) as string) will run on GPU
        *Expression <JsonToStructs> from_json(StructField(c1,LongType,true), StructField(c2,ArrayType(StructType(StructField(c3,LongType,true),StructField(c4,StringType,true)),true),true), c0#7, Some(UTC)) will run on GPU
    *Exec <FileSourceScanExec> will run on GPU

24/05/27 03:36:49 ERROR Executor: Exception in task 0.0 in stage 3.0 (TID 3)
ai.rapids.cudf.CudfException: CUDF failure at: /home/jenkins/agent/workspace/jenkins-spark-rapids-jni_nightly-pre_release-295-cuda11/target/libcudf-install/include/cudf/column/column_factories.hpp:343: Invalid, non-fixed-width type.
	at ai.rapids.cudf.Table.readJSONFromDataSource(Native Method)
	at ai.rapids.cudf.Table.readJSON(Table.java:1441)

@Feng-Jiang28 Feng-Jiang28 changed the title SPARK-33134: return partial results only for root JSON objects from_json function parses a column containing JSON data using a StructType object based on a provided schema, throws an exception, when the json's structure only partially matches the shema. May 27, 2024
@revans2 revans2 self-assigned this May 28, 2024
@revans2 revans2 added bug Something isn't working ? - Needs Triage Need team to review and classify labels May 28, 2024
@mattahrens mattahrens assigned Feng-Jiang28 and unassigned revans2 May 28, 2024
@mattahrens mattahrens removed the ? - Needs Triage Need team to review and classify label May 28, 2024
@GaryShen2008 GaryShen2008 changed the title from_json function parses a column containing JSON data using a StructType object based on a provided schema, throws an exception, when the json's structure only partially matches the shema. from_json Exception, when the json's structure only partially matches the provided schema Jun 7, 2024
@GaryShen2008 GaryShen2008 changed the title from_json Exception, when the json's structure only partially matches the provided schema from_json throws exception when the json's structure only partially matches the provided schema Jun 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants