carbondata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gvram...@apache.org
Subject [1/2] incubator-carbondata git commit: Alter operations on carbon table will be unsupported.
Date Tue, 30 Aug 2016 16:54:22 GMT
Repository: incubator-carbondata
Updated Branches:
  refs/heads/master 6537316de -> 1df4d4037


Alter operations on carbon table will be unsupported.


Project: http://git-wip-us.apache.org/repos/asf/incubator-carbondata/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-carbondata/commit/47e07599
Tree: http://git-wip-us.apache.org/repos/asf/incubator-carbondata/tree/47e07599
Diff: http://git-wip-us.apache.org/repos/asf/incubator-carbondata/diff/47e07599

Branch: refs/heads/master
Commit: 47e07599597f01ff2648be1aa79bd7c94762edb7
Parents: 6537316
Author: nareshpr <prnaresh.naresh@gmail.com>
Authored: Mon Aug 29 12:27:23 2016 +0530
Committer: Venkata Ramana G <ramana.gollamudi@huawei.com>
Committed: Tue Aug 30 22:20:41 2016 +0530

----------------------------------------------------------------------
 .../org/apache/spark/sql/CarbonSqlParser.scala  | 17 ++++++---------
 .../execution/command/carbonTableSchema.scala   |  3 ++-
 .../spark/sql/hive/CarbonStrategies.scala       | 15 +++++++++++++
 .../createtable/TestCreateTableSyntax.scala     | 22 ++++++++++++++++++++
 4 files changed, 45 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/47e07599/integration/spark/src/main/scala/org/apache/spark/sql/CarbonSqlParser.scala
