GitHub user chenghao-intel opened a pull request:

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

    [SPARK-6212][SQL] Fix bug of explain CTAS

    As we assume the `CreateTableAsSelect` is the leaf node, so it breaks the 
transformation rules applied recursively, while we do the `explain` command.
    
    To execute the explain for CTAS like:
    ```sql
    explain extended create table temp__b as select key, 1+4 from src limit 2;
    ```
    
    W/o this PR:
    ```
    == Parsed Logical Plan ==
    'CreateTableAsSelect 
HiveTable(None,temp__b,List(),List(),Map(),Map(),ManagedTable,None,Some(org.apache.hadoop.mapred.TextInputFormat),Some(org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat),None,None),
 false
     'Limit 2
      'Project [unresolvedalias('key),unresolvedalias((1 + 4))]
       'UnresolvedRelation [src], None
    
    == Analyzed Logical Plan ==
    
    CreateTableAsSelect [Database:default, TableName: temp__b, 
InsertIntoHiveTable]
    Limit 2
     Project [key#1,(1 + 4) AS _c1#3]
      MetastoreRelation default, src, None
    
    == Optimized Logical Plan ==
    CreateTableAsSelect [Database:default, TableName: temp__b, 
InsertIntoHiveTable]
    Limit 2
     Project [key#1,(1 + 4) AS _c1#3]
      MetastoreRelation default, src, None
    
    == Physical Plan ==
    ExecutedCommand (CreateTableAsSelect [Database:default, TableName: temp__b, 
InsertIntoHiveTable]
    Limit 2
     Project [key#1,(1 + 4) AS _c1#3]
      MetastoreRelation default, src, None)
    
    Code Generation: true
    == RDD ==
    ```
    
    W/ this PR:
    ```
    == Parsed Logical Plan ==
    'CreateTableAsSelect 
HiveTable(None,temp__b,List(),List(),Map(),Map(),ManagedTable,None,Some(org.apache.hadoop.mapred.TextInputFormat),Some(org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat),None,None),
 false
     'Limit 2
      'Project [unresolvedalias('key),unresolvedalias((1 + 4))]
       'UnresolvedRelation [src], None
    
    == Analyzed Logical Plan ==
    
    CreateTableAsSelect [AllowExisting: false, HiveTable: 
HiveTable(Some(default),temp__b,List(),List(),Map(),Map(),ManagedTable,None,Some(org.apache.hadoop.mapred.TextInputFormat),Some(org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat),Some(org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe),None)]
     Limit 2
      Project [key#1,(1 + 4) AS _c1#3]
       MetastoreRelation default, src, None
    
    == Optimized Logical Plan ==
    CreateTableAsSelect [AllowExisting: false, HiveTable: 
HiveTable(Some(default),temp__b,List(),List(),Map(),Map(),ManagedTable,None,Some(org.apache.hadoop.mapred.TextInputFormat),Some(org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat),Some(org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe),None)]
     Limit 2
      Project [key#1,5 AS _c1#3]
       MetastoreRelation default, src, None
    
    == Physical Plan ==
    ExecutedCommand [cmd:CreateTableAsSelect [AllowExisting: false, HiveTable: 
HiveTable(Some(default),temp__b,List(),List(),Map(),Map(),ManagedTable,None,Some(org.apache.hadoop.mapred.TextInputFormat),Some(org.apache.hadoop.hive.ql.io.IgnoreKeyTextOutputFormat),Some(org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe),None)]
     Limit 2
      Project [key#1,5 AS _c1#3]
       MetastoreRelation default, src, None
    ]
    
    Code Generation: true
    == RDD ==
    ```

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

    $ git pull https://github.com/chenghao-intel/spark SPARK-6212

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

    https://github.com/apache/spark/pull/7980.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 #7980
    
----
commit f6961e59c2975dff2ca6fc9cab9bcd175113639f
Author: Cheng Hao <[email protected]>
Date:   2015-08-05T14:45:06Z

    fix bug of explain CTAS

----


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