GitHub user gatorsmile opened a pull request:

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

    [SPARK-18415] [SQL] Weird Plan Output when CTE used in RunnableCommand

    ### What changes were proposed in this pull request?
    Currently, when CTE is used in RunnableCommand, the Analyzer does not 
replace the logical node `With`. The child plan of RunnableCommand is not 
resolved. Thus, the output of the `With` plan node looks very confusing.
    For example,
    ```
    sql("CREATE VIEW cte_view AS WITH w AS (SELECT 1 AS n) SELECT n FROM 
w").explain()
    ```
    The output is like
    ```
    ExecutedCommand
       +- CreateViewCommand `w`, WITH w AS (SELECT 1 AS n) SELECT n FROM w, 
false, false, org.apache.spark.sql.execution.command.PersistedView$@2251b87b
             +- 'With [(w,SubqueryAlias w
                   +- Project [1 AS n#16]
                      +- OneRowRelation$
                   )]
                +- 'Project ['n]
                   +- 'UnresolvedRelation `w`
    ```
    After the fix, the output is as shown below.
    ```
    ExecutedCommand
       +- CreateViewCommand `cte_view`, WITH w AS (SELECT 1 AS n) SELECT n FROM 
w, false, false, PersistedView
             +- CTE [w]
                +- 'Project ['n]
                   +- 'UnresolvedRelation `w`
    ```
    
    ### How was this patch tested?
    Manual

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

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

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

    https://github.com/apache/spark/pull/15854.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 #15854
    
----
commit 1dd5a7f2a4fb41642f0b8500e22384abd7ed1f14
Author: gatorsmile <[email protected]>
Date:   2016-11-11T21:12:27Z

    fix plan.

commit 55a4bff3cf504d3a8ad11e91637d1cc67fd9b111
Author: gatorsmile <[email protected]>
Date:   2016-11-11T21:15:25Z

    fix plan.

----


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to