You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@carbondata.apache.org by in...@apache.org on 2022/06/22 05:31:32 UTC

[carbondata] branch master updated: [CARBONDATA-4341] Drop Index Fails after TABLE RENAME

This is an automated email from the ASF dual-hosted git repository.

indhumuthumurugesh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/carbondata.git


The following commit(s) were added to refs/heads/master by this push:
     new 4b8846d1e6 [CARBONDATA-4341] Drop Index Fails after TABLE RENAME
4b8846d1e6 is described below

commit 4b8846d1e6737e7db8a96014818c067c8c253d1f
Author: ShreelekhyaG <sh...@yahoo.com>
AuthorDate: Wed Jun 15 12:08:41 2022 +0530

    [CARBONDATA-4341] Drop Index Fails after TABLE RENAME
    
    Why is this PR needed?
    Drop Index Fails after TABLE RENAME
    
    What changes were proposed in this PR?
    After table rename, its si tables property - parentTableName is updated
    with latest name and index metadata gets updated. Dropping the table
    from the metadata cache so that it would be reloaded and gets updated
    property when fetched next time.
    
    Does this PR introduce any user interface change?
    No
    
    Is any new testcase added?
    Yes
    
    This closes #4279
---
 .../events/AlterTableRenameEventListener.scala           |  4 +++-
 .../vectorreader/AlterTableColumnRenameTestCase.scala    | 16 ++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/integration/spark/src/main/scala/org/apache/spark/sql/secondaryindex/events/AlterTableRenameEventListener.scala b/integration/spark/src/main/scala/org/apache/spark/sql/secondaryindex/events/AlterTableRenameEventListener.scala
index 558a136d6b..7721aca40f 100644
--- a/integration/spark/src/main/scala/org/apache/spark/sql/secondaryindex/events/AlterTableRenameEventListener.scala
+++ b/integration/spark/src/main/scala/org/apache/spark/sql/secondaryindex/events/AlterTableRenameEventListener.scala
@@ -51,11 +51,13 @@ class AlterTableRenameEventListener extends OperationEventListener with Logging
           .lookupRelation(Some(oldDatabaseName), newTableName)(sparkSession)
           .asInstanceOf[CarbonRelation].carbonTable
         table.getIndexTableNames(IndexType.SI.getIndexProviderName)
-          .asScala.map {
+          .asScala.foreach {
           entry =>
             CarbonSessionCatalogUtil.getClient(sparkSession).runSqlHive(
               s"ALTER TABLE $oldDatabaseName.${ entry } " +
               s"SET SERDEPROPERTIES ('parentTableName'='$newTableName')")
+            CarbonEnv.getInstance(sparkSession).carbonMetaStore
+              .removeTableFromMetadata(oldDatabaseName, entry)
         }
     }
   }
diff --git a/integration/spark/src/test/scala/org/apache/spark/carbondata/restructure/vectorreader/AlterTableColumnRenameTestCase.scala b/integration/spark/src/test/scala/org/apache/spark/carbondata/restructure/vectorreader/AlterTableColumnRenameTestCase.scala
index cc7152b700..031db066ec 100644
--- a/integration/spark/src/test/scala/org/apache/spark/carbondata/restructure/vectorreader/AlterTableColumnRenameTestCase.scala
+++ b/integration/spark/src/test/scala/org/apache/spark/carbondata/restructure/vectorreader/AlterTableColumnRenameTestCase.scala
@@ -780,6 +780,21 @@ class AlterTableColumnRenameTestCase extends QueryTest with BeforeAndAfterAll {
     sql("DROP TABLE IF EXISTS test_alter")
   }
 
+  test("test alter rename table and drop index") {
+    sql("drop table if exists test_rename")
+    sql("drop index if exists si on test_rename1")
+    sql("CREATE TABLE test_rename (name string,id int) STORED AS carbondata")
+    sql("insert into test_rename values('a',1)")
+    sql("insert into test_rename values('v',2)")
+    sql(s"create index si on test_rename(name) as 'carbondata'")
+    // only rename operation
+    sql("alter table test_rename rename to test_rename1")
+    checkAnswer(sql("select id from test_rename1"),
+      Seq(Row(1), Row(2)))
+    sql("drop index if exists si on test_rename1")
+    sql("drop table if exists test_rename1")
+  }
+
   override def afterAll(): Unit = {
     dropTable()
   }
@@ -788,6 +803,7 @@ class AlterTableColumnRenameTestCase extends QueryTest with BeforeAndAfterAll {
     sql("DROP TABLE IF EXISTS rename")
     sql("DROP TABLE IF EXISTS rename_partition")
     sql("DROP TABLE IF EXISTS test_rename")
+    sql("drop table if exists test_rename1")
     sql("DROP TABLE IF EXISTS test_rename_compact")
     sql("DROP TABLE IF EXISTS test_alter")
     sql("DROP TABLE IF EXISTS simple_table")