carbondata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ravipes...@apache.org
Subject carbondata git commit: [CARBONDATA-1690][DATAMAP] Clear datamap when renaming table
Date Fri, 10 Nov 2017 10:52:20 GMT
Repository: carbondata
Updated Branches:
  refs/heads/master 4aa0f4930 -> a91c6e4f9


[CARBONDATA-1690][DATAMAP] Clear datamap when renaming table

This closes #1479


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

Branch: refs/heads/master
Commit: a91c6e4f975885d30850ff168ab06c8c5b04e6f2
Parents: 4aa0f49
Author: xuchuanyin <xuchuanyin@hust.edu.cn>
Authored: Thu Nov 9 21:25:06 2017 +0800
Committer: ravipesala <ravi.pesala@gmail.com>
Committed: Fri Nov 10 16:22:06 2017 +0530

----------------------------------------------------------------------
 .../schema/CarbonAlterTableRenameCommand.scala  |  7 ++++--
 .../AlterTableValidationTestCase.scala          | 24 ++++++++++++++++++++
 2 files changed, 29 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/carbondata/blob/a91c6e4f/integration/spark2/src/main/scala/org/apache/spark/sql/execution/command/schema/CarbonAlterTableRenameCommand.scala
----------------------------------------------------------------------
diff --git a/integration/spark2/src/main/scala/org/apache/spark/sql/execution/command/schema/CarbonAlterTableRenameCommand.scala
b/integration/spark2/src/main/scala/org/apache/spark/sql/execution/command/schema/CarbonAlterTableRenameCommand.scala
index c000488..5936355 100644
--- a/integration/spark2/src/main/scala/org/apache/spark/sql/execution/command/schema/CarbonAlterTableRenameCommand.scala
+++ b/integration/spark2/src/main/scala/org/apache/spark/sql/execution/command/schema/CarbonAlterTableRenameCommand.scala
@@ -25,6 +25,7 @@ import org.apache.spark.util.AlterTableUtil
 
 import org.apache.carbondata.common.logging.{LogService, LogServiceFactory}
 import org.apache.carbondata.core.constants.CarbonCommonConstants
+import org.apache.carbondata.core.datamap.DataMapStoreManager
 import org.apache.carbondata.core.datastore.impl.FileFactory
 import org.apache.carbondata.core.locks.{ICarbonLock, LockUsage}
 import org.apache.carbondata.core.metadata.{AbsoluteTableIdentifier, CarbonTableIdentifier}
@@ -83,9 +84,11 @@ private[sql] case class CarbonAlterTableRenameCommand(
       val tableMeta = metastore.lookupRelation(Some(oldDatabaseName), oldTableName)(sparkSession)
         .asInstanceOf[CarbonRelation].tableMeta
       carbonTable = tableMeta.carbonTable
+      // invalid data map for the old table, see CARBON-1690
+      val oldTableIdentifier = AbsoluteTableIdentifier.fromTablePath(tableMeta.tablePath)
+      DataMapStoreManager.getInstance().clearDataMap(oldTableIdentifier)
       // get the latest carbon table and check for column existence
-      val carbonTablePath = CarbonStorePath.
-        getCarbonTablePath(AbsoluteTableIdentifier.fromTablePath(tableMeta.tablePath))
+      val carbonTablePath = CarbonStorePath.getCarbonTablePath(oldTableIdentifier)
       val tableMetadataFile = carbonTablePath.getPath
       val tableInfo: org.apache.carbondata.format.TableInfo =
         metastore.getThriftTableInfo(carbonTablePath)(sparkSession)

http://git-wip-us.apache.org/repos/asf/carbondata/blob/a91c6e4f/integration/spark2/src/test/scala/org/apache/spark/carbondata/restructure/AlterTableValidationTestCase.scala
----------------------------------------------------------------------
diff --git a/integration/spark2/src/test/scala/org/apache/spark/carbondata/restructure/AlterTableValidationTestCase.scala
b/integration/spark2/src/test/scala/org/apache/spark/carbondata/restructure/AlterTableValidationTestCase.scala
index 9cfb77a..6f618fe 100644
--- a/integration/spark2/src/test/scala/org/apache/spark/carbondata/restructure/AlterTableValidationTestCase.scala
+++ b/integration/spark2/src/test/scala/org/apache/spark/carbondata/restructure/AlterTableValidationTestCase.scala
@@ -446,6 +446,30 @@ class AlterTableValidationTestCase extends Spark2QueryTest with BeforeAndAfterAl
     sql("alter table Default.uniqdata rename to uniqdata1")
     checkAnswer(sql("select * from Default.uniqdata1"), Row(1,"hello"))
   }
+
+  // test query before&after renaming, see CARBONDATA-1690
+  test("RenameTable_query_before_and_after_renaming") {
+    try {
+      sql(s"""create table test1 (name string, id int) stored by 'carbondata'""").collect
+      sql(s"""create table test2 (name string, id int) stored by 'carbondata'""").collect
+      sql(s"""insert into test1 select 'xx1',1""").collect
+      sql(s"""insert into test2 select 'xx2',2""").collect
+      // query before rename
+      checkAnswer(sql(s"""select * from test1"""), Seq(Row("xx1", 1)))
+      sql(s"""alter table test1 RENAME TO test3""").collect
+      sql(s"""alter table test2 RENAME TO test1""").collect
+      // query after rename
+      checkAnswer(sql(s"""select * from test1"""), Seq(Row("xx2", 2)))
+    } catch {
+      case e: Exception =>
+        assert(false)
+    } finally {
+      sql(s"""drop table if exists test1""").collect
+      sql(s"""drop table if exists test3""").collect
+      sql(s"""drop table if exists test2""").collect
+    }
+  }
+
   test("describe formatted for default sort_columns pre and post alter") {
     sql("CREATE TABLE defaultSortColumnsWithAlter (empno int, empname String, designation
String,role String, doj Timestamp) STORED BY 'org.apache.carbondata.format' " +
         "tblproperties('DICTIONARY_INCLUDE'='empno','DICTIONARY_EXCLUDE'='role')")


Mime
View raw message