Search in sources :

Example 1 with KeyGeneratorType

use of org.apache.hudi.keygen.constant.KeyGeneratorType in project hudi by apache.

the class TestCreateAvroKeyGeneratorByTypeWithFactory method testKeyGeneratorTypes.

@ParameterizedTest
@MethodSource("configParams")
public void testKeyGeneratorTypes(String keyGenType) throws IOException {
    props.put(HoodieWriteConfig.KEYGENERATOR_TYPE.key(), keyGenType);
    KeyGeneratorType keyType = KeyGeneratorType.valueOf(keyGenType);
    KeyGenerator keyGenerator = HoodieAvroKeyGeneratorFactory.createKeyGenerator(props);
    switch(keyType) {
        case SIMPLE:
            Assertions.assertEquals(SimpleAvroKeyGenerator.class.getName(), keyGenerator.getClass().getName());
            return;
        case COMPLEX:
            Assertions.assertEquals(ComplexAvroKeyGenerator.class.getName(), keyGenerator.getClass().getName());
            return;
        case TIMESTAMP:
            Assertions.assertEquals(TimestampBasedAvroKeyGenerator.class.getName(), keyGenerator.getClass().getName());
            return;
        case CUSTOM:
            Assertions.assertEquals(CustomAvroKeyGenerator.class.getName(), keyGenerator.getClass().getName());
            return;
        case NON_PARTITION:
            Assertions.assertEquals(NonpartitionedAvroKeyGenerator.class.getName(), keyGenerator.getClass().getName());
            return;
        case GLOBAL_DELETE:
            Assertions.assertEquals(GlobalAvroDeleteKeyGenerator.class.getName(), keyGenerator.getClass().getName());
            return;
        default:
            throw new HoodieKeyGeneratorException("Unsupported keyGenerator Type " + keyGenType);
    }
}
Also used : HoodieKeyGeneratorException(org.apache.hudi.exception.HoodieKeyGeneratorException) TimestampBasedAvroKeyGenerator(org.apache.hudi.keygen.TimestampBasedAvroKeyGenerator) CustomAvroKeyGenerator(org.apache.hudi.keygen.CustomAvroKeyGenerator) ComplexAvroKeyGenerator(org.apache.hudi.keygen.ComplexAvroKeyGenerator) NonpartitionedAvroKeyGenerator(org.apache.hudi.keygen.NonpartitionedAvroKeyGenerator) SimpleAvroKeyGenerator(org.apache.hudi.keygen.SimpleAvroKeyGenerator) KeyGeneratorType(org.apache.hudi.keygen.constant.KeyGeneratorType) NonpartitionedAvroKeyGenerator(org.apache.hudi.keygen.NonpartitionedAvroKeyGenerator) SimpleAvroKeyGenerator(org.apache.hudi.keygen.SimpleAvroKeyGenerator) KeyGenerator(org.apache.hudi.keygen.KeyGenerator) ComplexAvroKeyGenerator(org.apache.hudi.keygen.ComplexAvroKeyGenerator) GlobalAvroDeleteKeyGenerator(org.apache.hudi.keygen.GlobalAvroDeleteKeyGenerator) TimestampBasedAvroKeyGenerator(org.apache.hudi.keygen.TimestampBasedAvroKeyGenerator) CustomAvroKeyGenerator(org.apache.hudi.keygen.CustomAvroKeyGenerator) GlobalAvroDeleteKeyGenerator(org.apache.hudi.keygen.GlobalAvroDeleteKeyGenerator) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with KeyGeneratorType

use of org.apache.hudi.keygen.constant.KeyGeneratorType in project hudi by apache.

the class HoodieAvroKeyGeneratorFactory method createAvroKeyGeneratorByType.

