-
Notifications
You must be signed in to change notification settings - Fork 28.4k
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-18589] [SQL] Fix Python UDF accessing attributes from both side of join #16581
Changes from 2 commits
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 |
---|---|---|
|
@@ -342,6 +342,14 @@ def test_udf_in_filter_on_top_of_outer_join(self): | |
df = df.withColumn('b', udf(lambda x: 'x')(df.a)) | ||
self.assertEqual(df.filter('b = "x"').collect(), [Row(a=1, b='x')]) | ||
|
||
def test_udf_in_filter_on_top_of_join(self): | ||
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. done |
||
from pyspark.sql.functions import udf | ||
left = self.spark.createDataFrame([Row(a=1)]) | ||
right = self.spark.createDataFrame([Row(b=1)]) | ||
f = udf(lambda a, b: a == b, BooleanType()) | ||
df = left.crossJoin(right).filter(f("a", "b")) | ||
self.assertEqual(df.collect(), [Row(a=1, b=1)]) | ||
|
||
def test_udf_without_arguments(self): | ||
self.spark.catalog.registerFunction("foo", lambda: "bar") | ||
[row] = self.spark.sql("SELECT foo()").collect() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,19 @@ trait PredicateHelper { | |
*/ | ||
protected def canEvaluate(expr: Expression, plan: LogicalPlan): Boolean = | ||
expr.references.subsetOf(plan.outputSet) | ||
|
||
/** | ||
* Returns true iff `expr` could be evaluated as a condition within join. | ||
*/ | ||
protected def canEvaluateWithinJoin(expr: Expression): Boolean = { | ||
expr.find { | ||
case e: SubqueryExpression => | ||
// non-correlated subquery will be replaced as literal | ||
e.children.nonEmpty | ||
case e: Unevaluable => true | ||
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. we need more documentation here on why should be considered evaluable as a join condition. for example, just looking at this code i have no idea why Uneavaluable is evaluable. 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.
|
||
case _ => false | ||
}.isEmpty | ||
} | ||
} | ||
|
||
@ExpressionDescription( | ||
|
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.
should reference jira number