-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-28213][SQL][followup] code cleanup and bug fix for columnar execution framework #25264
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
867d94a
code cleanup for columnar execution framework
cloud-fan 009d760
add back numOutputRows metrics
cloud-fan ec2a2b8
address comments
cloud-fan 6bcbcc6
fix test
cloud-fan af177aa
address comments
cloud-fan 308fc11
address comments
cloud-fan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,6 @@ | |
|
|
||
| package org.apache.spark.sql.execution | ||
|
|
||
| import java.io.Writer | ||
| import java.util.Locale | ||
| import java.util.concurrent.atomic.AtomicInteger | ||
|
|
||
|
|
@@ -491,12 +490,8 @@ trait InputRDDCodegen extends CodegenSupport { | |
| * | ||
| * This is the leaf node of a tree with WholeStageCodegen that is used to generate code | ||
| * that consumes an RDD iterator of InternalRow. | ||
| * | ||
| * @param isChildColumnar true if the inputRDD is really columnar data hidden by type erasure, | ||
| * false if inputRDD is really an RDD[InternalRow] | ||
| */ | ||
| case class InputAdapter(child: SparkPlan, isChildColumnar: Boolean) | ||
| extends UnaryExecNode with InputRDDCodegen { | ||
| case class InputAdapter(child: SparkPlan) extends UnaryExecNode with InputRDDCodegen { | ||
|
|
||
| override def output: Seq[Attribute] = child.output | ||
|
|
||
|
|
@@ -522,13 +517,10 @@ case class InputAdapter(child: SparkPlan, isChildColumnar: Boolean) | |
| child.executeColumnar() | ||
|
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 inputRDD: RDD[InternalRow] = { | ||
| if (isChildColumnar) { | ||
| child.executeColumnar().asInstanceOf[RDD[InternalRow]] // Hack because of type erasure | ||
| } else { | ||
| child.execute() | ||
| } | ||
| } | ||
| // `InputAdapter` can only generate code to process the rows from its child. If the child produces | ||
| // columnar batches, there must be a `ColumnarToRowExec` above `InputAdapter` to handle it by | ||
| // overriding `inputRDDs` and calling `InputAdapter#executeColumnar` directly. | ||
| override def inputRDD: RDD[InternalRow] = child.execute() | ||
|
|
||
| // This is a leaf node so the node can produce limit not reached checks. | ||
| override protected def canCheckLimitNotReached: Boolean = true | ||
|
|
@@ -870,59 +862,45 @@ case class CollapseCodegenStages( | |
| /** | ||
| * Inserts an InputAdapter on top of those that do not support codegen. | ||
| */ | ||
| private def insertInputAdapter(plan: SparkPlan, isColumnarInput: Boolean): SparkPlan = { | ||
| val isColumnar = adjustColumnar(plan, isColumnarInput) | ||
| private def insertInputAdapter(plan: SparkPlan): SparkPlan = { | ||
| plan match { | ||
| case p if !supportCodegen(p) => | ||
| // collapse them recursively | ||
| InputAdapter(insertWholeStageCodegen(p, isColumnar), isColumnar) | ||
| InputAdapter(insertWholeStageCodegen(p)) | ||
| case j: SortMergeJoinExec => | ||
| // The children of SortMergeJoin should do codegen separately. | ||
| j.withNewChildren(j.children.map( | ||
| child => InputAdapter(insertWholeStageCodegen(child, isColumnar), isColumnar))) | ||
| case p => | ||
| p.withNewChildren(p.children.map(insertInputAdapter(_, isColumnar))) | ||
| child => InputAdapter(insertWholeStageCodegen(child)))) | ||
| case p => p.withNewChildren(p.children.map(insertInputAdapter)) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Inserts a WholeStageCodegen on top of those that support codegen. | ||
| */ | ||
| private def insertWholeStageCodegen(plan: SparkPlan, isColumnarInput: Boolean): SparkPlan = { | ||
| val isColumnar = adjustColumnar(plan, isColumnarInput) | ||
| private def insertWholeStageCodegen(plan: SparkPlan): SparkPlan = { | ||
| plan match { | ||
| // For operators that will output domain object, do not insert WholeStageCodegen for it as | ||
| // domain object can not be written into unsafe row. | ||
| case plan if plan.output.length == 1 && plan.output.head.dataType.isInstanceOf[ObjectType] => | ||
| plan.withNewChildren(plan.children.map(insertWholeStageCodegen(_, isColumnar))) | ||
| plan.withNewChildren(plan.children.map(insertWholeStageCodegen)) | ||
| case plan: LocalTableScanExec => | ||
| // Do not make LogicalTableScanExec the root of WholeStageCodegen | ||
| // to support the fast driver-local collect/take paths. | ||
| plan | ||
| case plan: CodegenSupport if supportCodegen(plan) => | ||
| WholeStageCodegenExec( | ||
| insertInputAdapter(plan, isColumnar))(codegenStageCounter.incrementAndGet()) | ||
| // The whole-stage-codegen framework is row-based. If a plan supports columnar execution, | ||
| // it can't support whole-stage-codegen at the same time. | ||
| assert(!plan.supportsColumnar) | ||
| WholeStageCodegenExec(insertInputAdapter(plan))(codegenStageCounter.incrementAndGet()) | ||
| case other => | ||
| other.withNewChildren(other.children.map(insertWholeStageCodegen(_, isColumnar))) | ||
| other.withNewChildren(other.children.map(insertWholeStageCodegen)) | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Depending on the stage in the plan and if we currently are columnar or not | ||
| * return if we are still columnar or not. | ||
| */ | ||
| private def adjustColumnar(plan: SparkPlan, isColumnar: Boolean): Boolean = | ||
| // We are walking up the plan, so columnar starts when we transition to rows | ||
| // and ends when we transition to columns | ||
| plan match { | ||
| case c2r: ColumnarToRowExec => true | ||
| case r2c: RowToColumnarExec => false | ||
| case _ => isColumnar | ||
| } | ||
|
|
||
| def apply(plan: SparkPlan): SparkPlan = { | ||
| if (conf.wholeStageEnabled) { | ||
| insertWholeStageCodegen(plan, false) | ||
| insertWholeStageCodegen(plan) | ||
| } else { | ||
| plan | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1