-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-35378][SQL] Eagerly execute commands in QueryExecution instead of caller sides #32513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
dad709c
0338a23
40cea6b
a82ed76
bf296fb
babe0d0
803a12a
4c9b3cf
e3b8454
6516cc4
ddbb5bb
bde1062
7a7bc55
2ad5391
33f0297
309fb0f
8e9277d
d006b2a
fc3afe3
fde3c31
b58c0ea
4dcc759
f47dda6
2a61f23
cd7d39c
6c74474
26c2341
d11b00d
a61c267
8fe6c06
b20b000
b60e04e
94ba930
0ed9485
911e081
ecfe9ba
cfeadd1
6a80674
c81b082
ee1e84a
9c95570
219abb4
f39f920
1d10b61
2bcdddd
5d9f7ee
6011bbe
0905d84
3f6cb85
1d821e0
ddbc5c4
d545d9b
4b730d4
de55034
1a3ce51
ccf8ba3
35ea747
2b2caf7
1db52b9
83d2710
8054799
d15e166
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| /* | ||
| * 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.execution | ||
|
|
||
| import org.apache.spark.rdd.RDD | ||
| import org.apache.spark.sql.catalyst.InternalRow | ||
| import org.apache.spark.sql.catalyst.expressions.{Attribute, UnsafeProjection} | ||
| import org.apache.spark.sql.catalyst.plans.QueryPlan | ||
| import org.apache.spark.sql.execution.metric.SQLMetrics | ||
|
|
||
| /** | ||
| * Physical plan node for holding data from a command. | ||
| * | ||
| * `commandPhysicalPlan` is just used to display the plan tree for EXPLAIN. | ||
| * `rows` may not be serializable and ideally we should not send `rows` to the executors. | ||
| * Thus marking them as transient. | ||
| */ | ||
| case class CommandResultExec( | ||
| output: Seq[Attribute], | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. override def output: Seq[Attribute] = commandPhysicalPlan.output?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because we obtain the output in |
||
| @transient commandPhysicalPlan: SparkPlan, | ||
| @transient rows: Seq[InternalRow]) extends LeafExecNode with InputRDDCodegen { | ||
|
|
||
| override lazy val metrics = Map( | ||
| "numOutputRows" -> SQLMetrics.createMetric(sparkContext, "number of output rows")) | ||
|
|
||
| override def innerChildren: Seq[QueryPlan[_]] = Seq(commandPhysicalPlan) | ||
|
|
||
| @transient private lazy val unsafeRows: Array[InternalRow] = { | ||
cloud-fan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (rows.isEmpty) { | ||
| Array.empty | ||
| } else { | ||
| val proj = UnsafeProjection.create(output, output) | ||
| rows.map(r => proj(r).copy()).toArray | ||
| } | ||
| } | ||
|
|
||
| @transient private lazy val rdd: RDD[InternalRow] = { | ||
| if (rows.isEmpty) { | ||
| sqlContext.sparkContext.emptyRDD | ||
| } else { | ||
| val numSlices = math.min( | ||
| unsafeRows.length, sqlContext.sparkSession.leafNodeDefaultParallelism) | ||
| sqlContext.sparkContext.parallelize(unsafeRows, numSlices) | ||
| } | ||
| } | ||
|
|
||
| override def doExecute(): RDD[InternalRow] = { | ||
| val numOutputRows = longMetric("numOutputRows") | ||
| rdd.map { r => | ||
| numOutputRows += 1 | ||
| r | ||
| } | ||
| } | ||
|
|
||
| override protected def stringArgs: Iterator[Any] = { | ||
| if (unsafeRows.isEmpty) { | ||
| Iterator("<empty>", output) | ||
| } else { | ||
| Iterator(output) | ||
| } | ||
| } | ||
|
|
||
| override def executeCollect(): Array[InternalRow] = { | ||
| longMetric("numOutputRows").add(rows.size) | ||
| rows.toArray | ||
| } | ||
|
|
||
| override def executeTake(limit: Int): Array[InternalRow] = { | ||
| val taken = unsafeRows.take(limit) | ||
| longMetric("numOutputRows").add(taken.size) | ||
| taken | ||
| } | ||
|
|
||
| override def executeTail(limit: Int): Array[InternalRow] = { | ||
| val taken: Seq[InternalRow] = unsafeRows.takeRight(limit) | ||
| longMetric("numOutputRows").add(taken.size) | ||
| taken.toArray | ||
| } | ||
|
|
||
| // Input is already UnsafeRows. | ||
| override protected val createUnsafeProjection: Boolean = false | ||
|
|
||
| override def inputRDD: RDD[InternalRow] = rdd | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.