satishkotha commented on a change in pull request #2048:
URL: https://github.com/apache/hudi/pull/2048#discussion_r488216199



##########
File path: 
hudi-client/src/main/java/org/apache/hudi/table/action/commit/InsertOverwriteCommitActionExecutor.java
##########
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hudi.table.action.commit;
+
+import org.apache.hudi.client.WriteStatus;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.model.HoodieRecordPayload;
+import org.apache.hudi.common.model.HoodieWriteStat;
+import org.apache.hudi.common.model.WriteOperationType;
+import org.apache.hudi.common.table.timeline.HoodieTimeline;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.table.HoodieTable;
+import org.apache.hudi.table.WorkloadProfile;
+import org.apache.hudi.table.action.HoodieWriteMetadata;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+import org.apache.spark.Partitioner;
+import org.apache.spark.api.java.JavaRDD;
+import org.apache.spark.api.java.JavaSparkContext;
+
+import java.util.ArrayList;
+import java.util.stream.Stream;
+
+public class InsertOverwriteCommitActionExecutor<T extends 
HoodieRecordPayload<T>>
+    extends CommitActionExecutor<T> {
+
+  private static final Logger LOG = 
LogManager.getLogger(InsertOverwriteCommitActionExecutor.class);
+
+  private final JavaRDD<HoodieRecord<T>> inputRecordsRDD;
+
+  public InsertOverwriteCommitActionExecutor(JavaSparkContext jsc,
+                                             HoodieWriteConfig config, 
HoodieTable table,
+                                             String instantTime, 
JavaRDD<HoodieRecord<T>> inputRecordsRDD) {
+    super(jsc, config, table, instantTime, 
WriteOperationType.INSERT_OVERWRITE);
+    this.inputRecordsRDD = inputRecordsRDD;
+  }
+
+  @Override
+  public HoodieWriteMetadata execute() {
+    return WriteHelper.write(instantTime, inputRecordsRDD, jsc, 
(HoodieTable<T>) table,
+        config.shouldCombineBeforeInsert(), 
config.getInsertShuffleParallelism(), this, false);
+  }
+
+  @Override
+  protected Partitioner getPartitioner(WorkloadProfile profile) {
+    return new InsertOverwritePartitioner<>(profile, jsc, table, config);
+  }
+
+  @Override
+  protected String getCommitActionType() {
+    return HoodieTimeline.REPLACE_COMMIT_ACTION;
+  }
+
+  @Override
+  protected JavaRDD<WriteStatus> processInputRecords(JavaRDD<HoodieRecord<T>> 
inputRecordsRDD, WorkloadProfile profile) {
+    // get all existing fileIds to mark them as replaced
+    JavaRDD<WriteStatus> replaceStatuses = getAllReplaceWriteStatus(profile);
+    // do necessary inserts into new file groups
+    JavaRDD<WriteStatus> writeStatuses = 
super.processInputRecords(inputRecordsRDD, profile);
+    return writeStatuses.union(replaceStatuses);
+  }
+
+  private JavaRDD<WriteStatus> getAllReplaceWriteStatus(WorkloadProfile 
profile) {
+    JavaRDD<String> partitions = jsc.parallelize(new 
ArrayList<>(profile.getPartitionPaths()));
+    JavaRDD<WriteStatus> replaceStatuses = partitions.flatMap(partition ->
+        getAllExistingFileIds(partition).map(fileId -> 
getReplaceWriteStatus(partition, fileId)).iterator());
+
+    return replaceStatuses;
+  }
+
+  private Stream<String> getAllExistingFileIds(String partitionPath) {
+    // because new commit is not complete. it is safe to mark all base files 
as old files
+    return 
table.getBaseFileOnlyView().getAllBaseFiles(partitionPath).map(baseFile -> 
baseFile.getFileId());

Review comment:
       My bad, missed that insert into log files case. I fixed it now. thanks 
for finding this bug.




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


Reply via email to