private static KeyGenerator createAvroKeyGeneratorByType(TypedProperties props) throws IOException {
    // Use KeyGeneratorType.SIMPLE as default keyGeneratorType
    String keyGeneratorType = props.getString(HoodieWriteConfig.KEYGENERATOR_TYPE.key(), null);
    if (StringUtils.isNullOrEmpty(keyGeneratorType)) {
        LOG.info("The value of {} is empty, using SIMPLE", HoodieWriteConfig.KEYGENERATOR_TYPE.key());
        keyGeneratorType = KeyGeneratorType.SIMPLE.name();
    }
    KeyGeneratorType keyGeneratorTypeEnum;
    try {
        keyGeneratorTypeEnum = KeyGeneratorType.valueOf(keyGeneratorType.toUpperCase(Locale.ROOT));
    } catch (IllegalArgumentException e) {
        throw new HoodieKeyGeneratorException("Unsupported keyGenerator Type " + keyGeneratorType);
    }
    switch(keyGeneratorTypeEnum) {
        case SIMPLE:
            return new SimpleAvroKeyGenerator(props);
        case COMPLEX:
            return new ComplexAvroKeyGenerator(props);
        case TIMESTAMP:
            return new TimestampBasedAvroKeyGenerator(props);
        case CUSTOM:
            return new CustomAvroKeyGenerator(props);
        case NON_PARTITION:
            return new NonpartitionedAvroKeyGenerator(props);
        case GLOBAL_DELETE:
            return new GlobalAvroDeleteKeyGenerator(props);
        default:
            throw new HoodieKeyGeneratorException("Unsupported keyGenerator Type " + keyGeneratorType);
    }
}
Also used : HoodieKeyGeneratorException(org.apache.hudi.exception.HoodieKeyGeneratorException) TimestampBasedAvroKeyGenerator(org.apache.hudi.keygen.TimestampBasedAvroKeyGenerator) CustomAvroKeyGenerator(org.apache.hudi.keygen.CustomAvroKeyGenerator) ComplexAvroKeyGenerator(org.apache.hudi.keygen.ComplexAvroKeyGenerator) NonpartitionedAvroKeyGenerator(org.apache.hudi.keygen.NonpartitionedAvroKeyGenerator) SimpleAvroKeyGenerator(org.apache.hudi.keygen.SimpleAvroKeyGenerator) KeyGeneratorType(org.apache.hudi.keygen.constant.KeyGeneratorType) GlobalAvroDeleteKeyGenerator(org.apache.hudi.keygen.GlobalAvroDeleteKeyGenerator)

Example 3 with KeyGeneratorType

use of org.apache.hudi.keygen.constant.KeyGeneratorType in project hudi by apache.

the class TestCreateKeyGeneratorByTypeWithFactory method testKeyGeneratorTypes.

@ParameterizedTest
@MethodSource("configParams")
public void testKeyGeneratorTypes(String keyGenType) throws IOException {
    props.put(HoodieWriteConfig.KEYGENERATOR_TYPE.key(), keyGenType);
    KeyGeneratorType keyType = KeyGeneratorType.valueOf(keyGenType);
    KeyGenerator keyGenerator = HoodieSparkKeyGeneratorFactory.createKeyGenerator(props);
    switch(keyType) {
        case SIMPLE:
            Assertions.assertEquals(SimpleKeyGenerator.class.getName(), keyGenerator.getClass().getName());
            return;
        case COMPLEX:
            Assertions.assertEquals(ComplexKeyGenerator.class.getName(), keyGenerator.getClass().getName());
            return;
        case TIMESTAMP:
            Assertions.assertEquals(TimestampBasedKeyGenerator.class.getName(), keyGenerator.getClass().getName());
            return;
        case CUSTOM:
            Assertions.assertEquals(CustomKeyGenerator.class.getName(), keyGenerator.getClass().getName());
            return;
        case NON_PARTITION:
            Assertions.assertEquals(NonpartitionedKeyGenerator.class.getName(), keyGenerator.getClass().getName());
            return;
        case GLOBAL_DELETE:
            Assertions.assertEquals(GlobalDeleteKeyGenerator.class.getName(), keyGenerator.getClass().getName());
            return;
        default:
            throw new HoodieKeyGeneratorException("Unsupported keyGenerator Type " + keyGenType);
    }
}
Also used : HoodieKeyGeneratorException(org.apache.hudi.exception.HoodieKeyGeneratorException) GlobalDeleteKeyGenerator(org.apache.hudi.keygen.GlobalDeleteKeyGenerator) CustomKeyGenerator(org.apache.hudi.keygen.CustomKeyGenerator) ComplexKeyGenerator(org.apache.hudi.keygen.ComplexKeyGenerator) TimestampBasedKeyGenerator(org.apache.hudi.keygen.TimestampBasedKeyGenerator) SimpleKeyGenerator(org.apache.hudi.keygen.SimpleKeyGenerator) KeyGeneratorType(org.apache.hudi.keygen.constant.KeyGeneratorType) CustomKeyGenerator(org.apache.hudi.keygen.CustomKeyGenerator) TimestampBasedKeyGenerator(org.apache.hudi.keygen.TimestampBasedKeyGenerator) ComplexKeyGenerator(org.apache.hudi.keygen.ComplexKeyGenerator) SimpleKeyGenerator(org.apache.hudi.keygen.SimpleKeyGenerator) GlobalDeleteKeyGenerator(org.apache.hudi.keygen.GlobalDeleteKeyGenerator) KeyGenerator(org.apache.hudi.keygen.KeyGenerator) NonpartitionedKeyGenerator(org.apache.hudi.keygen.NonpartitionedKeyGenerator) NonpartitionedKeyGenerator(org.apache.hudi.keygen.NonpartitionedKeyGenerator) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 4 with KeyGeneratorType

