You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by gatorsmile <gi...@git.apache.org> on 2016/02/08 22:04:42 UTC

[GitHub] spark pull request: [SPARK-13235] [SQL] Removed an Extra Distinct ...

GitHub user gatorsmile opened a pull request:

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

    [SPARK-13235] [SQL] Removed an Extra Distinct from the Plan with Union Distinct

    Currently, the parser added two `Distinct` operators in the plan if we are using `Union Distinct`. This PR is to remove the extra `Distinct` from the plan. 
    
    For example, before the fix, the following query has a plan with two `Distinct`
    ```scala
    sql("select * from t0 union select * from t0").explain(true)
    ```
    ```
    == Parsed Logical Plan ==
    'Project [unresolvedalias(*,None)]
    +- 'Subquery u_2
       +- 'Distinct
          +- 'Project [unresolvedalias(*,None)]
             +- 'Subquery u_1
                +- 'Distinct
                   +- 'Union
                      :- 'Project [unresolvedalias(*,None)]
                      :  +- 'UnresolvedRelation `t0`, None
                      +- 'Project [unresolvedalias(*,None)]
                         +- 'UnresolvedRelation `t0`, None
    
    == Analyzed Logical Plan ==
    id: bigint
    Project [id#16L]
    +- Subquery u_2
       +- Distinct
          +- Project [id#16L]
             +- Subquery u_1
                +- Distinct
                   +- Union
                      :- Project [id#16L]
                      :  +- Subquery t0
                      :     +- Relation[id#16L] ParquetRelation
                      +- Project [id#16L]
                         +- Subquery t0
                            +- Relation[id#16L] ParquetRelation
    
    == Optimized Logical Plan ==
    Aggregate [id#16L], [id#16L]
    +- Aggregate [id#16L], [id#16L]
       +- Union
          :- Project [id#16L]
          :  +- Relation[id#16L] ParquetRelation
          +- Project [id#16L]
             +- Relation[id#16L] ParquetRelation
    ```
    After the fix, the plan is changed without the extra `Distinct` as follows:
    ```
    == Parsed Logical Plan ==
    'Project [unresolvedalias(*,None)]
    +- 'Subquery u_1
       +- 'Distinct
          +- 'Union
             :- 'Project [unresolvedalias('id,None)]
             :  +- 'UnresolvedRelation `t0`, None
             +- 'Project [unresolvedalias(cast('id as int) AS id#16,None)]
                +- 'UnresolvedRelation `t0`, None
    
    == Analyzed Logical Plan ==
    id: bigint
    Project [id#17L]
    +- Subquery u_1
       +- Distinct
          +- Union
             :- Project [id#17L]
             :  +- Project [id#17L]
             :     +- Subquery t0
             :        +- Relation[id#17L] ParquetRelation
             +- Project [cast(id#16 as bigint) AS id#20L]
                +- Project [cast(id#17L as int) AS id#16]
                   +- Subquery t0
                      +- Relation[id#17L] ParquetRelation
    
    == Optimized Logical Plan ==
    Aggregate [id#17L], [id#17L]
    +- Union
       :- Project [id#17L]
       :  +- Relation[id#17L] ParquetRelation
       +- Project [cast(cast(id#17L as int) as bigint) AS id#20L]
          +- Relation[id#17L] ParquetRelation
    ```
    


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

    $ git pull https://github.com/gatorsmile/spark unionDistinct

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

    https://github.com/apache/spark/pull/11120.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 #11120
    
----

----


---
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-13235] [SQL] Removed an Extra Distinct ...

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

    https://github.com/apache/spark/pull/11120#issuecomment-181896060
  
    @hvanhovell @viirya Thank you for your reviews! Just added two test cases for this, as suggested by @hvanhovell 
    
    Yeah. I did check the original Hive JIRA: https://issues.apache.org/jira/browse/HIVE-9039 . The reason their parser added this is that they do not added another `Distinct` above `Union All`. 


---
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-13235] [SQL] Removed an Extra Distinct ...

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

    https://github.com/apache/spark/pull/11120#issuecomment-181608021
  
    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-13235] [SQL] Removed an Extra Distinct ...

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

    https://github.com/apache/spark/pull/11120#issuecomment-182750732
  
    Merging to master. 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-13235] [SQL] Removed an Extra Distinct ...

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

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


