-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-26147][SQL] only pull out unevaluable python udf from join condition #23153
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
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -155,19 +155,20 @@ object EliminateOuterJoin extends Rule[LogicalPlan] with PredicateHelper { | |
| } | ||
|
|
||
| /** | ||
| * PythonUDF in join condition can not be evaluated, this rule will detect the PythonUDF | ||
| * and pull them out from join condition. For python udf accessing attributes from only one side, | ||
| * they are pushed down by operation push down rules. If not (e.g. user disables filter push | ||
| * down rules), we need to pull them out in this rule too. | ||
| * PythonUDF in join condition can't be evaluated if it refers to attributes from both join sides. | ||
| * See `ExtractPythonUDFs` for details. This rule will detect un-evaluable PythonUDF and pull them | ||
| * out from join condition. | ||
| */ | ||
| object PullOutPythonUDFInJoinCondition extends Rule[LogicalPlan] with PredicateHelper { | ||
| def hasPythonUDF(expression: Expression): Boolean = { | ||
| expression.collectFirst { case udf: PythonUDF => udf }.isDefined | ||
|
|
||
| private def hasUnevaluablePythonUDF(expr: Expression, j: Join): Boolean = { | ||
| expr.find { e => | ||
| PythonUDF.isScalarPythonUDF(e) && !canEvaluate(e, j.left) && !canEvaluate(e, j.right) | ||
| }.isDefined | ||
| } | ||
|
|
||
| override def apply(plan: LogicalPlan): LogicalPlan = plan transformUp { | ||
| case j @ Join(_, _, joinType, condition) | ||
| if condition.isDefined && hasPythonUDF(condition.get) => | ||
| case j @ Join(_, _, joinType, Some(cond)) if hasUnevaluablePythonUDF(cond, j) => | ||
|
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. Followed by the rule changes, we need modify the suites in |
||
| if (!joinType.isInstanceOf[InnerLike] && joinType != LeftSemi) { | ||
| // The current strategy only support InnerLike and LeftSemi join because for other type, | ||
| // it breaks SQL semantic if we run the join condition as a filter after join. If we pass | ||
|
|
@@ -179,10 +180,9 @@ object PullOutPythonUDFInJoinCondition extends Rule[LogicalPlan] with PredicateH | |
| } | ||
| // If condition expression contains python udf, it will be moved out from | ||
| // the new join conditions. | ||
| val (udf, rest) = | ||
| splitConjunctivePredicates(condition.get).partition(hasPythonUDF) | ||
| val (udf, rest) = splitConjunctivePredicates(cond).partition(hasUnevaluablePythonUDF(_, j)) | ||
| val newCondition = if (rest.isEmpty) { | ||
| logWarning(s"The join condition:$condition of the join plan contains PythonUDF only," + | ||
| logWarning(s"The join condition:$cond of the join plan contains PythonUDF only," + | ||
| s" it will be moved out and the join plan will be turned to cross join.") | ||
| None | ||
| } else { | ||
|
|
||
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
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.
We might need a comment to explain why we only pull out the Scalar
PythonUDF.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.
It's only possible to have scalar UDF in join condition, so changing it to
e.isInstanceOf[PythonUDF]is same.