You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by ueshin <gi...@git.apache.org> on 2016/05/13 09:01:22 UTC

[GitHub] spark pull request: [SPARK-15313][SQL] EmbedSerializerInFilter rul...

GitHub user ueshin opened a pull request:

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

    [SPARK-15313][SQL] EmbedSerializerInFilter rule should keep exprIds of output of surrounded SerializeFromObject.

    ## What changes were proposed in this pull request?
    
    The following code:
    
    ```
    val ds = Seq(("a", 1), ("b", 2), ("c", 3)).toDS()
    ds.filter(_._1 == "b").select(expr("_1").as[String]).foreach(println(_))
    ```
    
    throws an Exception:
    
    ```
    org.apache.spark.sql.catalyst.errors.package$TreeNodeException: Binding attribute, tree: _1#420
     at org.apache.spark.sql.catalyst.errors.package$.attachTree(package.scala:50)
     at org.apache.spark.sql.catalyst.expressions.BindReferences$$anonfun$bindReference$1.applyOrElse(BoundAttribute.scala:88)
     at org.apache.spark.sql.catalyst.expressions.BindReferences$$anonfun$bindReference$1.applyOrElse(BoundAttribute.scala:87)
    
    ...
     Cause: java.lang.RuntimeException: Couldn't find _1#420 in [_1#416,_2#417]
     at scala.sys.package$.error(package.scala:27)
     at org.apache.spark.sql.catalyst.expressions.BindReferences$$anonfun$bindReference$1$$anonfun$applyOrElse$1.apply(BoundAttribute.scala:94)
     at org.apache.spark.sql.catalyst.expressions.BindReferences$$anonfun$bindReference$1$$anonfun$applyOrElse$1.apply(BoundAttribute.scala:88)
     at org.apache.spark.sql.catalyst.errors.package$.attachTree(package.scala:49)
     at org.apache.spark.sql.catalyst.expressions.BindReferences$$anonfun$bindReference$1.applyOrElse(BoundAttribute.scala:88)
     at org.apache.spark.sql.catalyst.expressions.BindReferences$$anonfun$bindReference$1.applyOrElse(BoundAttribute.scala:87)
    ...
    ```
    
    This is because `EmbedSerializerInFilter` rule drops the `exprId`s of output of surrounded `SerializeFromObject`.
    
    The analyzed and optimized plans of the above example are as follows:
    
    ```
    == Analyzed Logical Plan ==
    _1: string
    Project [_1#420]
    +- SerializeFromObject [staticinvoke(class org.apache.spark.unsafe.types.UTF8String, StringType, fromString, input[0, scala.Tuple2]._1, true) AS _1#420,input[0, scala.Tuple2]._2 AS _2#421]
       +- Filter <function1>.apply
          +- DeserializeToObject newInstance(class scala.Tuple2), obj#419: scala.Tuple2
             +- LocalRelation [_1#416,_2#417], [[0,1800000001,1,61],[0,1800000001,2,62],[0,1800000001,3,63]]
    
    == Optimized Logical Plan ==
    !Project [_1#420]
    +- Filter <function1>.apply
       +- LocalRelation [_1#416,_2#417], [[0,1800000001,1,61],[0,1800000001,2,62],[0,1800000001,3,63]]
    ```
    
    This PR fixes `EmbedSerializerInFilter` rule to keep `exprId`s of output of surrounded `SerializeFromObject`.
    
    The plans after this patch are as follows:
    
    ```
    == Analyzed Logical Plan ==
    _1: string
    Project [_1#420]
    +- SerializeFromObject [staticinvoke(class org.apache.spark.unsafe.types.UTF8String, StringType, fromString, input[0, scala.Tuple2]._1, true) AS _1#420,input[0, scala.Tuple2]._2 AS _2#421]
       +- Filter <function1>.apply
          +- DeserializeToObject newInstance(class scala.Tuple2), obj#419: scala.Tuple2
             +- LocalRelation [_1#416,_2#417], [[0,1800000001,1,61],[0,1800000001,2,62],[0,1800000001,3,63]]
    
    == Optimized Logical Plan ==
    Project [_1#416]
    +- Filter <function1>.apply
       +- LocalRelation [_1#416,_2#417], [[0,1800000001,1,61],[0,1800000001,2,62],[0,1800000001,3,63]]
    ```
    
    ## How was this patch tested?
    
    Existing tests and I added a test to check if `filter and then select` works.


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

    $ git pull https://github.com/ueshin/apache-spark issues/SPARK-15313

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

    https://github.com/apache/spark/pull/13096.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 #13096
    
