Search in sources :

Example 26 with TypedProperties

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

the class TestTypedProperties method testGetInteger.

@Test
public void testGetInteger() {
    Properties properties = new Properties();
    properties.put("key1", "123");
    TypedProperties typedProperties = new TypedProperties(properties);
    assertEquals(123, typedProperties.getInteger("key1"));
    assertEquals(123, typedProperties.getInteger("key1", 456));
    assertEquals(456, typedProperties.getInteger("key2", 456));
}
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)

Example 27 with TypedProperties

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

the class TestTypedProperties method testGetDouble.

@Test
public void testGetDouble() {
    Properties properties = new Properties();
    properties.put("key1", "123.4");
    TypedProperties typedProperties = new TypedProperties(properties);
    assertEquals(123.4, typedProperties.getDouble("key1"));
    assertEquals(123.4, typedProperties.getDouble("key1", 0.001D));
    assertEquals(0.001D, typedProperties.getDouble("key2", 0.001D));
}
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)

Example 28 with TypedProperties

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

the class TestTypedProperties method testGetBoolean.

@Test
public void testGetBoolean() {
    Properties properties = new Properties();
    properties.put("key1", "true");
    TypedProperties typedProperties = new TypedProperties(properties);
    assertTrue(typedProperties.getBoolean("key1"));
    assertTrue(typedProperties.getBoolean("key1", false));
    assertFalse(typedProperties.getBoolean("key2", false));
    // test getBoolean with non-string value for key2
    properties.put("key2", true);
    typedProperties = new TypedProperties(properties);
    assertTrue(typedProperties.getBoolean("key1", false));
    assertTrue(typedProperties.getBoolean("key2", false));
    // put non-string value in TypedProperties
    typedProperties.put("key3", true);
    assertTrue(typedProperties.getBoolean("key3", false));
}
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)

Example 29 with TypedProperties

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

the class TestTypedProperties method testGetString.

@Test
public void testGetString() {
    Properties properties = new Properties();
    properties.put("key1", "value1");
    TypedProperties typedProperties = new TypedProperties(properties);
    assertEquals("value1", typedProperties.getString("key1"));
    assertEquals("value1", typedProperties.getString("key1", "default"));
    assertEquals("default", typedProperties.getString("key2", "default"));
}
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)

Example 30 with TypedProperties

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

the class SparkMain method doBootstrap.

private static int doBootstrap(JavaSparkContext jsc, String tableName, String tableType, String basePath, String sourcePath, String recordKeyCols, String partitionFields, String parallelism, String schemaProviderClass, String bootstrapIndexClass, String selectorClass, String keyGenerator, String fullBootstrapInputProvider, String payloadClassName, String enableHiveSync, String propsFilePath, List<String> configs) throws IOException {
    TypedProperties properties = propsFilePath == null ? UtilHelpers.buildProperties(configs) : UtilHelpers.readConfig(jsc.hadoopConfiguration(), new Path(propsFilePath), configs).getProps(true);
    properties.setProperty(HoodieBootstrapConfig.BASE_PATH.key(), sourcePath);
    if (!StringUtils.isNullOrEmpty(keyGenerator) && KeyGeneratorType.getNames().contains(keyGenerator.toUpperCase(Locale.ROOT))) {
        properties.setProperty(HoodieBootstrapConfig.KEYGEN_TYPE.key(), keyGenerator.toUpperCase(Locale.ROOT));
    } else {
        properties.setProperty(HoodieBootstrapConfig.KEYGEN_CLASS_NAME.key(), keyGenerator);
    }
    properties.setProperty(HoodieBootstrapConfig.FULL_BOOTSTRAP_INPUT_PROVIDER_CLASS_NAME.key(), fullBootstrapInputProvider);
    properties.setProperty(HoodieBootstrapConfig.PARALLELISM_VALUE.key(), parallelism);
    properties.setProperty(HoodieBootstrapConfig.MODE_SELECTOR_CLASS_NAME.key(), selectorClass);
    properties.setProperty(DataSourceWriteOptions.RECORDKEY_FIELD().key(), recordKeyCols);
    properties.setProperty(DataSourceWriteOptions.PARTITIONPATH_FIELD().key(), partitionFields);
    HoodieDeltaStreamer.Config cfg = new HoodieDeltaStreamer.Config();
    cfg.targetTableName = tableName;
    cfg.targetBasePath = basePath;
    cfg.tableType = tableType;
    cfg.schemaProviderClassName = schemaProviderClass;
    cfg.bootstrapIndexClass = bootstrapIndexClass;
    cfg.payloadClassName = payloadClassName;
    cfg.enableHiveSync = Boolean.valueOf(enableHiveSync);
    new BootstrapExecutor(cfg, jsc, FSUtils.getFs(basePath, jsc.hadoopConfiguration()), jsc.hadoopConfiguration(), properties).execute();
    return 0;
}
Also used : Path(org.apache.hadoop.fs.Path) HoodieDeltaStreamer(org.apache.hudi.utilities.deltastreamer.HoodieDeltaStreamer) BootstrapExecutor(org.apache.hudi.utilities.deltastreamer.BootstrapExecutor) HoodieWriteConfig(org.apache.hudi.config.HoodieWriteConfig) HoodieIndexConfig(org.apache.hudi.config.HoodieIndexConfig) Config(org.apache.hudi.utilities.HDFSParquetImporter.Config) HoodieBootstrapConfig(org.apache.hudi.config.HoodieBootstrapConfig) TypedProperties(org.apache.hudi.common.config.TypedProperties)

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