Github user Xaprice commented on a diff in the pull request:
https://github.com/apache/carbondata/pull/2620#discussion_r208840858
--- Diff:
examples/spark2/src/main/scala/org/apache/carbondata/examples/CustomCompactionExample.scala
---
@@ -0,0 +1,69 @@
+package org.apache.carbondata.examples
+
+import java.io.File
+
+import org.apache.spark.sql.SparkSession
+
+import org.apache.carbondata.core.constants.CarbonCommonConstants
+import org.apache.carbondata.core.util.CarbonProperties
+import org.apache.carbondata.examples.util.ExampleUtils
+
+
+object CustomCompactionExample {
+
+ def main(args: Array[String]): Unit = {
+ val spark = ExampleUtils.createCarbonSession("CustomCompactionExample")
+ exampleBody(spark)
+ spark.close()
+ }
+
+ def exampleBody(spark : SparkSession): Unit = {
+ CarbonProperties.getInstance()
+ .addProperty(CarbonCommonConstants.CARBON_DATE_FORMAT, "yyyy/MM/dd")
+
+ spark.sql("DROP TABLE IF EXISTS custom_compaction_table")
+
+ spark.sql(
+ s"""
+ | CREATE TABLE IF NOT EXISTS custom_compaction_table(
+ | ID Int,
+ | date Date,
+ | country String,
+ | name String,
+ | phonetype String,
+ | serialname String,
+ | salary Int,
+ | floatField float
+ | ) STORED BY 'carbondata'
+ """.stripMargin)
+
+ val rootPath = new File(this.getClass.getResource("/").getPath
+ + "../../../..").getCanonicalPath
+ val path =
s"$rootPath/examples/spark2/src/main/resources/dataSample.csv"
+
+ // load 4 segments
+ // scalastyle:off
+ (1 to 4).foreach(_ => spark.sql(
+ s"""
+ | LOAD DATA LOCAL INPATH '$path'
+ | INTO TABLE custom_compaction_table
+ | OPTIONS('HEADER'='true')
+ """.stripMargin))
+ // scalastyle:on
+
+ // show all segments: 0,1,2,3
+ spark.sql("SHOW SEGMENTS FOR TABLE custom_compaction_table").show()
+
+ // do custom compaction, segments specified will be merged
+ spark.sql("ALTER TABLE custom_compaction_table COMPACT 'CUSTOM' WHERE
SEGMENT.ID IN (1,2)")
+ spark.sql("SHOW SEGMENTS FOR TABLE custom_compaction_table").show()
+
+ CarbonProperties.getInstance().addProperty(
--- End diff --
This Property is set to non-default value in the beginning of method
'exampleBody' . To ensure the completeness of this test case, the property is
set back to default value, though it seems to be redundant.
---