Skip to content
Permalink
Browse files
[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
  • Loading branch information
ShreelekhyaG authored and Indhumathi27 committed Jun 22, 2022
1 parent 33408be commit 4b8846d1e6737e7db8a96014818c067c8c253d1f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
@@ -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)
}
}
}
@@ -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")

0 comments on commit 4b8846d

Please sign in to comment.