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 a column containing a map into json throws an exception #10895

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

Converting a column containing a map into json throws an exception #10895

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 a column containing a Map into json throws an exception:

Reproduce:

CPU:

scala> val df = Seq(Map("a" -> Tuple1(1))).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)|
+--------------+
|{"a":{"_1":1}}|
+--------------+

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(Map("a" -> Tuple1(1))).toDF("a")
scala> df.write.mode("OVERWRITE").parquet("TEMP")
scala> val df2 = spark.read.parquet("TEMP")
df2: org.apache.spark.sql.DataFrame = [a: map<string,struct<_1:int>>]
scala> df2.select(to_json($"a")).show()
  @Partitioning <SinglePartition$> could run on GPU
  *Exec <ProjectExec> will run on GPU
    *Expression <Alias> to_json(a#24, Some(UTC)) AS to_json(a)#30 will run on GPU
      *Expression <StructsToJson> to_json(a#24, Some(UTC)) will run on GPU
    *Exec <FileSourceScanExec> will run on GPU
 ...
24/05/25 04:59:58 ERROR Executor: Exception in task 0.0 in stage 7.0 (TID 7)
java.lang.ClassCastException: org.apache.spark.sql.types.MapType 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)
...
@Feng-Jiang28 Feng-Jiang28 changed the title to_json - map Converting a column containing a Map into json throws an exception: May 25, 2024
@Feng-Jiang28 Feng-Jiang28 changed the title Converting a column containing a Map into json throws an exception: Converting a column containing a map into json throws an exception: May 25, 2024
@Feng-Jiang28 Feng-Jiang28 changed the title Converting a column containing a map into json throws an exception: Converting a column containing a map 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
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