Github user kunal642 commented on a diff in the pull request:
https://github.com/apache/carbondata/pull/2109#discussion_r178801803
--- Diff:
integration/spark2/src/main/scala/org/apache/spark/sql/execution/command/preaaggregate/PreAggregateListeners.scala
---
@@ -39,6 +41,212 @@ import
org.apache.carbondata.core.util.path.CarbonTablePath
import org.apache.carbondata.events._
import
org.apache.carbondata.processing.loading.events.LoadEvents.{LoadMetadataEvent,
LoadTablePostExecutionEvent, LoadTablePostStatusUpdateEvent,
LoadTablePreExecutionEvent, LoadTablePreStatusUpdateEvent}
+object AlterTableDropPartitionPreStatusListener extends
OperationEventListener {
+ /**
+ * Called on a specified event occurrence
+ *
+ * @param event
+ * @param operationContext
+ */
+ override protected def onEvent(event: Event,
+ operationContext: OperationContext) = {
+ val preStatusListener =
event.asInstanceOf[AlterTableDropPartitionPreStatusEvent]
+ val carbonTable = preStatusListener.carbonTable
+ val childDropPartitionCommands =
operationContext.getProperty("dropPartitionCommands")
+ if (childDropPartitionCommands != null &&
carbonTable.hasAggregationDataMap) {
+ val childCommands =
+
childDropPartitionCommands.asInstanceOf[Seq[CarbonAlterTableDropHivePartitionCommand]]
+
childCommands.foreach(_.processData(SparkSession.getActiveSession.get))
+ }
+ }
+}
+
+trait CommitHelper {
+
+ val LOGGER: LogService =
LogServiceFactory.getLogService(this.getClass.getName)
+
+ protected def markInProgressSegmentAsDeleted(tableStatusFile: String,
+ operationContext: OperationContext,
+ carbonTable: CarbonTable): Unit = {
+ val loadMetaDataDetails =
SegmentStatusManager.readTableStatusFile(tableStatusFile)
+ val segmentBeingLoaded =
+ operationContext.getProperty(carbonTable.getTableUniqueName +
"_Segment").toString
+ val newDetails = loadMetaDataDetails.collect {
+ case detail if
detail.getLoadName.equalsIgnoreCase(segmentBeingLoaded) =>
+ detail.setSegmentStatus(SegmentStatus.MARKED_FOR_DELETE)
+ detail
+ case others => others
+ }
+ SegmentStatusManager.writeLoadDetailsIntoFile(tableStatusFile,
newDetails)
+ }
+
+ /**
+ * Used to rename table status files for commit operation.
+ */
+ protected def renameDataMapTableStatusFiles(sourceFileName: String,
+ destinationFileName: String, uuid: String): Boolean = {
+ val oldCarbonFile = FileFactory.getCarbonFile(sourceFileName)
+ val newCarbonFile = FileFactory.getCarbonFile(destinationFileName)
+ if (oldCarbonFile.exists() && newCarbonFile.exists()) {
+ val backUpPostFix = if (uuid.nonEmpty) {
+ "_backup_" + uuid
+ } else {
--- End diff --
done
---