cala> val dataSourceName = "parquet"
dataSourceName: String = parquet
scala> val path = "/home/fejiang/Desktop"
path: String = /home/fejiang/Desktop
scala> val schema = ("`id` INT,`name` STRUCT<`first`: STRING, `middle`: STRING, `last`: STRING>, " +
| "`address` STRING,`pets` INT,`friends` ARRAY<STRUCT<`first`: STRING, `middle`: STRING, " +
| "`last`: STRING>>,`relatives` MAP<STRING, STRUCT<`first`: STRING, `middle`: STRING, " +
| "`last`: STRING>>,`employer` STRUCT<`id`: INT, `company`: STRUCT<`name`: STRING, " +
| "`address`: STRING>>,`relations` MAP<STRUCT<`first`: STRING, `middle`: STRING, " +
| "`last`: STRING>,STRING>,`p` INT")
schema: String = `id` INT,`name` STRUCT<`first`: STRING, `middle`: STRING, `last`: STRING>, `address` STRING,`pets` INT,`friends` ARRAY<STRUCT<`first`: STRING, `middle`: STRING, `last`: STRING>>,`relatives` MAP<STRING, STRUCT<`first`: STRING, `middle`: STRING, `last`: STRING>>,`employer` STRUCT<`id`: INT, `company`: STRUCT<`name`: STRING, `address`: STRING>>,`relations` MAP<STRUCT<`first`: STRING, `middle`: STRING, `last`: STRING>,STRING>,`p` INT
scala> spark.read.format(dataSourceName).schema(schema).load(path + "/contacts").createOrReplaceTempView("contacts")
scala> spark.sql("set spark.sql.optimizer.nestedSchemaPruning.enabled=false")
res1: org.apache.spark.sql.DataFrame = [key: string, value: string]
scala> spark.sql("set spark.sql.optimizer.expression.nestedPruning.enabled=true")
res2: org.apache.spark.sql.DataFrame = [key: string, value: string]
scala> val query1 = spark.table("contacts").select(explode(col("friends.first")))
query1: org.apache.spark.sql.DataFrame = [col: string]
scala> query1.explain()
24/10/24 15:35:06 WARN GpuOverrides:
*Exec <GenerateExec> will run on GPU
*Expression <Explode> explode(friends#4.first) will run on GPU
*Expression <GetArrayStructFields> friends#4.first will run on GPU
*Exec <ProjectExec> will run on GPU
*Exec <FileSourceScanExec> will run on GPU
== Physical Plan ==
GpuColumnarToRow false
+- GpuGenerate gpuexplode(friends#4.first), false, [col#48]
+- GpuProject [friends#4]
+- GpuFileGpuScan parquet [friends#4] Batched: true, DataFilters: [], Format: Parquet, Location: InMemoryFileIndex[file:/home/fejiang/Desktop/contacts], PartitionFilters: [], PushedFilters: [], ReadSchema: struct<friends:array<struct<first:string,middle:string,last:string>>>
scala> query1.show()
24/10/24 15:35:07 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 <GenerateExec> will run on GPU
*Expression <Explode> explode(friends#4.first) will run on GPU
*Expression <GetArrayStructFields> friends#4.first will run on GPU
*Exec <ProjectExec> will run on GPU
*Exec <FileSourceScanExec> will run on GPU
24/10/24 15:35:07 ERROR GpuOverrideUtil: Encountered an exception applying GPU overrides java.lang.IllegalArgumentException: Part of the plan is not columnar class org.apache.spark.sql.execution.CollectLimitExec
CollectLimit 21
+- GpuColumnarToRow false
+- GpuGenerate gpuexplode(friends#4.first), false, [col#48], [loreId=2]
+- GpuProject [friends#4], [loreId=1]
+- GpuFileGpuScan parquet [friends#4] Batched: true, DataFilters: [], Format: Parquet, Location: InMemoryFileIndex[file:/home/fejiang/Desktop/contacts], PartitionFilters: [], PushedFilters: [], ReadSchema: struct<friends:array<struct<first:string,middle:string,last:string>>>
java.lang.IllegalArgumentException: Part of the plan is not columnar class org.apache.spark.sql.execution.CollectLimitExec
CollectLimit 21
+- GpuColumnarToRow false
+- GpuGenerate gpuexplode(friends#4.first), false, [col#48], [loreId=2]
+- GpuProject [friends#4], [loreId=1]
+- GpuFileGpuScan parquet [friends#4] Batched: true, DataFilters: [], Format: Parquet, Location: InMemoryFileIndex[file:/home/fejiang/Desktop/contacts], PartitionFilters: [], PushedFilters: [], ReadSchema: struct<friends:array<struct<first:string,middle:string,last:string>>>
at com.nvidia.spark.rapids.GpuTransitionOverrides.assertIsOnTheGpu(GpuTransitionOverrides.scala:671)
at com.nvidia.spark.rapids.GpuTransitionOverrides.$anonfun$apply$3(GpuTransitionOverrides.scala:819)
at com.nvidia.spark.rapids.GpuOverrides$.logDuration(GpuOverrides.scala:457)
at com.nvidia.spark.rapids.GpuTransitionOverrides.$anonfun$apply$1(GpuTransitionOverrides.scala:793)
at com.nvidia.spark.rapids.GpuOverrideUtil$.$anonfun$tryOverride$1(GpuOverrides.scala:4646)
at com.nvidia.spark.rapids.GpuTransitionOverrides.apply(GpuTransitionOverrides.scala:852)
at com.nvidia.spark.rapids.GpuTransitionOverrides.apply(GpuTransitionOverrides.scala:46)
at org.apache.spark.sql.execution.ApplyColumnarRulesAndInsertTransitions.$anonfun$apply$2(Columnar.scala:555)
at org.apache.spark.sql.execution.ApplyColumnarRulesAndInsertTransitions.$anonfun$apply$2$adapted(Columnar.scala:555)
at scala.collection.mutable.ResizableArray.foreach(ResizableArray.scala:62)
at scala.collection.mutable.ResizableArray.foreach$(ResizableArray.scala:55)
at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:49)
at org.apache.spark.sql.execution.ApplyColumnarRulesAndInsertTransitions.apply(Columnar.scala:555)
at org.apache.spark.sql.execution.ApplyColumnarRulesAndInsertTransitions.apply(Columnar.scala:514)
at org.apache.spark.sql.execution.QueryExecution$.$anonfun$prepareForExecution$1(QueryExecution.scala:440)
at scala.collection.LinearSeqOptimized.foldLeft(LinearSeqOptimized.scala:126)
at scala.collection.LinearSeqOptimized.foldLeft$(LinearSeqOptimized.scala:122)
at scala.collection.immutable.List.foldLeft(List.scala:91)
****
Description:
contacts parquet is defined as following and has saved here: contacts.zip
Code to reproduce:
CPU:
GPU:
Start Plugin to run
strict mode