Search in sources :

Example 21 with TypedProperties

use of org.apache.hudi.common.config.TypedProperties in project hudi by apache.

the class TestSimpleKeyGenerator method getCommonProps.

private TypedProperties getCommonProps() {
    TypedProperties properties = new TypedProperties();
    properties.put(KeyGeneratorOptions.RECORDKEY_FIELD_NAME.key(), "_row_key");
    properties.put(KeyGeneratorOptions.HIVE_STYLE_PARTITIONING_ENABLE.key(), "true");
    return properties;
}
Also used : TypedProperties(org.apache.hudi.common.config.TypedProperties)

Example 22 with TypedProperties

use of org.apache.hudi.common.config.TypedProperties in project hudi by apache.

the class TestSimpleKeyGenerator method getPropertiesWithoutRecordKeyProp.

private TypedProperties getPropertiesWithoutRecordKeyProp() {
    TypedProperties properties = new TypedProperties();
    properties.put(KeyGeneratorOptions.PARTITIONPATH_FIELD_NAME.key(), "timestamp");
    return properties;
}
Also used : TypedProperties(org.apache.hudi.common.config.TypedProperties)

Example 23 with TypedProperties

use of org.apache.hudi.common.config.TypedProperties in project hudi by apache.

the class TestCreateKeyGeneratorByTypeWithFactory method init.

@BeforeEach
public void init() {
    props = new TypedProperties();
    props.put(KeyGeneratorOptions.RECORDKEY_FIELD_NAME.key(), "_row_key");
    props.put(KeyGeneratorOptions.HIVE_STYLE_PARTITIONING_ENABLE.key(), "true");
    props.put(KeyGeneratorOptions.PARTITIONPATH_FIELD_NAME.key(), "timestamp");
    // for timestamp based key generator
    props.put("hoodie.deltastreamer.keygen.timebased.timestamp.type", "DATE_STRING");
    props.put("hoodie.deltastreamer.keygen.timebased.input.dateformat", "yyyy-MM-dd");
    props.put("hoodie.deltastreamer.keygen.timebased.output.dateformat", "yyyyMMdd");
}
Also used : TypedProperties(org.apache.hudi.common.config.TypedProperties) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 24 with TypedProperties

use of org.apache.hudi.common.config.TypedProperties in project hudi by apache.

the class TestHoodieSparkKeyGeneratorFactory method testKeyGeneratorFactory.

@Test
public void testKeyGeneratorFactory() throws IOException {
    TypedProperties props = getCommonProps();
    // set KeyGenerator type only
    props.put(HoodieWriteConfig.KEYGENERATOR_TYPE.key(), KeyGeneratorType.SIMPLE.name());
    KeyGenerator keyGenerator = HoodieSparkKeyGeneratorFactory.createKeyGenerator(props);
    Assertions.assertEquals(SimpleKeyGenerator.class.getName(), keyGenerator.getClass().getName());
    // set KeyGenerator class only
    props = getCommonProps();
    props.put(HoodieWriteConfig.KEYGENERATOR_CLASS_NAME.key(), SimpleKeyGenerator.class.getName());
    KeyGenerator keyGenerator2 = HoodieSparkKeyGeneratorFactory.createKeyGenerator(props);
    Assertions.assertEquals(SimpleKeyGenerator.class.getName(), keyGenerator2.getClass().getName());
    // set both class name and keyGenerator type
    props.put(HoodieWriteConfig.KEYGENERATOR_TYPE.key(), KeyGeneratorType.CUSTOM.name());
    KeyGenerator keyGenerator3 = HoodieSparkKeyGeneratorFactory.createKeyGenerator(props);
    // KEYGENERATOR_TYPE_PROP was overwritten by KEYGENERATOR_CLASS_PROP
    Assertions.assertEquals(SimpleKeyGenerator.class.getName(), keyGenerator3.getClass().getName());
    // set wrong class name
    final TypedProperties props2 = getCommonProps();
    props2.put(HoodieWriteConfig.KEYGENERATOR_CLASS_NAME.key(), TestHoodieSparkKeyGeneratorFactory.class.getName());
    assertThrows(IOException.class, () -> HoodieSparkKeyGeneratorFactory.createKeyGenerator(props2));
    // set wrong keyGenerator type
    final TypedProperties props3 = getCommonProps();
    props3.put(HoodieWriteConfig.KEYGENERATOR_TYPE.key(), "wrong_type");
    assertThrows(HoodieKeyGeneratorException.class, () -> HoodieSparkKeyGeneratorFactory.createKeyGenerator(props3));
}
Also used : SimpleKeyGenerator(org.apache.hudi.keygen.SimpleKeyGenerator) TypedProperties(org.apache.hudi.common.config.TypedProperties) KeyGenerator(org.apache.hudi.keygen.KeyGenerator) TestComplexKeyGenerator(org.apache.hudi.keygen.TestComplexKeyGenerator) SimpleKeyGenerator(org.apache.hudi.keygen.SimpleKeyGenerator) Test(org.junit.jupiter.api.Test)

Example 25 with TypedProperties

use of org.apache.hudi.common.config.TypedProperties in project hudi by apache.

the class TestTypedProperties method testGetLong.

@Test
public void testGetLong() {
    Properties properties = new Properties();
    properties.put("key1", "1354354354");
    TypedProperties typedProperties = new TypedProperties(properties);
    assertEquals(1354354354, typedProperties.getLong("key1"));
    assertEquals(1354354354, typedProperties.getLong("key1", 8578494434L));
    assertEquals(8578494434L, typedProperties.getLong("key2", 8578494434L));
}
Also used : Properties(java.util.Properties) TypedProperties(org.apache.hudi.common.config.TypedProperties) TypedProperties(org.apache.hudi.common.config.TypedProperties) Test(org.junit.jupiter.api.Test)

Aggregations

TypedProperties (org.apache.hudi.common.config.TypedProperties)143 Test (org.junit.jupiter.api.Test)47 HoodieTestDataGenerator (org.apache.hudi.common.testutils.HoodieTestDataGenerator)22 JavaRDD (org.apache.spark.api.java.JavaRDD)16 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 IOException (java.io.IOException)14 Path (org.apache.hadoop.fs.Path)14 Properties (java.util.Properties)13 GenericRecord (org.apache.avro.generic.GenericRecord)13 SourceFormatAdapter (org.apache.hudi.utilities.deltastreamer.SourceFormatAdapter)12 Row (org.apache.spark.sql.Row)12 BeforeEach (org.junit.jupiter.api.BeforeEach)11 ArrayList (java.util.ArrayList)10 HoodieTableMetaClient (org.apache.hudi.common.table.HoodieTableMetaClient)10 HoodieKey (org.apache.hudi.common.model.HoodieKey)9 DFSPropertiesConfiguration (org.apache.hudi.common.config.DFSPropertiesConfiguration)8 HoodieWriteConfig (org.apache.hudi.config.HoodieWriteConfig)8 HoodieIOException (org.apache.hudi.exception.HoodieIOException)8 Dataset (org.apache.spark.sql.Dataset)8 HoodieRecord (org.apache.hudi.common.model.HoodieRecord)7