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 7ca3775  [CARBONDATA-4020] Fixed drop index when multiple index exists
7ca3775 is described below

commit 7ca377507c525394f94316e41fb00fbe305ca239
Author: Nihal ojha <[email protected]>
AuthorDate: Fri Oct 30 12:44:18 2020 +0530

    [CARBONDATA-4020] Fixed drop index when multiple index exists
    
    Why is this PR needed?
    Currently when we have multiple bloom indexes and we drop one index
    then 'show index' command is showing an empty index list.
    
    What changes were proposed in this PR?
    Checked, if no CG or FG index then set indexExist as true.
    
    Does this PR introduce any user interface change?
    No
    
    Is any new testcase added?
    Yes
    
    This closes #4000
---
 .../execution/command/index/DropIndexCommand.scala | 21 ++++++++++++---------
 .../bloom/BloomCoarseGrainIndexFunctionSuite.scala | 22 ++++++++++++++++++++++
 2 files changed, 34 insertions(+), 9 deletions(-)

diff --git 
a/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/index/DropIndexCommand.scala
 
b/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/index/DropIndexCommand.scala
index 3d4d32c..45a93bc 100644
--- 
a/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/index/DropIndexCommand.scala
+++ 
b/integration/spark/src/main/scala/org/apache/spark/sql/execution/command/index/DropIndexCommand.scala
@@ -183,17 +183,20 @@ private[sql] case class DropIndexCommand(
           parentCarbonTable)
         parentCarbonTable = getRefreshedParentTable(sparkSession, dbName)
         val indexMetadata = parentCarbonTable.getIndexMetadata
+        var hasCgFgIndexes = false
         if (null != indexMetadata && null != indexMetadata.getIndexesMap) {
-          val hasCgFgIndexes =
-            !(indexMetadata.getIndexesMap.size() == 1 &&
-              
indexMetadata.getIndexesMap.containsKey(IndexType.SI.getIndexProviderName))
-          if (hasCgFgIndexes) {
-            CarbonIndexUtil
-              .addOrModifyTableProperty(parentCarbonTable,
-                Map("indexExists" -> "false"), needLock = false)(sparkSession)
+          // check if any CG or FG index exists. If not exists,
+          // then set indexExists as false to return empty index list for next 
query.
+          hasCgFgIndexes =
+            
indexMetadata.getIndexesMap.containsKey(IndexType.BLOOMFILTER.getIndexProviderName)
 ||
+              
indexMetadata.getIndexesMap.containsKey(IndexType.LUCENE.getIndexProviderName)
+        }
+        if (!hasCgFgIndexes) {
+          CarbonIndexUtil
+            .addOrModifyTableProperty(parentCarbonTable,
+              Map("indexExists" -> "false"), needLock = false)(sparkSession)
 
-            CarbonHiveIndexMetadataUtil.refreshTable(dbName, parentTableName, 
sparkSession)
-          }
+          CarbonHiveIndexMetadataUtil.refreshTable(dbName, parentTableName, 
sparkSession)
         }
       }
     } finally {
diff --git 
a/integration/spark/src/test/scala/org/apache/carbondata/index/bloom/BloomCoarseGrainIndexFunctionSuite.scala
 
b/integration/spark/src/test/scala/org/apache/carbondata/index/bloom/BloomCoarseGrainIndexFunctionSuite.scala
index c42056c..d9d8e84 100644
--- 
a/integration/spark/src/test/scala/org/apache/carbondata/index/bloom/BloomCoarseGrainIndexFunctionSuite.scala
+++ 
b/integration/spark/src/test/scala/org/apache/carbondata/index/bloom/BloomCoarseGrainIndexFunctionSuite.scala
@@ -660,6 +660,28 @@ class BloomCoarseGrainIndexFunctionSuite
       sql(s"SELECT * FROM $normalTable WHERE salary='1040'"))
   }
 
+  test("test drop index when more than one bloom index exists") {
+    sql(s"CREATE TABLE $bloomSampleTable " +
+      "(id int,name string,salary int)STORED as carbondata 
TBLPROPERTIES('SORT_COLUMNS'='id')")
+    sql(s"CREATE index index1 ON TABLE $bloomSampleTable(id) as 'bloomfilter' 
" +
+      "PROPERTIES ( 'BLOOM_SIZE'='640000', 'BLOOM_FPP'='0.00001', 
'BLOOM_COMPRESS'='true')")
+    sql(s"CREATE index index2 ON TABLE $bloomSampleTable (name) as 
'bloomfilter' " +
+      "PROPERTIES ('BLOOM_SIZE'='640000', 'BLOOM_FPP'='0.00001', 
'BLOOM_COMPRESS'='true')")
+    sql(s"insert into $bloomSampleTable values(1,'nihal',20)")
+    checkExistence(sql(s"SHOW INDEXES ON TABLE $bloomSampleTable"), true, 
"index1", "index2")
+    sql(s"drop index index1 on $bloomSampleTable")
+    checkExistence(sql(s"SHOW INDEXES ON TABLE $bloomSampleTable"), true, 
"index2")
+    sql(s"drop index index2 on $bloomSampleTable")
+    val carbonTable = CarbonEnv.getCarbonTable(
+      Option("default"), bloomSampleTable)(sqlContext.sparkSession)
+    val isIndexExists = carbonTable.getTableInfo
+      .getFactTable
+      .getTableProperties
+      .get("indexexists")
+    assertResult("false")(isIndexExists)
+    assert(sql(s"SHOW INDEXES ON TABLE $bloomSampleTable").collect().isEmpty)
+  }
+
   test("test rebuild bloom index: index column is float, dictionary") {
     val floatCsvPath = s"$resourcesPath/datasamplefordate.csv"
     CarbonProperties.getInstance()

Reply via email to