sunchao commented on code in PR #6883: URL: https://github.com/apache/datafusion-comet/pull/6883#discussion_r4266138751
########## spark-local/src/main/scala/org/apache/comet/local/CometLocalResultExec.scala: ########## @@ -0,0 +1,122 @@ +/* + * 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.comet.local + +import java.util.concurrent.ConcurrentHashMap +import java.util.concurrent.atomic.AtomicLong + +import scala.collection.mutable.ArrayBuffer + +import org.apache.spark.SparkException +import org.apache.spark.rdd.RDD +import org.apache.spark.sql.catalyst.InternalRow +import org.apache.spark.sql.catalyst.expressions.{Attribute, SortOrder, UnsafeRow} +import org.apache.spark.sql.catalyst.plans.physical.Partitioning +import org.apache.spark.sql.execution.{SparkPlan, UnaryExecNode} + +/** + * Row result boundary of a local query. Spark's collect encodes and compresses every row of a + * result partition in its task, then decodes them on the driver. A local query has one result + * partition, so that work would run on a single thread. Admission requires an in-process local + * master, so collect and take still run one Spark task (keeping cancellation, job groups and SQL + * metrics) but hand copied rows to the driver in this JVM. + */ +case class CometLocalResultExec(child: SparkPlan) extends UnaryExecNode { Review Comment: [P2] Preserve bounded delivery for `toLocalIterator`. This wrapper specializes collect and take but inherits `SparkPlan.executeToIterator`, which serializes an entire Spark partition before yielding rows. Since `LocalQueryRDD` combines every source partition into one, iterator consumption now buffers the whole query. With `local[2]`, Comet range/local execution enabled and `spark.driver.maxResultSize=64k`, consuming `spark.range(0, 4000, 1, 8).selectExpr("id", "sha2(cast(id as string), 256) AS v").toLocalIterator()` fails with a 267.9 KiB task result. Spark and ordinary Comet both stream all 4,000 rows successfully. This makes previously streamable results fail the driver limit and increases buffering from one source partition to the whole query. Please provide bounded `executeToIterator` delivery or retain ordinary execution for iterator actions. Evidence: Reproduced on Spark 4.1.3/JDK 21 with JVM sources compiled at head 49dbdf859da3a8cc9022fb75c0633bb7da7c183e and the matching native CI artifact, SHA-256 4631fc089894cae2019bc78ac2cfdcb6cd11ca1bbbdd458dab5162e6edc67dbd. Spark and ordinary Comet returned rows=4000. Local execution failed: `Total size of serialized results of 1 tasks (267.9 KiB) is bigger than spark.driver.maxResultSize (64.0 KiB)`. The local plan contains `CometLocalResult -> ColumnarToRow -> CometLocal`, with eight range slices. Spark 3.4.3 through 4.2.0 have identical `executeToIterator` implementations calling `getByteArrayRdd().map(_._2).toLocalIterator`. Reproduction and output: `/tmp/comet6883-review-active-9jbswbx6/ReviewIteratorProbe.scala` and `/tmp/comet6883-review-active-9jbswbx6/iterator.log`. -- 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]
