You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "andygrove (via GitHub)" <gi...@apache.org> on 2024/08/16 20:47:15 UTC
[PR] chore: Preparatory work for implementing custom C2R [datafusion-comet]
andygrove opened a new pull request, #838:
URL: https://github.com/apache/datafusion-comet/pull/838
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
Closes https://github.com/apache/datafusion-comet/issues/837
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
This is in preparation for implementing an optimized C2R in Comet.
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
- Add `CometColumnarToRowExec` which is currently an identical copy of Spark's `ColumnarToRowExec`
- Adds new optimizer rules to replace `ColumnarToRowExec` with `CometColumnarToRowExec`
- Update expected plans
## How are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
Existing tests
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] chore: Preparatory work for implementing custom C2R [datafusion-comet]
Posted by "parthchandra (via GitHub)" <gi...@apache.org>.
parthchandra commented on code in PR #838:
URL: https://github.com/apache/datafusion-comet/pull/838#discussion_r1720376085
##########
spark/src/main/scala/org/apache/spark/sql/comet/CometColumnarToRowExec.scala:
##########
@@ -0,0 +1,81 @@
+/*
+ * 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
+
+import org.apache.comet.vector.CometVector
+
+import scala.collection.JavaConverters._
+import org.apache.spark.rdd.RDD
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.{Attribute, SortOrder, UnsafeProjection}
+import org.apache.spark.sql.catalyst.plans.physical.Partitioning
+import org.apache.spark.sql.execution.{ColumnarToRowTransition, SparkPlan}
+import org.apache.spark.sql.execution.metric.{SQLMetric, SQLMetrics}
+import org.apache.spark.util.Utils
+
+/**
+ * This is currently an identical copy of Spark's ColumnarToRowExec except for removing the
+ * code-gen features.
+ *
+ * This is moved into the Comet repo as the first step towards refactoring this to make the
+ * interactions with CometVector more efficient to avoid some JNI overhead.
+ */
+case class CometColumnarToRowExec(child: SparkPlan) extends ColumnarToRowTransition {
+ // supportsColumnar requires to be only called on driver side, see also SPARK-37779.
+ assert(Utils.isInRunningSparkTask || child.supportsColumnar)
+
+ override def output: Seq[Attribute] = child.output
+
+ override def outputPartitioning: Partitioning = child.outputPartitioning
+
+ override def outputOrdering: Seq[SortOrder] = child.outputOrdering
+
+ override lazy val metrics: Map[String, SQLMetric] = Map(
+ "numOutputRows" -> SQLMetrics.createMetric(sparkContext, "number of output rows"),
+ "numInputBatches" -> SQLMetrics.createMetric(sparkContext, "number of input batches"))
+
+ override def doExecute(): RDD[InternalRow] = {
+ val numOutputRows = longMetric("numOutputRows")
+ val numInputBatches = longMetric("numInputBatches")
+ // This avoids calling `output` in the RDD closure, so that we don't need to include the entire
+ // plan (this) in the closure.
+ val localOutput = this.output
+ child.executeColumnar().mapPartitionsInternal { batches =>
+ val toUnsafe = UnsafeProjection.create(localOutput, localOutput)
+ batches.flatMap { batch =>
+ numInputBatches += 1
+ numOutputRows += batch.numRows()
+
+ // TODO add code that is optimized for dealing with CometVector
+ // but we can do something like ...
+ for (i <- 0 until batch.numCols()) {
+ val cv = batch.column(i).asInstanceOf[CometVector]
+ // cv.importVector
Review Comment:
The current implementation accesses each value from the underlying buffer via JNI. This is reasonably quick for integers (and floating point too perhaps, though I have not verified that). But for byte buffers this is a performance killer.
Based on experiments with decimals in CometVector, we have seen that copying the entire buffer in one call and avoiding the JNI calls makes things much faster at the cost of increased memory usage.
The increase memory usage is something to keep in mind. We might have to experiment with varying the default batch size to get the right mix.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] experimental: Prefetch vectors in C2R [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove closed pull request #838: experimental: Prefetch vectors in C2R
URL: https://github.com/apache/datafusion-comet/pull/838
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org