You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by viirya <gi...@git.apache.org> on 2016/04/13 17:33:24 UTC

[GitHub] spark pull request: [SPARK-14592][SQL] Native support for CREATE T...

GitHub user viirya opened a pull request:

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

    [SPARK-14592][SQL] Native support for CREATE TABLE LIKE DDL command

    ## What changes were proposed in this pull request?
    JIRA: https://issues.apache.org/jira/browse/SPARK-14592
    
    This patch adds native support for DDL command `CREATE TABLE LIKE`.
    
    The SQL syntax is like:
        
        CREATE TABLE table_name LIKE existing_table
        CREATE TABLE IF NOT EXISTS table_name LIKE existing_table
    
    ## How was this patch tested?
    `HiveDDLCommandSuite`.


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

    $ git pull https://github.com/viirya/spark-1 create-table-like

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

    https://github.com/apache/spark/pull/12362.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 #12362
    
----
commit 2a0a4743a0502dc727ff7aaaa0b5ccd3582e2545
Author: Liang-Chi Hsieh <si...@tw.ibm.com>
Date:   2016-04-13T10:45:13Z

    init import.

commit 6525695c4f7edad066a54c1f9dd17c9f4ad918db
Author: Liang-Chi Hsieh <si...@tw.ibm.com>
Date:   2016-04-13T15:17:36Z

    Make it work.

commit 82a3ee864f3a7a6b5f46801e3e49a714e6e03f1e
Author: Liang-Chi Hsieh <si...@tw.ibm.com>
Date:   2016-04-13T15:28:00Z

    Reset storage location.

commit a23559d0df74df30f08615489dbaa67aaa87e097
Author: Liang-Chi Hsieh <si...@tw.ibm.com>
Date:   2016-04-13T15:31:47Z

    Modify comment.

----


---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#discussion_r59761027
  
    --- 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 --
    
    I think things like `lastAccessTime` are exceptions. Otherwise if we add a new field to `CatalogTable` in the future you might forget to copy it here.


---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#issuecomment-209641967
  
    @viirya we just merged a patch that implements `CREATE TABLE`. It would be good if you can rebase. Some of the changes in that patch may be relevant here.


