You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by GitBox <gi...@apache.org> on 2021/01/17 03:39:08 UTC

[GitHub] [hudi] lw309637554 commented on a change in pull request #2452: [HUDI-1531] Introduce HoodiePartitionCleaner to delete specific parti…

lw309637554 commented on a change in pull request #2452:
URL: https://github.com/apache/hudi/pull/2452#discussion_r559072569



##########
File path: hudi-utilities/src/main/java/org/apache/hudi/utilities/HoodiePartitionCleaner.java
##########
@@ -0,0 +1,142 @@
+/*
+ * 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.utilities;
+
+import org.apache.hudi.client.HoodieWriteResult;
+import org.apache.hudi.client.SparkRDDWriteClient;
+import org.apache.hudi.client.common.HoodieSparkEngineContext;
+import org.apache.hudi.common.config.TypedProperties;
+import org.apache.hudi.common.fs.FSUtils;
+import org.apache.hudi.common.table.timeline.HoodieActiveTimeline;
+import org.apache.hudi.common.table.timeline.HoodieTimeline;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.config.HoodieWriteConfig;
+
+import com.beust.jcommander.JCommander;
+import com.beust.jcommander.Parameter;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hudi.exception.HoodieException;
+import org.apache.log4j.LogManager;
+import org.apache.log4j.Logger;
+import org.apache.spark.api.java.JavaSparkContext;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Util Class help to delete hoodie data in specific partition.
+ */
+public class HoodiePartitionCleaner {
+
+  private static final Logger LOG = LogManager.getLogger(HoodiePartitionCleaner.class);
+
+  /**
+   * Config for Cleaner.
+   */
+  private final Config cfg;
+
+  /**
+   * Spark context.
+   */
+  private transient JavaSparkContext jssc;
+
+  /**
+   * Bag of properties with source, hoodie client etc.
+   */
+  private TypedProperties props;
+
+  public HoodiePartitionCleaner(Config cfg, JavaSparkContext jssc) {
+    this.cfg = cfg;
+    this.jssc = jssc;
+    /*
+     * Filesystem used.
+     */
+    FileSystem fs = FSUtils.getFs(cfg.basePath, jssc.hadoopConfiguration());
+    this.props = cfg.propsFilePath == null ? UtilHelpers.buildProperties(cfg.configs)
+        : UtilHelpers.readConfig(fs, new Path(cfg.propsFilePath), cfg.configs).getConfig();
+    LOG.info("Creating Cleaner with configs : " + props.toString());
+  }
+
+  public void run() {
+    HoodieWriteConfig hoodieCfg = getHoodieClientConfig();
+    SparkRDDWriteClient client = new SparkRDDWriteClient<>(new HoodieSparkEngineContext(jssc), hoodieCfg, true);
+    String cleanInstant = HoodieActiveTimeline.createNewInstantTime();
+    client.startCommitWithTime(cleanInstant, HoodieTimeline.REPLACE_COMMIT_ACTION);

Review comment:
       1.now with replace_commit_action at incremental scenario also  have some issues, please pay attention.
   2. can link the issue to https://issues.apache.org/jira/browse/HUDI-1042




----------------------------------------------------------------
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:
users@infra.apache.org