----------------------------------------------------------------------
diff --git a/integration/spark/src/main/scala/org/apache/spark/sql/CarbonSqlParser.scala b/integration/spark/src/main/scala/org/apache/spark/sql/CarbonSqlParser.scala
index 318c78a..6556ba2 100644
--- a/integration/spark/src/main/scala/org/apache/spark/sql/CarbonSqlParser.scala
+++ b/integration/spark/src/main/scala/org/apache/spark/sql/CarbonSqlParser.scala
@@ -290,10 +290,11 @@ class CarbonSqlParser()
     ALTER ~> TABLE ~> restInput ^^ {
       case statement =>
         try {
+          val alterSql = "alter table " + statement
           // DDl will be parsed and we get the AST tree from the HiveQl
-          val node = HiveQlWrapper.getAst("alter table " + statement)
+          val node = HiveQlWrapper.getAst(alterSql)
           // processing the AST tree
-          nodeToPlanForAlterTable(node)
+          nodeToPlanForAlterTable(node, alterSql)
         } catch {
           // MalformedCarbonCommandException need to be throw directly, parser will catch
it
           case ce: MalformedCarbonCommandException =>
@@ -468,7 +469,7 @@ class CarbonSqlParser()
    * @param node
    * @return LogicalPlan
    */
-  protected def nodeToPlanForAlterTable(node: Node): LogicalPlan = {
+  protected def nodeToPlanForAlterTable(node: Node, alterSql: String): LogicalPlan = {
     node match {
       // if create table taken is found then only we will handle.
       case Token("TOK_ALTERTABLE", children) =>
@@ -490,14 +491,8 @@ class CarbonSqlParser()
           case _ => // Unsupport features
         }
 
-        if (compactionType.equalsIgnoreCase("minor") || compactionType.equalsIgnoreCase("major"))
{
-          val altertablemodel = AlterTableModel(dbName, tableName, compactionType)
-          AlterTableCompaction(altertablemodel)
-        }
-        else {
-          sys.error("Invalid compaction type, supported values are 'major' and 'minor'")
-        }
-
+        val altertablemodel = AlterTableModel(dbName, tableName, compactionType, alterSql)
+        AlterTableCompaction(altertablemodel)
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/47e07599/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/carbonTableSchema.scala
----------------------------------------------------------------------
diff --git a/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/carbonTableSchema.scala
b/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/carbonTableSchema.scala
index 85f0a2d..486d54c 100644
--- a/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/carbonTableSchema.scala
+++ b/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/carbonTableSchema.scala
@@ -152,7 +152,8 @@ case class CarbonMergerMapping(storeLocation: String, hdfsStoreLocation:
String,
 case class NodeInfo(TaskId: String, noOfBlocks: Int)
 
 
-case class AlterTableModel(dbName: Option[String], tableName: String, compactionType: String)
+case class AlterTableModel(dbName: Option[String], tableName: String,
+  compactionType: String, alterSql: String)
 
 case class CompactionModel(compactionSize: Long,
   compactionType: CompactionType,

http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/47e07599/integration/spark/src/main/scala/org/apache/spark/sql/hive/CarbonStrategies.scala
----------------------------------------------------------------------
diff --git a/integration/spark/src/main/scala/org/apache/spark/sql/hive/CarbonStrategies.scala
b/integration/spark/src/main/scala/org/apache/spark/sql/hive/CarbonStrategies.scala
index 21a4dc3..d8e23bd 100644
--- a/integration/spark/src/main/scala/org/apache/spark/sql/hive/CarbonStrategies.scala
+++ b/integration/spark/src/main/scala/org/apache/spark/sql/hive/CarbonStrategies.scala
@@ -236,6 +236,21 @@ class CarbonStrategies(sqlContext: SQLContext) extends QueryPlanner[SparkPlan]
{
         } else {
           ExecutedCommand(HiveNativeCommand(inputSqlString)) :: Nil
         }
+      case alterTable@AlterTableCompaction(altertablemodel) =>
+        val isCarbonTable = CarbonEnv.getInstance(sqlContext).carbonCatalog
+            .tableExists(TableIdentifier(altertablemodel.tableName,
+                 altertablemodel.dbName))(sqlContext)
+        if (isCarbonTable) {
+          if (altertablemodel.compactionType.equalsIgnoreCase("minor") ||
+              altertablemodel.compactionType.equalsIgnoreCase("major")) {
+            ExecutedCommand(alterTable) :: Nil
+          } else {
+            throw new MalformedCarbonCommandException(
+                "Unsupported alter operation on carbon table")
+          }
+        } else {
+          ExecutedCommand(HiveNativeCommand(altertablemodel.alterSql)) :: Nil
+        }
       case d: HiveNativeCommand =>
         try {
           val resolvedTable = sqlContext.executePlan(CarbonHiveSyntax.parse(d.sql)).optimizedPlan

http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/47e07599/integration/spark/src/test/scala/org/apache/carbondata/spark/testsuite/createtable/TestCreateTableSyntax.scala
----------------------------------------------------------------------
diff --git a/integration/spark/src/test/scala/org/apache/carbondata/spark/testsuite/createtable/TestCreateTableSyntax.scala
b/integration/spark/src/test/scala/org/apache/carbondata/spark/testsuite/createtable/TestCreateTableSyntax.scala
index 877f47f..6fd5e1d 100644
--- a/integration/spark/src/test/scala/org/apache/carbondata/spark/testsuite/createtable/TestCreateTableSyntax.scala
+++ b/integration/spark/src/test/scala/org/apache/carbondata/spark/testsuite/createtable/TestCreateTableSyntax.scala
@@ -44,6 +44,28 @@ class TestCreateTableSyntax extends QueryTest with BeforeAndAfterAll {
     sql("drop table if exists carbontable")
   }
   
+  test("Test table rename operation on carbon table and on hive table") {
+    sql("create table hivetable(test1 int, test2 array<String>,test3 array<bigint>,"+
+        "test4 array<int>,test5 array<decimal>,test6 array<timestamp>,test7
array<double>)"+
+        "row format delimited fields terminated by ',' collection items terminated by '$'
map keys terminated by ':'")
+    sql("alter table hivetable rename To hiveRenamedTable")
+    sql("create table carbontable(test1 int, test2 array<String>,test3 array<bigint>,"+
+        "test4 array<int>,test5 array<decimal>,test6 array<timestamp>,test7
array<double>)"+
+        "STORED BY 'org.apache.carbondata.format'")
+    sql("alter table carbontable compact 'minor'")
+    try {
+      sql("alter table carbontable rename To carbonRenamedTable")
+      assert(false)
+    } catch {
+      case e : MalformedCarbonCommandException => {
+        assert(e.getMessage.equals("Unsupported alter operation on carbon table"))
+      }
+    }
+    sql("drop table if exists hiveRenamedTable")
+    sql("drop table if exists carbontable")
+  }
+
+  
   test("test carbon table create with complex datatype as dictionary exclude") {
     try {
       sql("create table carbontable(id int, name string, dept string, mobile array<string>,
"+


Mime
View raw message