@@ -19,7 +19,8 @@ package com.nvidia.spark.rapids.iceberg
1919import scala .reflect .ClassTag
2020import scala .util .Try
2121
22- import com .nvidia .spark .rapids .{AppendDataExecMeta , AtomicCreateTableAsSelectExecMeta , AtomicReplaceTableAsSelectExecMeta , FileFormatChecks , GpuExec , GpuExpression , GpuRowToColumnarExec , GpuScan , IcebergFormatType , OverwriteByExpressionExecMeta , OverwritePartitionsDynamicExecMeta , RapidsConf , ScanMeta , ScanRule , ShimReflectionUtils , SparkPlanMeta , StaticInvokeMeta , TargetSize , WriteFileOp }
22+ import com .nvidia .spark .rapids .{AppendDataExecMeta , AtomicCreateTableAsSelectExecMeta , AtomicReplaceTableAsSelectExecMeta , FileFormatChecks , GpuExec , GpuExpression , GpuScan , IcebergFormatType , OverwriteByExpressionExecMeta , OverwritePartitionsDynamicExecMeta , RapidsConf , ScanMeta , ScanRule , ShimReflectionUtils , SparkPlanMeta , StaticInvokeMeta , WriteFileOp }
23+ import com .nvidia .spark .rapids .iceberg .IcebergProviderImpl .checkChildPlan
2324import com .nvidia .spark .rapids .shims .{ReplaceDataExecMeta , WriteDeltaExecMeta }
2425import org .apache .iceberg .spark .GpuTypeToSparkType .toSparkType
2526import org .apache .iceberg .spark .functions ._
@@ -31,6 +32,7 @@ import org.apache.spark.sql.catalyst.expressions.objects.StaticInvoke
3132import org .apache .spark .sql .connector .read .Scan
3233import org .apache .spark .sql .connector .write .Write
3334import org .apache .spark .sql .execution .SparkPlan
35+ import org .apache .spark .sql .execution .adaptive .AdaptiveSparkPlanExec
3436import org .apache .spark .sql .execution .datasources .v2 .{AppendDataExec , AtomicCreateTableAsSelectExec , AtomicReplaceTableAsSelectExec , GpuAppendDataExec , GpuOverwriteByExpressionExec , GpuOverwritePartitionsDynamicExec , GpuReplaceDataExec , GpuWriteDeltaExec , OverwriteByExpressionExec , OverwritePartitionsDynamicExec , ReplaceDataExec , WriteDeltaExec }
3537import org .apache .spark .sql .execution .datasources .v2 .rapids .{GpuAtomicCreateTableAsSelectExec , GpuAtomicReplaceTableAsSelectExec }
3638import org .apache .spark .sql .types .{DateType , TimestampType }
@@ -177,6 +179,8 @@ class IcebergProviderImpl extends IcebergProvider {
177179 FileFormatChecks .tag(meta, cpuExec.query.schema, IcebergFormatType , WriteFileOp )
178180
179181 GpuSparkWrite .tagForGpuCtas(cpuExec, meta)
182+
183+ checkChildPlan(meta)
180184 }
181185
182186 private def convertToGpu (
@@ -208,6 +212,8 @@ class IcebergProviderImpl extends IcebergProvider {
208212 FileFormatChecks .tag(meta, cpuExec.query.schema, IcebergFormatType , WriteFileOp )
209213
210214 GpuSparkWrite .tagForGpuRtas(cpuExec, meta)
215+
216+ checkChildPlan(meta)
211217 }
212218
213219 private def convertToGpu (
@@ -238,15 +244,13 @@ class IcebergProviderImpl extends IcebergProvider {
238244 FileFormatChecks .tag(meta, cpuExec.query.schema, IcebergFormatType , WriteFileOp )
239245
240246 GpuSparkWrite .tagForGpu(cpuExec.write, meta)
247+
248+ checkChildPlan(meta)
241249 }
242250
243251 private def convertToGpu (cpuExec : AppendDataExec , meta : AppendDataExecMeta ): GpuExec = {
244- var child : SparkPlan = meta.childPlans.head.convertIfNeeded()
245- if (! child.supportsColumnar) {
246- child = GpuRowToColumnarExec (child, TargetSize (meta.conf.gpuTargetBatchSizeBytes))
247- }
248252 GpuAppendDataExec (
249- child ,
253+ meta.childPlans.head.convertIfNeeded() ,
250254 cpuExec.refreshCache,
251255 GpuSparkWrite .convert(cpuExec.write))
252256 }
@@ -266,16 +270,14 @@ class IcebergProviderImpl extends IcebergProvider {
266270 FileFormatChecks .tag(meta, cpuExec.query.schema, IcebergFormatType , WriteFileOp )
267271
268272 GpuSparkWrite .tagForGpu(cpuExec.write, meta)
273+
274+ checkChildPlan(meta)
269275 }
270276
271277 private def convertToGpu (cpuExec : OverwritePartitionsDynamicExec ,
272278 meta : OverwritePartitionsDynamicExecMeta ): GpuExec = {
273- var child : SparkPlan = meta.childPlans.head.convertIfNeeded()
274- if (! child.supportsColumnar) {
275- child = GpuRowToColumnarExec (child, TargetSize (meta.conf.gpuTargetBatchSizeBytes))
276- }
277279 GpuOverwritePartitionsDynamicExec (
278- child ,
280+ meta.childPlans.head.convertIfNeeded() ,
279281 cpuExec.refreshCache,
280282 GpuSparkWrite .convert(cpuExec.write))
281283 }
@@ -295,16 +297,14 @@ class IcebergProviderImpl extends IcebergProvider {
295297 FileFormatChecks .tag(meta, cpuExec.query.schema, IcebergFormatType , WriteFileOp )
296298
297299 GpuSparkWrite .tagForGpu(cpuExec.write, meta)
300+
301+ checkChildPlan(meta)
298302 }
299303
300304 private def convertToGpu (cpuExec : OverwriteByExpressionExec ,
301305 meta : OverwriteByExpressionExecMeta ): GpuExec = {
302- var child : SparkPlan = meta.childPlans.head.convertIfNeeded()
303- if (! child.supportsColumnar) {
304- child = GpuRowToColumnarExec (child, TargetSize (meta.conf.gpuTargetBatchSizeBytes))
305- }
306306 GpuOverwriteByExpressionExec (
307- child ,
307+ meta.childPlans.head.convertIfNeeded() ,
308308 cpuExec.refreshCache,
309309 GpuSparkWrite .convert(cpuExec.write))
310310 }
@@ -366,15 +366,13 @@ class IcebergProviderImpl extends IcebergProvider {
366366 FileFormatChecks .tag(meta, cpuExec.query.schema, IcebergFormatType , WriteFileOp )
367367
368368 GpuSparkWrite .tagForGpu(cpuExec.write, meta)
369+
370+ checkChildPlan(meta)
369371 }
370372
371373 private def convertToGpu (cpuExec : ReplaceDataExec , meta : ReplaceDataExecMeta ): GpuExec = {
372- var child : SparkPlan = meta.childPlans.head.convertIfNeeded()
373- if (! child.supportsColumnar) {
374- child = GpuRowToColumnarExec (child, TargetSize (meta.conf.gpuTargetBatchSizeBytes))
375- }
376374 GpuReplaceDataExec (
377- child ,
375+ meta.childPlans.head.convertIfNeeded() ,
378376 cpuExec.refreshCache,
379377 GpuSparkWrite .convert(cpuExec.write))
380378 }
@@ -395,17 +393,26 @@ class IcebergProviderImpl extends IcebergProvider {
395393 IcebergFormatType , WriteFileOp )
396394
397395 GpuSparkPositionDeltaWrite .tagForGpu(cpuExec.write, meta)
396+
397+ checkChildPlan(meta)
398398 }
399399
400400 private def convertToGpu (cpuExec : WriteDeltaExec , meta : WriteDeltaExecMeta ): GpuExec = {
401- var child : SparkPlan = meta.childPlans.head.convertIfNeeded()
402- if (! child.supportsColumnar) {
403- child = GpuRowToColumnarExec (child, TargetSize (meta.conf.gpuTargetBatchSizeBytes))
404- }
405401 GpuWriteDeltaExec (
406- child ,
402+ meta.childPlans.head.convertIfNeeded() ,
407403 cpuExec.refreshCache,
408404 cpuExec.projections,
409405 GpuSparkPositionDeltaWrite .convert(cpuExec.write))
410406 }
411407}
408+
409+ object IcebergProviderImpl {
410+ def checkChildPlan [T <: SparkPlan ](meta : SparkPlanMeta [T ]): Unit = {
411+ if (meta.childPlans.nonEmpty) {
412+ val childMeta = meta.childPlans.head
413+ if (! childMeta.wrapped.isInstanceOf [AdaptiveSparkPlanExec ] && ! childMeta.canThisBeReplaced) {
414+ meta.willNotWorkOnGpu(" Because child can't run gpu" )
415+ }
416+ }
417+ }
418+ }
0 commit comments