---
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-13235] [SQL] Removed an Extra Distinct ...

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

    https://github.com/apache/spark/pull/11120#issuecomment-181616874
  
    This change is on the parser. @hvanhovell Could you please take a look? 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-13235] [SQL] Removed an Extra Distinct ...

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

    https://github.com/apache/spark/pull/11120#discussion_r52303696
  
    --- Diff: sql/catalyst/src/main/antlr3/org/apache/spark/sql/catalyst/parser/SparkSqlParser.g ---
    @@ -2358,34 +2358,8 @@ setOpSelectStatement[CommonTree t, boolean topLevel]
         u=setOperator LPAREN b=simpleSelectStatement RPAREN
         |
         u=setOperator b=simpleSelectStatement)
    -   -> {$setOpSelectStatement.tree != null && $u.tree.getType()==SparkSqlParser.TOK_UNIONDISTINCT}?
    --- End diff --
    
    Yea, this is redundant because originally `TOK_UNIONALL` is used here. So an additional distinct is necessary. As we use `TOK_UNIONDISTINCT` now, we can skip 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-13235] [SQL] Removed an Extra Distinct ...

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

    https://github.com/apache/spark/pull/11120#issuecomment-182068427
  
    LGTM


---
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-13235] [SQL] Removed an Extra Distinct ...

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

    https://github.com/apache/spark/pull/11120#issuecomment-181608024
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/50938/
    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-13235] [SQL] Removed an Extra Distinct ...

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

    https://github.com/apache/spark/pull/11120#issuecomment-182141218
  
    LGTM


---
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-13235] [SQL] Removed an Extra Distinct ...

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

    https://github.com/apache/spark/pull/11120#issuecomment-181897784
  
    **[Test build #50975 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/50975/consoleFull)** for PR 11120 at commit [`a5e81f4`](https://github.com/apache/spark/commit/a5e81f4a66cba12c999f0c2ed903b2c7ddd18247).


---
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-13235] [SQL] Removed an Extra Distinct ...

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

    https://github.com/apache/spark/pull/11120#issuecomment-181933600
  
    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-13235] [SQL] Removed an Extra Distinct ...

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

    https://github.com/apache/spark/pull/11120#issuecomment-181732170
  
    @gatorsmile This looks pretty solid. Could you add a test for this to `CatalystQlSuite`?  I'll have a better look at the grammar change tonight.


---
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-13235] [SQL] Removed an Extra Distinct ...

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

    https://github.com/apache/spark/pull/11120#issuecomment-181572532
  
    **[Test build #50938 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/50938/consoleFull)** for PR 11120 at commit [`2e78d2c`](https://github.com/apache/spark/commit/2e78d2c36a41ed2c29cfaf84fa6837b3095f1d1b).


---
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-13235] [SQL] Removed an Extra Distinct ...

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

    https://github.com/apache/spark/pull/11120#issuecomment-181932934
  
    **[Test build #50975 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/50975/consoleFull)** for PR 11120 at commit [`a5e81f4`](https://github.com/apache/spark/commit/a5e81f4a66cba12c999f0c2ed903b2c7ddd18247).
     * 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-13235] [SQL] Removed an Extra Distinct ...

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

    https://github.com/apache/spark/pull/11120#issuecomment-181933602
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/50975/
    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-13235] [SQL] Removed an Extra Distinct ...

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

    https://github.com/apache/spark/pull/11120#issuecomment-181607440
  
    **[Test build #50938 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/50938/consoleFull)** for PR 11120 at commit [`2e78d2c`](https://github.com/apache/spark/commit/2e78d2c36a41ed2c29cfaf84fa6837b3095f1d1b).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds the following public classes _(experimental)_:
      * `              s\"Unable to generate an encoder for inner class `$`
      * `case class AssertNotNull(child: Expression, walkedTypePath: Seq[String])`
      * `case class ReturnAnswer(child: LogicalPlan) extends UnaryNode `
      * `case class CollectLimit(limit: Int, child: SparkPlan) extends UnaryNode `
      * `trait BaseLimit extends UnaryNode `
      * `case class LocalLimit(limit: Int, child: SparkPlan) extends BaseLimit `
      * `case class GlobalLimit(limit: Int, child: SparkPlan) extends BaseLimit `
      * `case class TakeOrderedAndProject(`


---
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