----
commit 59085d3862522265246d0e80992f4fb031a98c79
Author: Takuya UESHIN <ue...@happy-camper.st>
Date:   2016-05-13T08:25:35Z

    Add a test to check if filter and then select works.

commit 2620409239e808578dbbd9e0099d32f041879f8e
Author: Takuya UESHIN <ue...@happy-camper.st>
Date:   2016-05-13T08:39:26Z

    Fix EmbedSerializerInFilter rule to keep exprIds of output of surrounded SerializeFromObject.

----


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request: [SPARK-15313][SQL] EmbedSerializerInFilter rul...

Posted by rxin <gi...@git.apache.org>.
Github user rxin commented on the pull request:

    https://github.com/apache/spark/pull/13096#issuecomment-220516852
  
    Can you add the jira ticket somewhere as inline comment in the test case and in the analyzer code?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request: [SPARK-15313][SQL] EmbedSerializerInFilter rul...

Posted by rxin <gi...@git.apache.org>.
Github user rxin commented on the pull request:

    https://github.com/apache/spark/pull/13096#issuecomment-220519361
  
    cc @cloud-fan 


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request: [SPARK-15313][SQL] EmbedSerializerInFilter rul...

Posted by HyukjinKwon <gi...@git.apache.org>.
Github user HyukjinKwon commented on a diff in the pull request:

    https://github.com/apache/spark/pull/13096#discussion_r63152997
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala ---
    @@ -1560,7 +1561,15 @@ object EmbedSerializerInFilter extends Rule[LogicalPlan] {
             val newCondition = condition transform {
               case a: Attribute if a == d.output.head => d.deserializer
             }
    -        Filter(newCondition, d.child)
    +        val filter = Filter(newCondition, d.child)
    +
    +        // Adds an extra Project here, to preserve the output expr id of `SerializeFromObject`.
    +        // We will remove it later in RemoveAliasOnlyProject rule.
    +        val objAttrs = filter.output.zip(s.output).map {
    +          case (fout, sout) =>
    +            Alias(fout, fout.name)(exprId = sout.exprId)
    --- End diff --
    
    (it seems putting the case in the same line is preferred (`foreach { case (name, _) =>`) [scala-style-guide#pattern-matching](https://github.com/databricks/scala-style-guide#pattern-matching))


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request: [SPARK-15313][SQL] EmbedSerializerInFilter rul...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/13096#issuecomment-218992912
  
    **[Test build #58555 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/58555/consoleFull)** for PR 13096 at commit [`da35c7e`](https://github.com/apache/spark/commit/da35c7eb38ed10cff4c657d5d68bf2d78d4e2e1b).


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request: [SPARK-15313][SQL] EmbedSerializerInFilter rul...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/13096#issuecomment-219007314
  
    **[Test build #58553 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/58553/consoleFull)** for PR 13096 at commit [`2620409`](https://github.com/apache/spark/commit/2620409239e808578dbbd9e0099d32f041879f8e).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request: [SPARK-15313][SQL] EmbedSerializerInFilter rul...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/13096#discussion_r63992991
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala ---
    @@ -1560,7 +1561,14 @@ object EmbedSerializerInFilter extends Rule[LogicalPlan] {
             val newCondition = condition transform {
               case a: Attribute if a == d.output.head => d.deserializer
             }
    -        Filter(newCondition, d.child)
    +        val filter = Filter(newCondition, d.child)
    +
    +        // Adds an extra Project here, to preserve the output expr id of `SerializeFromObject`.
    +        // We will remove it later in RemoveAliasOnlyProject rule.
    +        val objAttrs = filter.output.zip(s.output).map { case (fout, sout) =>
    --- End diff --
    
    I'd say it's not object attributes, maybe we should just name it `attrs`


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request: [SPARK-15313][SQL] EmbedSerializerInFilter rul...

Posted by HyukjinKwon <gi...@git.apache.org>.
Github user HyukjinKwon commented on a diff in the pull request:

    https://github.com/apache/spark/pull/13096#discussion_r63153328
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala ---
    @@ -1560,7 +1561,15 @@ object EmbedSerializerInFilter extends Rule[LogicalPlan] {
             val newCondition = condition transform {
               case a: Attribute if a == d.output.head => d.deserializer
             }
    -        Filter(newCondition, d.child)
    +        val filter = Filter(newCondition, d.child)
    +
    +        // Adds an extra Project here, to preserve the output expr id of `SerializeFromObject`.
    +        // We will remove it later in RemoveAliasOnlyProject rule.
    +        val objAttrs = filter.output.zip(s.output).map {
    +          case (fout, sout) =>
    --- End diff --
    
    (it seems putting the case in the same line is preferred (`map { case (fout, sout) =>`) [scala-style-guide#pattern-matching](https://github.com/databricks/scala-style-guide#pattern-matching))


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request: [SPARK-15313][SQL] EmbedSerializerInFilter rul...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the pull request:

    https://github.com/apache/spark/pull/13096#issuecomment-220521107
  
    LGTM, thanks for finding this bug!


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request: [SPARK-15313][SQL] EmbedSerializerInFilter rul...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/13096#issuecomment-219010208
  
    Merged build finished. Test PASSed.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request: [SPARK-15313][SQL] EmbedSerializerInFilter rul...

Posted by rxin <gi...@git.apache.org>.
Github user rxin commented on the pull request:

    https://github.com/apache/spark/pull/13096#issuecomment-220523585
  
    Alright I'm going to merge this in master/2.0. Thanks.



---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request: [SPARK-15313][SQL] EmbedSerializerInFilter rul...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/13096#issuecomment-219007546
  
    Merged build finished. Test PASSed.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request: [SPARK-15313][SQL] EmbedSerializerInFilter rul...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/13096#issuecomment-219007550
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/58553/
    Test PASSed.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request: [SPARK-15313][SQL] EmbedSerializerInFilter rul...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the pull request:

    https://github.com/apache/spark/pull/13096#issuecomment-219010209
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/58555/
    Test PASSed.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request: [SPARK-15313][SQL] EmbedSerializerInFilter rul...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/13096#issuecomment-219010063
  
    **[Test build #58555 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/58555/consoleFull)** for PR 13096 at commit [`da35c7e`](https://github.com/apache/spark/commit/da35c7eb38ed10cff4c657d5d68bf2d78d4e2e1b).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request: [SPARK-15313][SQL] EmbedSerializerInFilter rul...

Posted by ueshin <gi...@git.apache.org>.
Github user ueshin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/13096#discussion_r63153478
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala ---
    @@ -1560,7 +1561,15 @@ object EmbedSerializerInFilter extends Rule[LogicalPlan] {
             val newCondition = condition transform {
               case a: Attribute if a == d.output.head => d.deserializer
             }
    -        Filter(newCondition, d.child)
    +        val filter = Filter(newCondition, d.child)
    +
    +        // Adds an extra Project here, to preserve the output expr id of `SerializeFromObject`.
    +        // We will remove it later in RemoveAliasOnlyProject rule.
    +        val objAttrs = filter.output.zip(s.output).map {
    +          case (fout, sout) =>
    --- End diff --
    
    @HyukjinKwon Thank you, I'll fix it.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request: [SPARK-15313][SQL] EmbedSerializerInFilter rul...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

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


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request: [SPARK-15313][SQL] EmbedSerializerInFilter rul...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the pull request:

    https://github.com/apache/spark/pull/13096#issuecomment-218989593
  
    **[Test build #58553 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/58553/consoleFull)** for PR 13096 at commit [`2620409`](https://github.com/apache/spark/commit/2620409239e808578dbbd9e0099d32f041879f8e).


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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