use of org.apache.hudi.keygen.constant.KeyGeneratorType in project hudi by apache.

the class HoodieSparkKeyGeneratorFactory method getKeyGeneratorClassName.

public static String getKeyGeneratorClassName(TypedProperties props) {
    String keyGeneratorClass = props.getString(HoodieWriteConfig.KEYGENERATOR_CLASS_NAME.key(), null);
    if (StringUtils.isNullOrEmpty(keyGeneratorClass)) {
        String keyGeneratorType = props.getString(HoodieWriteConfig.KEYGENERATOR_TYPE.key(), KeyGeneratorType.SIMPLE.name());
        LOG.info("The value of {} is empty, use SIMPLE", HoodieWriteConfig.KEYGENERATOR_TYPE.key());
        KeyGeneratorType keyGeneratorTypeEnum;
        try {
            keyGeneratorTypeEnum = KeyGeneratorType.valueOf(keyGeneratorType.toUpperCase(Locale.ROOT));
        } catch (IllegalArgumentException e) {
            throw new HoodieKeyGeneratorException("Unsupported keyGenerator Type " + keyGeneratorType);
        }
        switch(keyGeneratorTypeEnum) {
            case SIMPLE:
                keyGeneratorClass = SimpleKeyGenerator.class.getName();
                break;
            case COMPLEX:
                keyGeneratorClass = ComplexKeyGenerator.class.getName();
                break;
            case TIMESTAMP:
                keyGeneratorClass = TimestampBasedKeyGenerator.class.getName();
                break;
            case CUSTOM:
                keyGeneratorClass = CustomKeyGenerator.class.getName();
                break;
            case NON_PARTITION:
                keyGeneratorClass = NonpartitionedKeyGenerator.class.getName();
                break;
            case GLOBAL_DELETE:
                keyGeneratorClass = GlobalDeleteKeyGenerator.class.getName();
                break;
            default:
                throw new HoodieKeyGeneratorException("Unsupported keyGenerator Type " + keyGeneratorType);
        }
    }
    return keyGeneratorClass;
}
Also used : HoodieKeyGeneratorException(org.apache.hudi.exception.HoodieKeyGeneratorException) GlobalDeleteKeyGenerator(org.apache.hudi.keygen.GlobalDeleteKeyGenerator) CustomKeyGenerator(org.apache.hudi.keygen.CustomKeyGenerator) ComplexKeyGenerator(org.apache.hudi.keygen.ComplexKeyGenerator) TimestampBasedKeyGenerator(org.apache.hudi.keygen.TimestampBasedKeyGenerator) SimpleKeyGenerator(org.apache.hudi.keygen.SimpleKeyGenerator) KeyGeneratorType(org.apache.hudi.keygen.constant.KeyGeneratorType) NonpartitionedKeyGenerator(org.apache.hudi.keygen.NonpartitionedKeyGenerator)

Aggregations

HoodieKeyGeneratorException (org.apache.hudi.exception.HoodieKeyGeneratorException)4 KeyGeneratorType (org.apache.hudi.keygen.constant.KeyGeneratorType)4 ComplexAvroKeyGenerator (org.apache.hudi.keygen.ComplexAvroKeyGenerator)2 ComplexKeyGenerator (org.apache.hudi.keygen.ComplexKeyGenerator)2 CustomAvroKeyGenerator (org.apache.hudi.keygen.CustomAvroKeyGenerator)2 CustomKeyGenerator (org.apache.hudi.keygen.CustomKeyGenerator)2 GlobalAvroDeleteKeyGenerator (org.apache.hudi.keygen.GlobalAvroDeleteKeyGenerator)2 GlobalDeleteKeyGenerator (org.apache.hudi.keygen.GlobalDeleteKeyGenerator)2 KeyGenerator (org.apache.hudi.keygen.KeyGenerator)2 NonpartitionedAvroKeyGenerator (org.apache.hudi.keygen.NonpartitionedAvroKeyGenerator)2 NonpartitionedKeyGenerator (org.apache.hudi.keygen.NonpartitionedKeyGenerator)2 SimpleAvroKeyGenerator (org.apache.hudi.keygen.SimpleAvroKeyGenerator)2 SimpleKeyGenerator (org.apache.hudi.keygen.SimpleKeyGenerator)2 TimestampBasedAvroKeyGenerator (org.apache.hudi.keygen.TimestampBasedAvroKeyGenerator)2 TimestampBasedKeyGenerator (org.apache.hudi.keygen.TimestampBasedKeyGenerator)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2