HiveOutput implements BulkOutput, ProvidesAlias, ProvidesValidations { @Override public void configure(Config config) { tableName = config.getString(TABLE_CONFIG); if (config.hasPath(PARTITION_BY_CONFIG)) { List<String> colNames = config.getStringList(PARTITION_BY_CONFIG); partitionColumns = colNames.toArray(new String[0]); } doesAlignColumns = ConfigUtils.getOrElse(config, ALIGN_COLUMNS_CONFIG, false); if (config.hasPath(LOCATION_CONFIG) || config.hasPath(OPTIONS_CONFIG)) { options = new ConfigUtils.OptionMap(config); if (config.hasPath(LOCATION_CONFIG)) { options.resolve("path", LOCATION_CONFIG); } if (config.hasPath(OPTIONS_CONFIG)) { Config optionsConfig = config.getConfig(OPTIONS_CONFIG); for (Map.Entry<String, ConfigValue> entry : optionsConfig.entrySet()) { String param = entry.getKey(); String value = entry.getValue().unwrapped().toString(); if (value != null) { options.put(param, value); } } } } }  @Override void configure(Config config); @Override void applyBulkMutations(List<Tuple2<MutationType, Dataset<Row>>> planned); @Override Set<MutationType> getSupportedBulkMutationTypes(); Dataset<Row> alignColumns(Dataset<Row> input); @Override String getAlias(); @Override Validations getValidations(); final static String TABLE_CONFIG; final static String PARTITION_BY_CONFIG; final static String LOCATION_CONFIG; final static String OPTIONS_CONFIG; final static String ALIGN_COLUMNS_CONFIG; final static String SPARK_SQL_CASE_SENSITIVE_CONFIG; }
@Test public void configure() throws Exception { Map<String, Object> paramMap = new HashMap<>(); paramMap.put(HiveOutput.TABLE_CONFIG, "foo"); config = ConfigFactory.parseMap(paramMap); HiveOutput hiveOutput = new HiveOutput(); assertNoValidationFailures(hiveOutput, config); hiveOutput.configure(config); }
@Test public void configureLocation() throws Exception { Map<String, Object> paramMap = new HashMap<>(); paramMap.put(HiveOutput.TABLE_CONFIG, "foo"); paramMap.put(HiveOutput.LOCATION_CONFIG, "bar"); config = ConfigFactory.parseMap(paramMap); HiveOutput hiveOutput = new HiveOutput(); assertNoValidationFailures(hiveOutput, config); hiveOutput.configure(config); Map<String, String> optionsMap = Deencapsulation.getField(hiveOutput, "options"); assertNotNull("Options are null", optionsMap); assertEquals("Invalid option", "bar", optionsMap.get("path")); }
@Test public void configureOtherOptions() throws Exception { Map<String, Object> otherMap = new HashMap<>(); otherMap.put("hive-option", "badabing"); Map<String, Object> paramMap = new HashMap<>(); paramMap.put(HiveOutput.TABLE_CONFIG, "foo"); paramMap.put(HiveOutput.OPTIONS_CONFIG, otherMap); config = ConfigFactory.parseMap(paramMap); HiveOutput hiveOutput = new HiveOutput(); assertNoValidationFailures(hiveOutput, config); hiveOutput.configure(config); Map<String, String> optionsMap = Deencapsulation.getField(hiveOutput, "options"); assertNotNull("Options are null", optionsMap); assertEquals("Invalid option", "badabing", optionsMap.get("hive-option")); }