[GitHub] [carbondata] kevinjmh commented on a change in pull request #3382: [CARBONDATA-3518] Support create table like command

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[GitHub] [carbondata] kevinjmh commented on a change in pull request #3382: [CARBONDATA-3518] Support create table like command

GitBox
kevinjmh commented on a change in pull request #3382: [CARBONDATA-3518] Support create table like command
URL: https://github.com/apache/carbondata/pull/3382#discussion_r327462744
 
 

 ##########
 File path: integration/spark2/src/main/scala/org/apache/spark/sql/execution/command/table/CarbonCreateTableLikeCommand.scala
 ##########
 @@ -0,0 +1,93 @@
+/*
+ * 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.table
+
+import java.io._
+import java.util
+import java.util.UUID
+
+import org.apache.spark.sql.{CarbonEnv, Row, SparkSession}
+import org.apache.spark.sql.catalyst.TableIdentifier
+import org.apache.spark.sql.execution.command.MetadataCommand
+
+import org.apache.carbondata.common.exceptions.sql.MalformedCarbonCommandException
+import org.apache.carbondata.common.logging.LogServiceFactory
+import org.apache.carbondata.core.metadata.schema.{SchemaEvolution, SchemaEvolutionEntry}
+import org.apache.carbondata.core.metadata.schema.table.{TableInfo, TableSchema}
+
+/**
+* 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 CarbonCreateTableLikeCommand(
+    sourceTable: TableIdentifier,
+    targetTable: TableIdentifier,
+    ifNotExists: Boolean = false) extends MetadataCommand {
+
+  private val LOGGER = LogServiceFactory.getLogService(this.getClass.getName)
+
+  override def processMetadata(sparkSession: SparkSession): Seq[Row] = {
+    val srcTable = CarbonEnv.getCarbonTable(sourceTable.database, sourceTable.table)(sparkSession)
+    val srcTableInfo = srcTable.getTableInfo
+
+    if (!srcTable.isTransactionalTable) {
+      throw new MalformedCarbonCommandException("Unsupported operation on non transactional table")
+    }
+    if (srcTable.isChildTable || srcTable.isChildDataMap) {
+      throw new MalformedCarbonCommandException("Unsupported operation on child table or datamap")
+    }
+
+    val dstTableSchema = try {
+      // deep copy a TableSchema and update table ID and name
 
 Review comment:
   ok, moved

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[hidden email]


With regards,
Apache Git Services