use of com.typesafe.config.ConfigValue in project incubator-gobblin by apache.
the class StateStores method getStateStoreConfig.
private static Config getStateStoreConfig(Config config, String rootDir, String dbTableKey) {
Config fallbackConfig = ConfigFactory.empty().withFallback(config).withValue(ConfigurationKeys.STATE_STORE_ROOT_DIR_KEY, ConfigValueFactory.fromAnyRef(rootDir)).withValue(ConfigurationKeys.STATE_STORE_DB_TABLE_KEY, ConfigValueFactory.fromAnyRef(dbTableKey));
Config scopedConfig = ConfigFactory.empty();
for (Map.Entry<String, ConfigValue> entry : config.withOnlyPath(ConfigurationKeys.INTERMEDIATE_STATE_STORE_PREFIX).entrySet()) {
scopedConfig.withValue(entry.getKey().substring(ConfigurationKeys.INTERMEDIATE_STATE_STORE_PREFIX.length()), entry.getValue());
}
return scopedConfig.withFallback(fallbackConfig);
}
use of com.typesafe.config.ConfigValue in project incubator-gobblin by apache.
the class HiveDataset method resolveConfig.
/**
* Replace various tokens (DB, TABLE, LOGICAL_DB, LOGICAL_TABLE) with their values.
*
* @param datasetConfig The config object that needs to be resolved with final values.
* @param realDbAndTable Real DB and Table .
* @param logicalDbAndTable Logical DB and Table.
* @return Resolved config object.
*/
@VisibleForTesting
protected static Config resolveConfig(Config datasetConfig, DbAndTable realDbAndTable, DbAndTable logicalDbAndTable) {
Preconditions.checkNotNull(datasetConfig, "Dataset config should not be null");
Preconditions.checkNotNull(realDbAndTable, "Real DB and table should not be null");
Preconditions.checkNotNull(logicalDbAndTable, "Logical DB and table should not be null");
ImmutableMap.Builder<String, Object> immutableMapBuilder = ImmutableMap.builder();
Config resolvedConfig = datasetConfig.resolve();
for (Map.Entry<String, ConfigValue> entry : resolvedConfig.entrySet()) {
if (ConfigValueType.LIST.equals(entry.getValue().valueType())) {
List<String> rawValueList = resolvedConfig.getStringList(entry.getKey());
List<String> resolvedValueList = Lists.newArrayList();
for (String rawValue : rawValueList) {
String resolvedValue = StringUtils.replaceEach(rawValue, new String[] { DATABASE_TOKEN, TABLE_TOKEN, LOGICAL_DB_TOKEN, LOGICAL_TABLE_TOKEN }, new String[] { realDbAndTable.getDb(), realDbAndTable.getTable(), logicalDbAndTable.getDb(), logicalDbAndTable.getTable() });
resolvedValueList.add(resolvedValue);
}
StringBuilder listToStringWithQuotes = new StringBuilder();
for (String resolvedValueStr : resolvedValueList) {
if (listToStringWithQuotes.length() > 0) {
listToStringWithQuotes.append(",");
}
listToStringWithQuotes.append("\"").append(resolvedValueStr).append("\"");
}
immutableMapBuilder.put(entry.getKey(), listToStringWithQuotes.toString());
} else {
String resolvedValue = StringUtils.replaceEach(resolvedConfig.getString(entry.getKey()), new String[] { DATABASE_TOKEN, TABLE_TOKEN, LOGICAL_DB_TOKEN, LOGICAL_TABLE_TOKEN }, new String[] { realDbAndTable.getDb(), realDbAndTable.getTable(), logicalDbAndTable.getDb(), logicalDbAndTable.getTable() });
immutableMapBuilder.put(entry.getKey(), resolvedValue);
}
}
return ConfigFactory.parseMap(immutableMapBuilder.build());
}
Aggregations