[GitHub] spark pull request #16581: [SPARK-18589] [SQL] Fix Python UDF accessing attr...

2017-01-20 Thread asfgit
Github user asfgit closed the pull request at:

https://github.com/apache/spark/pull/16581


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request #16581: [SPARK-18589] [SQL] Fix Python UDF accessing attr...

2017-01-17 Thread davies
Github user davies commented on a diff in the pull request:

https://github.com/apache/spark/pull/16581#discussion_r96469102
  
--- Diff: python/pyspark/sql/tests.py ---
@@ -342,6 +342,15 @@ 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):
--- End diff --

done


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request #16581: [SPARK-18589] [SQL] Fix Python UDF accessing attr...

2017-01-14 Thread hvanhovell
Github user hvanhovell commented on a diff in the pull request:

https://github.com/apache/spark/pull/16581#discussion_r96121284
  
--- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/predicates.scala
 ---
@@ -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
--- End diff --

`Unevaluable` is not evaluable. This block tries to find a case that is not 
evaluable in a join, and then negates it by isEmpty. I have to admit that we 
should document this.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request #16581: [SPARK-18589] [SQL] Fix Python UDF accessing attr...

2017-01-13 Thread rxin
Github user rxin commented on a diff in the pull request:

https://github.com/apache/spark/pull/16581#discussion_r9630
  
--- Diff: python/pyspark/sql/tests.py ---
@@ -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):
--- End diff --

should reference jira number


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request #16581: [SPARK-18589] [SQL] Fix Python UDF accessing attr...

2017-01-13 Thread rxin
Github user rxin commented on a diff in the pull request:

https://github.com/apache/spark/pull/16581#discussion_r9624
  
--- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/predicates.scala
 ---
@@ -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
--- End diff --

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.



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] spark pull request #16581: [SPARK-18589] [SQL] Fix Python UDF accessing attr...

2017-01-13 Thread davies
GitHub user davies opened a pull request:

https://github.com/apache/spark/pull/16581

[SPARK-18589] [SQL] Fix Python UDF accessing attributes from both side of 
join

## What changes were proposed in this pull request?

PythonUDF is unevaluable, which can not be used inside a join condition, 
currently the optimizer will push a PythonUDF which accessing both side of join 
into the join condition, then the query will fail to plan.

This PR fix this issue by checking the expression is evaluable  or not 
before pushing it into Join.

## How was this patch tested?

Add a regression test.


You can merge this pull request into a Git repository by running:

$ git pull https://github.com/davies/spark pyudf_join

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/spark/pull/16581.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #16581


commit 95d73fcf911bfb25b20fea798d1f7b3f4b319e26
Author: Davies Liu 
Date:   2017-01-13T19:50:11Z

Fix Python UDF accessing attributes from both side of join




---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org