Github user chenliang613 commented on a diff in the pull request:

    https://github.com/apache/carbondata/pull/2620#discussion_r208780697
  
    --- 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(
    +      CarbonCommonConstants.CARBON_DATE_FORMAT,
    +      CarbonCommonConstants.CARBON_DATE_DEFAULT_FORMAT)
    +
    --- End diff --
    
    After custom compaction, please query table data once to check the data if 
it is correct?


---

Reply via email to