1
0

[HUDI-3283] Bootstrap support overwrite existing table (#4647)

This commit is contained in:
wangxianghu
2022-01-20 14:42:52 +04:00
committed by GitHub
parent 31b57a256f
commit b7a79aa943
2 changed files with 18 additions and 8 deletions

View File

@@ -97,6 +97,7 @@ public class BootstrapExecutor implements Serializable {
/** /**
* Bootstrap Executor. * Bootstrap Executor.
*
* @param cfg DeltaStreamer Config * @param cfg DeltaStreamer Config
* @param jssc Java Spark Context * @param jssc Java Spark Context
* @param fs File System * @param fs File System
@@ -168,10 +169,16 @@ public class BootstrapExecutor implements Serializable {
} }
private void initializeTable() throws IOException { private void initializeTable() throws IOException {
if (fs.exists(new Path(cfg.targetBasePath))) { Path basePath = new Path(cfg.targetBasePath);
if (fs.exists(basePath)) {
if (cfg.bootstrapOverwrite) {
LOG.warn("Target base path already exists, overwrite it");
fs.delete(basePath, true);
} else {
throw new HoodieException("target base path already exists at " + cfg.targetBasePath throw new HoodieException("target base path already exists at " + cfg.targetBasePath
+ ". Cannot bootstrap data on top of an existing table"); + ". Cannot bootstrap data on top of an existing table");
} }
}
HoodieTableMetaClient.withPropertyBuilder() HoodieTableMetaClient.withPropertyBuilder()
.setTableType(cfg.tableType) .setTableType(cfg.tableType)
.setTableName(cfg.targetTableName) .setTableName(cfg.targetTableName)

View File

@@ -363,6 +363,9 @@ public class HoodieDeltaStreamer implements Serializable {
@Parameter(names = {"--run-bootstrap"}, description = "Run bootstrap if bootstrap index is not found") @Parameter(names = {"--run-bootstrap"}, description = "Run bootstrap if bootstrap index is not found")
public Boolean runBootstrap = false; public Boolean runBootstrap = false;
@Parameter(names = {"--bootstrap-overwrite"}, description = "Overwrite existing target table, default false")
public Boolean bootstrapOverwrite = false;
@Parameter(names = {"--bootstrap-index-class"}, description = "subclass of BootstrapIndex") @Parameter(names = {"--bootstrap-index-class"}, description = "subclass of BootstrapIndex")
public String bootstrapIndexClass = HFileBootstrapIndex.class.getName(); public String bootstrapIndexClass = HFileBootstrapIndex.class.getName();