akashrn5 commented on a change in pull request #3988:
URL: https://github.com/apache/carbondata/pull/3988#discussion_r515746959



##########
File path: 
core/src/main/java/org/apache/carbondata/core/constants/CarbonCommonConstants.java
##########
@@ -361,6 +361,11 @@ private CarbonCommonConstants() {
 
   public static final String CARBON_INDEX_SCHEMA_STORAGE_DATABASE = "DATABASE";
 
+  @CarbonProperty
+  public static final String CARBON_INDEXFILES_DELETETIME = 
"carbon.index.delete.time";

Review comment:
       agree with @ajantha-bhat , we can reuse the query execution timeout and 
delete as its also one hour.

##########
File path: 
integration/spark/src/test/scala/org/apache/carbondata/spark/testsuite/cleanfiles/TestCleanFileCommand.scala
##########
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.carbondata.spark.testsuite.cleanfiles
+
+import org.apache.spark.sql.Row
+import org.apache.spark.sql.test.util.QueryTest
+import org.scalatest.BeforeAndAfterAll
+
+import org.apache.carbondata.core.constants.CarbonCommonConstants
+import org.apache.carbondata.core.datastore.filesystem.{CarbonFile, 
CarbonFileFilter}
+import org.apache.carbondata.core.datastore.impl.FileFactory
+import org.apache.carbondata.core.index.Segment
+import org.apache.carbondata.core.metadata.{CarbonMetadata, SegmentFileStore}
+import org.apache.carbondata.core.util.CarbonProperties
+import org.apache.carbondata.core.util.path.CarbonTablePath
+
+class TestCleanFileCommand extends QueryTest with BeforeAndAfterAll {
+
+  var count = 0
+
+  override protected def beforeAll(): Unit = {
+    sql("DROP TABLE IF EXISTS cleantest")
+    CarbonProperties.getInstance()
+      .addProperty(CarbonCommonConstants.MAX_QUERY_EXECUTION_TIME, "0")
+  }
+
+  override protected def afterAll(): Unit = {
+    sql("DROP TABLE IF EXISTS cleantest")
+    CarbonProperties.getInstance()
+      .addProperty(CarbonCommonConstants.MAX_QUERY_EXECUTION_TIME,
+        CarbonCommonConstants.DEFAULT_MAX_QUERY_EXECUTION_TIME.toString)
+  }
+
+  test("test clean files command for index files") {
+    sql("drop table if exists cleantest")
+    sql("create table cleantest(id int, issue date) STORED AS carbondata")
+    sql("insert into table cleantest select '1','2000-02-01'")
+    assert(getIndexFileCountFromSegmentPath("default_cleantest", "0") == 1)
+    sql("clean files for table cleantest")
+    assert(getIndexFileCountFromSegmentPath("default_cleantest", "0") == 0)
+    sql("drop table if exists cleantest")
+  }
+
+  test("test clean files command for index files with SI") {
+    sql("drop table if exists cleantest")
+    sql("create table cleantest(id int, issue date, name string) STORED AS 
carbondata")
+    sql("insert into table cleantest select '1','2000-02-01', 'abc' ")
+    sql("create index indextable1 on table cleantest (name) AS 'carbondata'")
+    assert(getIndexFileCountFromSegmentPath("default_cleantest", "0") == 1)
+    assert(getIndexFileCountFromSegmentPath("default_indextable1", "0") == 1)
+    sql("clean files for table cleantest")
+    assert(getIndexFileCountFromSegmentPath("default_cleantest", "0") == 0)
+    assert(getIndexFileCountFromSegmentPath("default_indextable1", "0") == 0)
+    sql("drop table if exists cleantest")
+  }
+
+  test("test clean files command on partition table") {
+    sql("drop table if exists cleantest")
+    sql("create table cleantest(id int, issue date) STORED AS carbondata " +
+        "partitioned by (name string)")
+    sql("insert into table cleantest select '1','2000-02-01', 'abc' ")
+    assert(getIndexFileCountFromSegmentPath("default_cleantest", "0") == 1)
+    sql("clean files for table cleantest")
+    assert(getIndexFileCountFromSegmentPath("default_cleantest", "0") == 0)
+    sql("drop table if exists cleantest")
+  }
+
+  test("test clean files command for index files after update") {
+    sql("drop table if exists cleantest")
+    sql("create table cleantest(id int, name string) STORED AS carbondata")
+    sql("insert into table cleantest select '1', 'abc' ")
+    sql("insert into table cleantest select '2', 'abc' ")
+    assert(getIndexFileCountFromSegmentPath("default_cleantest", "0") == 1)
+    assert(getIndexFileCountFromSegmentPath("default_cleantest", "1") == 1)
+    sql("update cleantest set (name)=('xyz') where id=2")
+    assert(getIndexFileCountFromSegmentPath("default_cleantest", "1") == 2)
+    sql("clean files for table cleantest")
+    assert(getIndexFileCountFromSegmentPath("default_cleantest", "1") == 1)
+    checkAnswer(sql("select *from cleantest where id=2"), Seq(Row(2, "xyz")))
+  }
+
+  test("test clean files without mergeindex") {
+    CarbonProperties.getInstance()
+      .addProperty(CarbonCommonConstants.CARBON_MERGE_INDEX_IN_SEGMENT, 
"false")
+    sql("drop table if exists cleantest")
+    sql("create table cleantest(id int, name string) STORED AS carbondata")
+    sql("insert into table cleantest select '1', 'abc' ")
+    assert(getIndexFileCountFromSegmentPath("default_cleantest", "0") == 1)
+    assert(getIndexFileCountFromSegmentFile("default_cleantest", "0") == 1)
+    sql("clean files for table cleantest")
+    assert(getIndexFileCountFromSegmentPath("default_cleantest", "0") == 1)
+    assert(getIndexFileCountFromSegmentFile("default_cleantest", "0") == 1)
+    checkAnswer(sql("select *from cleantest where id=1"), Seq(Row(1, "abc")))
+  }
+
+  test("test clean files after index merge and check segment count") {
+    CarbonProperties.getInstance()
+      .addProperty(CarbonCommonConstants.CARBON_MERGE_INDEX_IN_SEGMENT, 
"false")
+    sql("drop table if exists cleantest")
+    sql(s"create table cleantest(id int, issue date) STORED AS carbondata")
+    sql("insert into table cleantest select '1','2000-02-01'")
+    assert(getIndexFileCountFromSegmentPath("default_cleantest", "0") == 1)
+    assert(getSegmentFileCount("default_cleantest") == 1)
+    CarbonProperties.getInstance()
+      .addProperty(CarbonCommonConstants.CARBON_MERGE_INDEX_IN_SEGMENT, "true")
+    sql("ALTER TABLE cleantest COMPACT 'SEGMENT_INDEX'").collect()
+    assert(getSegmentFileCount("default_cleantest") == 2)
+    assert(getIndexFileCountFromSegmentPath("default_cleantest", "0") == 1)
+    assert(getIndexFileCountFromSegmentPath("default_cleantest",
+      "0", CarbonTablePath.MERGE_INDEX_FILE_EXT) == 1)
+    sql("clean files for table cleantest")
+    assert(getSegmentFileCount("default_cleantest") == 1)
+    assert(getIndexFileCountFromSegmentPath("default_cleantest", "0") == 0)
+  }
+
+  private def getSegmentFileCount(tableName: String): Int = {
+    val carbonTable = 
CarbonMetadata.getInstance().getCarbonTable("default_cleantest")
+    val segmentsPath = 
CarbonTablePath.getSegmentFilesLocation(carbonTable.getTablePath)
+    FileFactory.getCarbonFile(segmentsPath).listFiles(true).size()
+  }
+
+  private def getIndexFileCountFromSegmentFile(tableName: String, segmentNo: 
String): Int = {
+    val carbonTable = CarbonMetadata.getInstance().getCarbonTable(tableName)
+    val segment = Segment.getSegment(segmentNo, carbonTable.getTablePath)
+    new SegmentFileStore(carbonTable.getTablePath, segment.getSegmentFileName)
+      .getIndexFiles.size()
+  }
+
+  private def getIndexFileCountFromSegmentPath(tableName: String,

Review comment:
       is this method used somewhere also? if yes, do not duplicate the code, 
you can add in any test utility class and then use everywhere same

##########
File path: 
integration/spark/src/test/scala/org/apache/carbondata/spark/testsuite/cleanfiles/TestCleanFileCommand.scala
##########
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.carbondata.spark.testsuite.cleanfiles
+
+import org.apache.spark.sql.Row
+import org.apache.spark.sql.test.util.QueryTest
+import org.scalatest.BeforeAndAfterAll
+
+import org.apache.carbondata.core.constants.CarbonCommonConstants
+import org.apache.carbondata.core.datastore.filesystem.{CarbonFile, 
CarbonFileFilter}
+import org.apache.carbondata.core.datastore.impl.FileFactory
+import org.apache.carbondata.core.index.Segment
+import org.apache.carbondata.core.metadata.{CarbonMetadata, SegmentFileStore}
+import org.apache.carbondata.core.util.CarbonProperties
+import org.apache.carbondata.core.util.path.CarbonTablePath
+
+class TestCleanFileCommand extends QueryTest with BeforeAndAfterAll {
+
+  var count = 0
+
+  override protected def beforeAll(): Unit = {
+    sql("DROP TABLE IF EXISTS cleantest")
+    CarbonProperties.getInstance()
+      .addProperty(CarbonCommonConstants.MAX_QUERY_EXECUTION_TIME, "0")
+  }
+
+  override protected def afterAll(): Unit = {
+    sql("DROP TABLE IF EXISTS cleantest")
+    CarbonProperties.getInstance()
+      .addProperty(CarbonCommonConstants.MAX_QUERY_EXECUTION_TIME,
+        CarbonCommonConstants.DEFAULT_MAX_QUERY_EXECUTION_TIME.toString)
+  }
+
+  test("test clean files command for index files") {
+    sql("drop table if exists cleantest")
+    sql("create table cleantest(id int, issue date) STORED AS carbondata")
+    sql("insert into table cleantest select '1','2000-02-01'")
+    assert(getIndexFileCountFromSegmentPath("default_cleantest", "0") == 1)
+    sql("clean files for table cleantest")
+    assert(getIndexFileCountFromSegmentPath("default_cleantest", "0") == 0)
+    sql("drop table if exists cleantest")
+  }
+
+  test("test clean files command for index files with SI") {

Review comment:
       combine `test clean files command for index files` and `test clean files 
command for index files with SI` in a single test case, as not much diff




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to