Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/12362#discussion_r59677375
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala ---
    @@ -17,9 +17,45 @@
     
     package org.apache.spark.sql.execution.command
     
    -import org.apache.spark.sql.{Row, SQLContext}
    +import org.apache.spark.sql.{AnalysisException, Row, SQLContext}
     import org.apache.spark.sql.catalyst.TableIdentifier
    -import org.apache.spark.sql.catalyst.catalog.CatalogTable
    +import org.apache.spark.sql.catalyst.catalog.{CatalogTable, 
CatalogTableType}
    +
    +/**
    + * A command to create a table with the same definition of the given 
existing table.
    + *
    + * The syntax of using this command in SQL is:
    + * {{{
    + *   CREATE TABLE [IF NOT EXISTS] [db_name.]table_name
    + *   LIKE [other_db_name.]existing_table_name
    + * }}}
    + */
    +case class CreateTableLike(
    +    targetTable: TableIdentifier,
    +    sourceTable: TableIdentifier,
    +    ifNotExists: Boolean) extends RunnableCommand {
    +
    +  override def run(sqlContext: SQLContext): Seq[Row] = {
    +    val catalog = sqlContext.sessionState.catalog
    +    if (!catalog.tableExists(sourceTable)) {
    +      throw new AnalysisException(
    +        s"Source table in CREATE TABLE LIKE does not exist: 
'$sourceTable'")
    +    }
    +    if (catalog.isTemporaryTable(sourceTable)) {
    +      throw new AnalysisException(
    +        s"Source table in CREATE TABLE LIKE cannot be temporary: 
'$sourceTable'")
    +    }
    +
    +    val tableToCreate = catalog.getTableMetadata(sourceTable).copy(
    --- End diff --
    
    instead of doing a copy and change some variables that we need to update, 
how about we create a new `CatalogTable` and put the stuff that we need to 
retain from the source table? Then it's more clear that what we retained for 
the `CREATE TABLE LIKE` command.


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