[HUDI-1930] Bootstrap support configure KeyGenerator by type (#3170)
* [HUDI-1930] Bootstrap support configure KeyGenerator by type
This commit is contained in:
@@ -25,6 +25,7 @@ import org.apache.hudi.common.bootstrap.index.HFileBootstrapIndex;
|
||||
import org.apache.hudi.common.config.ConfigProperty;
|
||||
import org.apache.hudi.common.config.HoodieConfig;
|
||||
import org.apache.hudi.common.table.HoodieTableConfig;
|
||||
import org.apache.hudi.keygen.constant.KeyGeneratorType;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
@@ -60,6 +61,12 @@ public class HoodieBootstrapConfig extends HoodieConfig {
|
||||
.sinceVersion("0.6.0")
|
||||
.withDocumentation("Key generator implementation to be used for generating keys from the bootstrapped dataset");
|
||||
|
||||
public static final ConfigProperty<String> BOOTSTRAP_KEYGEN_TYPE = ConfigProperty
|
||||
.key("hoodie.bootstrap.keygen.type")
|
||||
.defaultValue(KeyGeneratorType.SIMPLE.name())
|
||||
.sinceVersion("0.9.0")
|
||||
.withDocumentation("Type of build-in key generator, currently support SIMPLE, COMPLEX, TIMESTAMP, CUSTOM, NON_PARTITION, GLOBAL_DELETE");
|
||||
|
||||
public static final ConfigProperty<String> BOOTSTRAP_PARTITION_PATH_TRANSLATOR_CLASS = ConfigProperty
|
||||
.key("hoodie.bootstrap.partitionpath.translator.class")
|
||||
.defaultValue(IdentityBootstrapPartitionPathTranslator.class.getName())
|
||||
@@ -131,6 +138,11 @@ public class HoodieBootstrapConfig extends HoodieConfig {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withBootstrapKeyGenType(String keyGenType) {
|
||||
bootstrapConfig.setValue(BOOTSTRAP_KEYGEN_TYPE, keyGenType);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withBootstrapPartitionPathTranslatorClass(String partitionPathTranslatorClass) {
|
||||
bootstrapConfig
|
||||
.setValue(BOOTSTRAP_PARTITION_PATH_TRANSLATOR_CLASS, partitionPathTranslatorClass);
|
||||
|
||||
@@ -1126,6 +1126,10 @@ public class HoodieWriteConfig extends HoodieConfig {
|
||||
return getString(HoodieBootstrapConfig.BOOTSTRAP_KEYGEN_CLASS);
|
||||
}
|
||||
|
||||
public String getBootstrapKeyGeneratorType() {
|
||||
return getString(HoodieBootstrapConfig.BOOTSTRAP_KEYGEN_TYPE);
|
||||
}
|
||||
|
||||
public String getBootstrapModeSelectorRegex() {
|
||||
return getString(HoodieBootstrapConfig.BOOTSTRAP_MODE_SELECTOR_REGEX);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,10 @@
|
||||
|
||||
package org.apache.hudi.keygen.constant;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Types of {@link org.apache.hudi.keygen.KeyGenerator}.
|
||||
*/
|
||||
@@ -55,5 +59,12 @@ public enum KeyGeneratorType {
|
||||
/**
|
||||
* Key generator for deletes using global indices.
|
||||
*/
|
||||
GLOBAL_DELETE
|
||||
GLOBAL_DELETE;
|
||||
|
||||
public static List<String> getNames() {
|
||||
List<String> names = new ArrayList<>(KeyGeneratorType.values().length);
|
||||
Arrays.stream(KeyGeneratorType.values())
|
||||
.forEach(x -> names.add(x.name()));
|
||||
return names;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package org.apache.hudi.keygen.factory;
|
||||
|
||||
import org.apache.hudi.common.config.TypedProperties;
|
||||
import org.apache.hudi.common.util.StringUtils;
|
||||
import org.apache.hudi.config.HoodieWriteConfig;
|
||||
import org.apache.hudi.exception.HoodieKeyGeneratorException;
|
||||
import org.apache.hudi.keygen.ComplexAvroKeyGenerator;
|
||||
@@ -30,6 +31,9 @@ import org.apache.hudi.keygen.SimpleAvroKeyGenerator;
|
||||
import org.apache.hudi.keygen.TimestampBasedAvroKeyGenerator;
|
||||
import org.apache.hudi.keygen.constant.KeyGeneratorType;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
@@ -41,6 +45,9 @@ import java.util.Objects;
|
||||
* will not be overwritten by {@link KeyGeneratorType}
|
||||
*/
|
||||
public class HoodieAvroKeyGeneratorFactory {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(HoodieAvroKeyGeneratorFactory.class);
|
||||
|
||||
public static KeyGenerator createKeyGenerator(TypedProperties props) throws IOException {
|
||||
// keyGenerator class name has higher priority
|
||||
KeyGenerator keyGenerator = KeyGenUtils.createKeyGeneratorByClassName(props);
|
||||
@@ -50,7 +57,12 @@ public class HoodieAvroKeyGeneratorFactory {
|
||||
private static KeyGenerator createAvroKeyGeneratorByType(TypedProperties props) throws IOException {
|
||||
// Use KeyGeneratorType.SIMPLE as default keyGeneratorType
|
||||
String keyGeneratorType =
|
||||
props.getString(HoodieWriteConfig.KEYGENERATOR_TYPE_PROP.key(), KeyGeneratorType.SIMPLE.name());
|
||||
props.getString(HoodieWriteConfig.KEYGENERATOR_TYPE_PROP.key(), null);
|
||||
|
||||
if (StringUtils.isNullOrEmpty(keyGeneratorType)) {
|
||||
LOG.info("The value of {} is empty, use SIMPLE", HoodieWriteConfig.KEYGENERATOR_TYPE_PROP.key());
|
||||
keyGeneratorType = KeyGeneratorType.SIMPLE.name();
|
||||
}
|
||||
|
||||
KeyGeneratorType keyGeneratorTypeEnum;
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user