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

Converting an column containing an array into json throws an exception #10896

Closed
Feng-Jiang28 opened this issue May 25, 2024 · 0 comments · Fixed by #11642
Closed

Converting an column containing an array into json throws an exception #10896

Feng-Jiang28 opened this issue May 25, 2024 · 0 comments · Fixed by #11642
Assignees
Labels
bug Something isn't working

Comments

@Feng-Jiang28
Copy link
Contributor

Feng-Jiang28 commented May 25, 2024

Converting an colunn containing an array into json format throws an exception.

Reproduce:

CPU:

scala> val df = Seq(Array(1, 2, 3)).toDF("a")
scala> df.write.mode("OVERWRITE").parquet("TEMP")
scala> val df2 = spark.read.parquet("TEMP")
scala> df2.select(to_json($"a")).show()
+----------+                                                                    
|to_json(a)|
+----------+
|   [1,2,3]|
+----------+

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> val df = Seq(Array(1, 2, 3)).toDF("a")
scala> df.write.mode("OVERWRITE").parquet("TEMP")
scala> val df2 = spark.read.parquet("TEMP")
scala> df2.select(to_json($"a")).show()
24/05/25 05:34:56 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> to_json(a#41, Some(UTC)) AS to_json(a)#47 will run on GPU
      *Expression <StructsToJson> to_json(a#41, Some(UTC)) will run on GPU
    *Exec <FileSourceScanExec> will run on GPU

24/05/25 05:34:56 ERROR Executor: Exception in task 0.0 in stage 11.0 (TID 11)
java.lang.ClassCastException: org.apache.spark.sql.types.ArrayType cannot be cast to org.apache.spark.sql.types.StructType
	at org.apache.spark.sql.rapids.GpuStructsToJson.doColumnar(GpuStructsToJson.scala:86)
	at com.nvidia.spark.rapids.GpuUnaryExpression.doItColumnar(GpuExpressions.scala:250)
	at com.nvidia.spark.rapids.GpuUnaryExpression.$anonfun$columnarEval$1(GpuExpressions.scala:261)
	at com.nvidia.spark.rapids.Arm$.withResource(Arm.scala:30)
	at com.nvidia.spark.rapids.GpuUnaryExpression.columnarEval(GpuExpressions.scala:260)
	at com.nvidia.spark.rapids.RapidsPluginImplicits$ReallyAGpuExpression.columnarEval(implicits.scala:35)
	at com.nvidia.spark.rapids.GpuAlias.columnarEval(namedExpressions.scala:110)
	at com.nvidia.spark.rapids.RapidsPluginImplicits$ReallyAGpuExpression.columnarEval(implicits.scala:35)
	at com.nvidia.spark.rapids.GpuProjectExec$.$anonfun$project$1(basicPhysicalOperators.scala:110)
	at com.nvidia.spark.rapids.RapidsPluginImplicits$MapsSafely.$anonfun$safeMap$1(implicits.scala:221)
	at com.nvidia.spark.rapids.RapidsPluginImplicits$MapsSafely.$anonfun$safeMap$1$adapted(implicits.scala:218)
	at scala.collection.immutable.List.foreach(List.scala:431)
	at com.nvidia.spark.rapids.RapidsPluginImplicits$MapsSafely.safeMap(impli
@Feng-Jiang28 Feng-Jiang28 changed the title to_json - array of primitive types Converting an colunn containing an Array into JSON format throws an exception May 25, 2024
@Feng-Jiang28 Feng-Jiang28 changed the title Converting an colunn containing an Array into JSON format throws an exception Converting an colunn containing an array into json throws an exception May 25, 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 removed the ? - Needs Triage Need team to review and classify label May 28, 2024
@GaryShen2008 GaryShen2008 changed the title Converting an colunn containing an array into json throws an exception Converting an column containing an array into json throws an exception Jul 5, 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

Successfully merging a pull request may close this issue.

3 participants