andygrove commented on code in PR #4507:
URL: https://github.com/apache/datafusion-comet/pull/4507#discussion_r3343592930


##########
spark/src/main/scala/org/apache/spark/sql/comet/execution/shuffle/CometNativeShuffleInputRDD.scala:
##########
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.spark.sql.comet.execution.shuffle
+
+import org.apache.spark._
+import org.apache.spark.rdd.RDD
+import org.apache.spark.sql.vectorized.ColumnarBatch
+
+import org.apache.comet.CometShuffleBlockIterator
+
+/**
+ * Thin scheduling-anchor RDD for the native-shuffle path. Declares 
`OneToOneDependency` on each
+ * leaf input RDD (so the DAGScheduler triggers prior stages, broadcasts, 
etc.) and constructs
+ * per-partition leaf iterators in `compute`, packaged into a 
[[CometNativeShuffleInputIterator]].
+ * The iterator reports `hasNext = false`; [[CometNativeShuffleWriter]] 
downcasts it and reads the
+ * leaf iterators directly to drive the unified `ShuffleWriter(child = 
childNativeOp)` plan.
+ */
+private[shuffle] class CometNativeShuffleInputRDD(
+    sc: SparkContext,
+    var inputRDDs: Seq[RDD[ColumnarBatch]],
+    numPartitionsParam: Int,
+    shuffleScanIndices: Set[Int])
+    extends RDD[Product2[Int, ColumnarBatch]](
+      sc,
+      inputRDDs.map(rdd => new OneToOneDependency(rdd))) {
+
+  override protected def getPartitions: Array[Partition] =
+    (0 until numPartitionsParam).map { i =>
+      // Resolve leaf-RDD partitions on the driver here (where their 
@transient fields are still
+      // populated). Stashing them on the partition lets `compute` avoid 
touching
+      // `leafRdd.partitions` on the executor, which would otherwise trigger 
getPartitions and
+      // hit the @transient-null trap (e.g. CometExecRDD.perPartitionByKey).
+      val inputParts = inputRDDs.map(_.partitions(i)).toArray
+      new CometNativeShuffleInputPartition(i, inputParts)
+    }.toArray
+
+  override def compute(
+      split: Partition,
+      context: TaskContext): Iterator[Product2[Int, ColumnarBatch]] = {
+    val partition = split.asInstanceOf[CometNativeShuffleInputPartition]
+    val leafIterators = inputRDDs.zip(partition.inputPartitions).map { case 
(rdd, part) =>
+      rdd.iterator(part, context)
+    }
+    val shuffleBlockIters: Map[Int, CometShuffleBlockIterator] =
+      shuffleScanIndices.flatMap { si =>
+        inputRDDs(si) match {
+          case rdd: CometShuffledBatchRDD =>
+            Some(si -> 
rdd.computeAsShuffleBlockIterator(partition.inputPartitions(si), context))
+          case _ => None

Review Comment:
   Should `case _` throw an error instead? Is it safe to just skip input RDDs?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to