-
Notifications
You must be signed in to change notification settings - Fork 28.5k
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
[SPARK-23315][SQL] failed to get output from canonicalized data source v2 related plans #20485
Closed
Closed
Changes from all commits
Commits
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 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 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 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 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 |
---|---|---|
|
@@ -81,33 +81,44 @@ object PushDownOperatorsToDataSource extends Rule[LogicalPlan] with PredicateHel | |
|
||
// TODO: add more push down rules. | ||
|
||
pushDownRequiredColumns(filterPushed, filterPushed.outputSet) | ||
val columnPruned = pushDownRequiredColumns(filterPushed, filterPushed.outputSet) | ||
// After column pruning, we may have redundant PROJECT nodes in the query plan, remove them. | ||
RemoveRedundantProject(filterPushed) | ||
RemoveRedundantProject(columnPruned) | ||
} | ||
|
||
// TODO: nested fields pruning | ||
private def pushDownRequiredColumns(plan: LogicalPlan, requiredByParent: AttributeSet): Unit = { | ||
private def pushDownRequiredColumns( | ||
plan: LogicalPlan, requiredByParent: AttributeSet): LogicalPlan = { | ||
plan match { | ||
case Project(projectList, child) => | ||
case p @ Project(projectList, child) => | ||
val required = projectList.flatMap(_.references) | ||
pushDownRequiredColumns(child, AttributeSet(required)) | ||
p.copy(child = pushDownRequiredColumns(child, AttributeSet(required))) | ||
|
||
case Filter(condition, child) => | ||
case f @ Filter(condition, child) => | ||
val required = requiredByParent ++ condition.references | ||
pushDownRequiredColumns(child, required) | ||
f.copy(child = pushDownRequiredColumns(child, required)) | ||
|
||
case relation: DataSourceV2Relation => relation.reader match { | ||
case reader: SupportsPushDownRequiredColumns => | ||
// TODO: Enable the below assert after we make `DataSourceV2Relation` immutable. Fow now | ||
// it's possible that the mutable reader being updated by someone else, and we need to | ||
// always call `reader.pruneColumns` here to correct it. | ||
// assert(relation.output.toStructType == reader.readSchema(), | ||
// "Schema of data source reader does not match the relation plan.") | ||
|
||
val requiredColumns = relation.output.filter(requiredByParent.contains) | ||
reader.pruneColumns(requiredColumns.toStructType) | ||
|
||
case _ => | ||
val nameToAttr = relation.output.map(_.name).zip(relation.output).toMap | ||
val newOutput = reader.readSchema().map(_.name).map(nameToAttr) | ||
relation.copy(output = newOutput) | ||
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. @rdblue This is the bug I mentioned before. Finally I figured out a way to fix it surgically: always run column pruning even no column needs to be pruned. This helps us correct the required schema of the reader, if it's updated by someone else. |
||
|
||
case _ => relation | ||
} | ||
|
||
// TODO: there may be more operators that can be used to calculate the required columns. We | ||
// can add more and more in the future. | ||
case _ => plan.children.foreach(child => pushDownRequiredColumns(child, child.outputSet)) | ||
case _ => plan.mapChildren(c => pushDownRequiredColumns(c, c.outputSet)) | ||
} | ||
} | ||
|
||
|
This file contains 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
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.
Typo: Fow