---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#discussion_r59608060
  
    --- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/HiveSqlParser.scala ---
    @@ -203,6 +204,32 @@ class HiveSqlAstBuilder extends SparkSqlAstBuilder {
       }
     
       /**
    +   * Create a [[CreateTableLike]] command.
    +   */
    +  override def visitCreateTableLike(ctx: CreateTableLikeContext): LogicalPlan = withOrigin(ctx) {
    +    // Get the table header.
    +    val (table, temp, ifNotExists, external) = visitCreateTableHeader(ctx.createTableHeader)
    +    val sourceTable = visitTableIdentifier(ctx.source)
    +
    +    val tableType = if (external) {
    +      throw new ParseException("Unsupported operation: EXTERNAL clause.", ctx)
    +    } else {
    --- End diff --
    
    MINOR: Redundant `else`... You can just assign the `tableType` directly.


---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#issuecomment-209721645
  
    Merged build finished. Test FAILed.


---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#discussion_r59622663
  
    --- Diff: sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4 ---
    @@ -55,6 +55,7 @@ statement
             rowFormat?  createFileFormat? locationSpec?
             (TBLPROPERTIES tablePropertyList)?
             (AS? query)?                                                   #createTable
    +    | createTableHeader LIKE source=tableIdentifier                    #createTableLike
    --- End diff --
    
    (For that reason I don't think we should use `createTableHeader` here since it doesn't make sense to say `CREATE TEMPORARY TABLE x LIKE ...`, and we just throw an exception downstream anyway.


---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#discussion_r59622384
  
    --- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/HiveSqlParser.scala ---
    @@ -203,6 +204,32 @@ class HiveSqlAstBuilder extends SparkSqlAstBuilder {
       }
     
       /**
    +   * Create a [[CreateTableLike]] command.
    +   */
    +  override def visitCreateTableLike(ctx: CreateTableLikeContext): LogicalPlan = withOrigin(ctx) {
    +    // Get the table header.
    +    val (table, temp, ifNotExists, external) = visitCreateTableHeader(ctx.createTableHeader)
    +    val sourceTable = visitTableIdentifier(ctx.source)
    +
    +    val tableType = if (external) {
    +      throw new ParseException("Unsupported operation: EXTERNAL clause.", ctx)
    +    } else {
    +      CatalogTableType.MANAGED_TABLE
    +    }
    +
    +    // Unsupported clauses.
    +    if (temp) {
    +      throw new ParseException(s"Unsupported operation: TEMPORARY clause.", ctx)
    +    }
    +    val tableDesc = CatalogTable(
    +      identifier = table,
    +      tableType = tableType,
    +      schema = Seq.empty,
    +      storage = EmptyStorageFormat)
    +    CreateTableLike(tableDesc, ifNotExists, sourceTable)
    --- End diff --
    
    why pass in this incomplete `tableDesc`? We should just pass in `name` and `sourceName`, and call `catalog.getTableMetadata(sourceName)` in the DDL 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 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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#discussion_r59642353
  
    --- Diff: sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4 ---
    @@ -55,6 +55,7 @@ statement
             rowFormat?  createFileFormat? locationSpec?
             (TBLPROPERTIES tablePropertyList)?
             (AS? query)?                                                   #createTable
    +    | createTableHeader LIKE source=tableIdentifier                    #createTableLike
    --- End diff --
    
    yea, I am referring the Hive manual that only lists one syntax `CREATE TABLE x LIKE y`.


---
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-14592][SQL] Native support for CREATE T...

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/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 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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#discussion_r59621133
  
    --- Diff: sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4 ---
    @@ -55,6 +55,7 @@ statement
             rowFormat?  createFileFormat? locationSpec?
             (TBLPROPERTIES tablePropertyList)?
             (AS? query)?                                                   #createTable
    +    | createTableHeader LIKE source=tableIdentifier                    #createTableLike
    --- End diff --
    
    actually, what does it mean to provide table properties or row format in a `CREATE TABLE LIKE` statement? Trying to merge the provided properties with the existing ones seems complicated and full of corner cases. It might be simpler to just handle `CREATE TABLE x LIKE y` instead of accepting more things that we don't know how to handle.


---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#issuecomment-209753335
  
    **[Test build #55783 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/55783/consoleFull)** for PR 12362 at commit [`ec589b8`](https://github.com/apache/spark/commit/ec589b87c68343409d657d1a7c6ed82692a79ac6).
     * 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-14592][SQL] Native support for CREATE T...

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

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


---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#issuecomment-209731260
  
    **[Test build #55783 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/55783/consoleFull)** for PR 12362 at commit [`ec589b8`](https://github.com/apache/spark/commit/ec589b87c68343409d657d1a7c6ed82692a79ac6).


---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#discussion_r59621625
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala ---
    @@ -0,0 +1,66 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.execution.command
    +
    +import org.apache.spark.sql.{AnalysisException, Row, SQLContext}
    +import org.apache.spark.sql.catalyst.TableIdentifier
    +import org.apache.spark.sql.catalyst.catalog.CatalogTable
    +
    +/**
    + * 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(
    +    table: CatalogTable,
    +    ifNotExists: Boolean,
    +    sourceTable: TableIdentifier) extends RunnableCommand {
    +
    +  override def run(sqlContext: SQLContext): Seq[Row] = {
    +    val catalog = sqlContext.sessionState.catalog
    +    if (!catalog.tableExists(sourceTable)) {
    +      throw new AnalysisException(
    +        s"Cannot create table like on not existing table ${sourceTable.identifier}.")
    --- End diff --
    
    I would say: `Source table in CREATE TABLE LIKE does not exist: ${...}`


---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#issuecomment-209515627
  
    **[Test build #55722 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/55722/consoleFull)** for PR 12362 at commit [`a23559d`](https://github.com/apache/spark/commit/a23559d0df74df30f08615489dbaa67aaa87e097).


---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#discussion_r59622497
  
    --- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/HiveSqlParser.scala ---
    @@ -203,6 +204,32 @@ class HiveSqlAstBuilder extends SparkSqlAstBuilder {
       }
     
       /**
    +   * Create a [[CreateTableLike]] command.
    +   */
    +  override def visitCreateTableLike(ctx: CreateTableLikeContext): LogicalPlan = withOrigin(ctx) {
    +    // Get the table header.
    +    val (table, temp, ifNotExists, external) = visitCreateTableHeader(ctx.createTableHeader)
    +    val sourceTable = visitTableIdentifier(ctx.source)
    +
    +    val tableType = if (external) {
    +      throw new ParseException("Unsupported operation: EXTERNAL clause.", ctx)
    +    } else {
    --- End diff --
    
    as I commented elsewhere, extracting table type here is actually not necessary


---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#discussion_r59621802
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala ---
    @@ -0,0 +1,66 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.execution.command
    +
    +import org.apache.spark.sql.{AnalysisException, Row, SQLContext}
    +import org.apache.spark.sql.catalyst.TableIdentifier
    +import org.apache.spark.sql.catalyst.catalog.CatalogTable
    +
    +/**
    + * 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(
    +    table: CatalogTable,
    +    ifNotExists: Boolean,
    +    sourceTable: TableIdentifier) extends RunnableCommand {
    +
    +  override def run(sqlContext: SQLContext): Seq[Row] = {
    +    val catalog = sqlContext.sessionState.catalog
    +    if (!catalog.tableExists(sourceTable)) {
    +      throw new AnalysisException(
    +        s"Cannot create table like on not existing table ${sourceTable.identifier}.")
    +    }
    +    if (catalog.isTemporaryTable(sourceTable)) {
    +      throw new AnalysisException(
    +        s"Cannot create table like on a temporary table ${sourceTable.identifier}.")
    +    }
    +
    +    val sourceTableMetadata = catalog.getTableMetadata(sourceTable)
    +    val tableToCreate = CatalogTable(
    --- End diff --
    
    +1


---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#issuecomment-210080734
  
    Merged into master, thanks for your work!


---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#discussion_r59654481
  
    --- Diff: sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4 ---
    @@ -55,6 +55,7 @@ statement
             rowFormat?  createFileFormat? locationSpec?
             (TBLPROPERTIES tablePropertyList)?
             (AS? query)?                                                   #createTable
    +    | createTableHeader LIKE source=tableIdentifier                    #createTableLike
    --- End diff --
    
    I would say disable it. I don't think it actually merges the table properties (and it would be super confusing if it did)


---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#discussion_r59621513
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala ---
    @@ -0,0 +1,66 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.execution.command
    +
    +import org.apache.spark.sql.{AnalysisException, Row, SQLContext}
    +import org.apache.spark.sql.catalyst.TableIdentifier
    +import org.apache.spark.sql.catalyst.catalog.CatalogTable
    +
    +/**
    + * 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(
    +    table: CatalogTable,
    +    ifNotExists: Boolean,
    +    sourceTable: TableIdentifier) extends RunnableCommand {
    +
    +  override def run(sqlContext: SQLContext): Seq[Row] = {
    +    val catalog = sqlContext.sessionState.catalog
    +    if (!catalog.tableExists(sourceTable)) {
    +      throw new AnalysisException(
    +        s"Cannot create table like on not existing table ${sourceTable.identifier}.")
    +    }
    +    if (catalog.isTemporaryTable(sourceTable)) {
    +      throw new AnalysisException(
    +        s"Cannot create table like on a temporary table ${sourceTable.identifier}.")
    --- End diff --
    
    I would say: `Operation not allowed: CREATE TABLE ... LIKE temp_table`


---
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-14592][SQL] Native support for CREATE T...

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

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


---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#discussion_r59621219
  
    --- Diff: sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4 ---
    @@ -55,6 +55,7 @@ statement
             rowFormat?  createFileFormat? locationSpec?
             (TBLPROPERTIES tablePropertyList)?
             (AS? query)?                                                   #createTable
    +    | createTableHeader LIKE source=tableIdentifier                    #createTableLike
    --- End diff --
    
    e.g. Hive only documents the simple case of `CREATE TABLE x LIKE y` without any other flags or properties
    https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-CreateTableLike


---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#issuecomment-209753421
  
    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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#issuecomment-209704350
  
    @andrewor14 @hvanhovell Thanks. Your comments are addressed. One remaining question is do we want to support the syntax like:
    
        CREATE TABLE test_table LIKE src TBLPROPERTIES('key'='value')
    
    Because in `HiveCompatibilitySuite`, one test `create_like_tbl_props` uses the syntax. If we don't want to support it, we need to disable the test then.
    



---
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-14592][SQL] Native support for CREATE T...

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

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


---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#discussion_r59684652
  
    --- 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 --
    
    Your concern is correct. But I think most fields in source table should be retained. Only few exceptions like `lastAccessTime`.


---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#issuecomment-209822194
  
    LGTM except one comment.


---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#issuecomment-209720029
  
    I would say disable it. I don't think it actually merges the table properties (and it would be super confusing if it did)


---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#issuecomment-209541409
  
    **[Test build #55722 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/55722/consoleFull)** for PR 12362 at commit [`a23559d`](https://github.com/apache/spark/commit/a23559d0df74df30f08615489dbaa67aaa87e097).
     * This patch **fails Spark unit 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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#issuecomment-209753422
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/55783/
    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-14592][SQL] Native support for CREATE T...

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/12362#discussion_r59680990
  
    --- 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 --
    
    My concern is that we may add more fields into `CatalogTable` which we don't want to retain, like `lastAccessTime`, I'm not sure which way is safer too, cc @andrewor14


---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#discussion_r59763836
  
    --- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/HiveSqlParser.scala ---
    @@ -237,6 +237,15 @@ class HiveSqlAstBuilder extends SparkSqlAstBuilder {
       }
     
       /**
    +   * Create a [[CreateTableLike]] command.
    +   */
    +  override def visitCreateTableLike(ctx: CreateTableLikeContext): LogicalPlan = withOrigin(ctx) {
    +    val targetTable = visitTableIdentifier(ctx.target)
    +    val sourceTable = visitTableIdentifier(ctx.source)
    +    CreateTableLike(targetTable, sourceTable, ctx.EXISTS != null)
    --- End diff --
    
    much better!


---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#discussion_r59642497
  
    --- Diff: sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4 ---
    @@ -55,6 +55,7 @@ statement
             rowFormat?  createFileFormat? locationSpec?
             (TBLPROPERTIES tablePropertyList)?
             (AS? query)?                                                   #createTable
    +    | createTableHeader LIKE source=tableIdentifier                    #createTableLike
    --- End diff --
    
    Not sure if we want to support `CREATE TABLE IF NOT EXIST x LIKE y`? It is not on the Hive manual, but `HiveQuerySuite` has tests using this syntax...


---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#issuecomment-209542135
  
    Merged build finished. Test FAILed.


---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#discussion_r59607790
  
    --- Diff: sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4 ---
    @@ -55,6 +55,7 @@ statement
             rowFormat?  createFileFormat? locationSpec?
             (TBLPROPERTIES tablePropertyList)?
             (AS? query)?                                                   #createTable
    +    | createTableHeader LIKE source=tableIdentifier                    #createTableLike
    --- End diff --
    
    Curious why you do not implement the full Hive spec? It seems usefull to be able to change the non-structural properties.


---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#discussion_r59607938
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala ---
    @@ -0,0 +1,66 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.execution.command
    +
    +import org.apache.spark.sql.{AnalysisException, Row, SQLContext}
    +import org.apache.spark.sql.catalyst.TableIdentifier
    +import org.apache.spark.sql.catalyst.catalog.CatalogTable
    +
    +/**
    + * 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(
    +    table: CatalogTable,
    +    ifNotExists: Boolean,
    +    sourceTable: TableIdentifier) extends RunnableCommand {
    +
    +  override def run(sqlContext: SQLContext): Seq[Row] = {
    +    val catalog = sqlContext.sessionState.catalog
    +    if (!catalog.tableExists(sourceTable)) {
    +      throw new AnalysisException(
    +        s"Cannot create table like on not existing table ${sourceTable.identifier}.")
    +    }
    +    if (catalog.isTemporaryTable(sourceTable)) {
    +      throw new AnalysisException(
    +        s"Cannot create table like on a temporary table ${sourceTable.identifier}.")
    +    }
    +
    +    val sourceTableMetadata = catalog.getTableMetadata(sourceTable)
    +    val tableToCreate = CatalogTable(
    --- End diff --
    
    `sourceTableMetadata.copy(identifier = ..., tableType = ...)` is less error prone.


---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#discussion_r59644711
  
    --- Diff: sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4 ---
    @@ -55,6 +55,7 @@ statement
             rowFormat?  createFileFormat? locationSpec?
             (TBLPROPERTIES tablePropertyList)?
             (AS? query)?                                                   #createTable
    +    | createTableHeader LIKE source=tableIdentifier                    #createTableLike
    --- End diff --
    
    I just found that in `HiveCompatibilitySuite`, one test `create_like_tbl_props` uses the syntax:
    
        CREATE TABLE test_table LIKE src TBLPROPERTIES('key'='value')
    
    So do we want to support it? Or just disable this test? @andrewor14 @hvanhovell 



---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#issuecomment-209704224
  
    **[Test build #55771 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/55771/consoleFull)** for PR 12362 at commit [`0bcafcd`](https://github.com/apache/spark/commit/0bcafcd669e7f7b556c1523575c07c113d431c5a).


---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#discussion_r59629224
  
    --- Diff: sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4 ---
    @@ -55,6 +55,7 @@ statement
             rowFormat?  createFileFormat? locationSpec?
             (TBLPROPERTIES tablePropertyList)?
             (AS? query)?                                                   #createTable
    +    | createTableHeader LIKE source=tableIdentifier                    #createTableLike
    --- End diff --
    
    Yeah, just being curious here. The grammar (of course) was much more elaborate in its definition: https://github.com/apache/hive/blob/master/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g#L887-L892


---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#discussion_r59678835
  
    --- 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 --
    
    Actually I am neutral about this.


---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#issuecomment-209721574
  
    **[Test build #55771 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/55771/consoleFull)** for PR 12362 at commit [`0bcafcd`](https://github.com/apache/spark/commit/0bcafcd669e7f7b556c1523575c07c113d431c5a).
     * This patch **fails Spark unit 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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#discussion_r59678675
  
    --- 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 --
    
    Thanks. But I do this to address previous comment. The main concern is that we may add more fields into `CatalogTable`. If so, we will need to revisit here to add these fields.


---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#discussion_r59711549
  
    --- 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 --
    
    @dilipbiswal and I also hit the same issue when doing the `Describe Table`. At the end, we decided to avoid adding more fields into `CatalogTable`. Will follow the discussion in this thread. 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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#discussion_r59621980
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/command/tables.scala ---
    @@ -0,0 +1,66 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.execution.command
    +
    +import org.apache.spark.sql.{AnalysisException, Row, SQLContext}
    +import org.apache.spark.sql.catalyst.TableIdentifier
    +import org.apache.spark.sql.catalyst.catalog.CatalogTable
    +
    +/**
    + * 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(
    +    table: CatalogTable,
    +    ifNotExists: Boolean,
    +    sourceTable: TableIdentifier) extends RunnableCommand {
    +
    +  override def run(sqlContext: SQLContext): Seq[Row] = {
    +    val catalog = sqlContext.sessionState.catalog
    +    if (!catalog.tableExists(sourceTable)) {
    +      throw new AnalysisException(
    +        s"Cannot create table like on not existing table ${sourceTable.identifier}.")
    +    }
    +    if (catalog.isTemporaryTable(sourceTable)) {
    +      throw new AnalysisException(
    +        s"Cannot create table like on a temporary table ${sourceTable.identifier}.")
    +    }
    +
    +    val sourceTableMetadata = catalog.getTableMetadata(sourceTable)
    +    val tableToCreate = CatalogTable(
    --- End diff --
    
    actually, we only want to change the identifier right? and maybe the create time and last access time. The rest should be exactly the same.


---
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-14592][SQL] Native support for CREATE T...

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

    https://github.com/apache/spark/pull/12362#issuecomment-210080336
  
    LGTM2


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