jackylk commented on a change in pull request #3542: [CARBONDATA-3640] Insert 
from stage command support partition table
URL: https://github.com/apache/carbondata/pull/3542#discussion_r361827670
 
 

 ##########
 File path: 
integration/spark2/src/main/scala/org/apache/spark/sql/execution/command/management/CarbonInsertFromStageCommand.scala
 ##########
 @@ -269,11 +281,90 @@ case class CarbonInsertFromStageCommand(
       SparkSQLUtil.sessionState(spark).newHadoopConf()
     ).map { row =>
         (row._1, FailureCauses.NONE == row._2._2.failureCauses)
-      }
+    }
+
+    LOGGER.info(s"finish data loading, time taken ${System.currentTimeMillis() 
- start}ms")
+  }
+
+  /**
+   * Start global sort loading of partition table
+   */
+  private def startLoadingWithPartition(
+      spark: SparkSession,
+      table: CarbonTable,
+      loadModel: CarbonLoadModel,
+      stageInput: Seq[StageInput]
+    ): Unit = {
+    val partitionDataList = listPartitionFiles(stageInput)
+    val start = System.currentTimeMillis()
+    var index = 0
+    partitionDataList.map(
+      partitionData => {
+        index = index + 1
+        val partition = partitionData._1
+        val splits = partitionData._2
+        LOGGER.info(s"start to load ${splits.size} files into " +
+          s"${table.getDatabaseName}.${table.getTableName}")
+        val dataFrame = createInputDataFrameOfInternalRow(spark, table, splits)
+        val columns = dataFrame.columns
+        val header = columns.mkString(",")
+        val selectColumns = columns.filter(!partition.contains(_))
+        val selectedDataFrame = dataFrame.select(selectColumns.head, 
selectColumns.tail : _*)
 
+        val loadCommand = CarbonLoadDataCommand(
+          databaseNameOp = Option(table.getDatabaseName),
+          tableName = table.getTableName,
+          factPathFromUser = null,
+          dimFilesPath = Seq(),
+          options = scala.collection.immutable.Map("fileheader" -> header),
+          isOverwriteTable = false,
+          inputSqlString = null,
+          dataFrame = Some(selectedDataFrame),
+          updateModel = None,
+          tableInfoOp = None,
+          internalOptions = Map.empty,
+          partition = partition
+        )
+        loadCommand.run(spark)
+      }
+    )
     LOGGER.info(s"finish data loading, time taken ${System.currentTimeMillis() 
- start}ms")
   }
 
+  private def listPartitionFiles(stageInputs : Seq[StageInput]):
 
 Review comment:
   describe the return tuple in comment

----------------------------------------------------------------
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


With regards,
Apache Git Services

Reply via email to