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

    https://github.com/apache/carbondata/pull/1192#discussion_r131058295
  
    --- Diff: 
integration/spark2/src/main/scala/org/apache/spark/sql/execution/command/carbonTableSchema.scala
 ---
    @@ -184,6 +189,161 @@ case class AlterTableCompaction(alterTableModel: 
AlterTableModel) extends Runnab
       }
     }
     
    +/**
    + * Command for Alter Table Add & Split partition
    + * Add is a special case of Splitting the default partition (part0)
    + * @param alterTableSplitPartitionModel
    + */
    +case class AlterTableSplitPartition(alterTableSplitPartitionModel: 
AlterTableSplitPartitionModel)
    +  extends RunnableCommand {
    +  val LOGGER = LogServiceFactory.getLogService(this.getClass.getName)
    +
    +  def run(sparkSession: SparkSession): Seq[Row] = {
    +
    +    val tableName = alterTableSplitPartitionModel.tableName
    +    val dbName = alterTableSplitPartitionModel.databaseName
    +      .getOrElse(sparkSession.catalog.currentDatabase)
    +    val splitInfo = alterTableSplitPartitionModel.splitInfo
    +    val partitionId = 
Integer.parseInt(alterTableSplitPartitionModel.partitionId)
    +    val timestampFormatter = new 
SimpleDateFormat(CarbonProperties.getInstance
    +      .getProperty(CarbonCommonConstants.CARBON_TIMESTAMP_FORMAT,
    +        CarbonCommonConstants.CARBON_TIMESTAMP_DEFAULT_FORMAT))
    +    val dateFormatter = new SimpleDateFormat(CarbonProperties.getInstance
    +      .getProperty(CarbonCommonConstants.CARBON_DATE_FORMAT,
    +        CarbonCommonConstants.CARBON_DATE_DEFAULT_FORMAT))
    +
    +    val locksToBeAcquired = List(LockUsage.METADATA_LOCK,
    +      LockUsage.COMPACTION_LOCK,
    +      LockUsage.DELETE_SEGMENT_LOCK,
    +      LockUsage.DROP_TABLE_LOCK,
    +      LockUsage.CLEAN_FILES_LOCK,
    +      LockUsage.ALTER_PARTITION_LOCK)
    +    var locks = List.empty[ICarbonLock]
    +    try {
    +      locks = AlterTableUtil.validateTableAndAcquireLock(dbName, tableName,
    +        locksToBeAcquired)(sparkSession)
    +      val carbonMetastore = 
CarbonEnv.getInstance(sparkSession).carbonMetastore
    +      val relation = carbonMetastore.lookupRelation(Option(dbName), 
tableName)(sparkSession)
    +        .asInstanceOf[CarbonRelation]
    +      val carbonTableIdentifier = relation.tableMeta.carbonTableIdentifier
    +      val storePath = relation.tableMeta.storePath
    +      if (relation == null) {
    +        sys.error(s"Table $dbName.$tableName does not exist")
    +      }
    +      carbonMetastore.checkSchemasModifiedTimeAndReloadTables(storePath)
    +      if (null == CarbonMetadata.getInstance.getCarbonTable(dbName + "_" + 
tableName)) {
    +        LOGGER.error(s"Alter table failed. table not found: 
$dbName.$tableName")
    +        sys.error(s"Alter table failed. table not found: 
$dbName.$tableName")
    +      }
    +      val carbonLoadModel = new CarbonLoadModel()
    +
    +      val table = relation.tableMeta.carbonTable
    +      val partitionInfo = table.getPartitionInfo(tableName)
    +      val partitionIdList = partitionInfo.getPartitionIds.asScala
    +      // keep a copy of partitionIdList before update partitionInfo.
    +      // will be used in partition data scan
    +      val oldPartitionIdList: ArrayBuffer[Int] = new ArrayBuffer[Int]()
    +      for (i: Integer <- partitionIdList) {
    --- End diff --
    
    do not use for loop, use `map` or `addAll`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to