use of com.google.common.base.Splitter in project incubator-gobblin by apache.
the class WhitelistBlacklist method populateMultimap.
private static void populateMultimap(SetMultimap<Pattern, Pattern> multimap, String list) throws IOException {
Splitter tokenSplitter = Splitter.on(",").omitEmptyStrings().trimResults();
Splitter partSplitter = Splitter.on(".").omitEmptyStrings().trimResults();
Splitter tableSplitter = Splitter.on("|").omitEmptyStrings().trimResults();
for (String token : tokenSplitter.split(list)) {
if (!Strings.isNullOrEmpty(token)) {
List<String> parts = partSplitter.splitToList(token);
if (parts.size() > 2) {
throw new IOException("Invalid token " + token);
}
Pattern databasePattern = Pattern.compile(parts.get(0).replace("*", ".*"));
Set<Pattern> tablePatterns = Sets.newHashSet();
if (parts.size() == 2) {
String tables = parts.get(1);
for (String table : tableSplitter.split(tables)) {
if (table.equals("*")) {
// special case, must use ALL_TABLES due to use of set.contains(ALL_TABLES) in multimapContains
tablePatterns.add(ALL_TABLES);
} else {
tablePatterns.add(Pattern.compile(table.replace("*", ".*")));
}
}
} else {
tablePatterns.add(ALL_TABLES);
}
multimap.putAll(databasePattern, tablePatterns);
}
}
}
use of com.google.common.base.Splitter in project incubator-gobblin by apache.
the class HivePurgerPublisher method submitEvent.
private void submitEvent(WorkUnitState state, String name) {
WorkUnit workUnit = state.getWorkunit();
Map<String, String> metadata = new HashMap<>();
String recordsRead = state.getProp(ComplianceConfigurationKeys.NUM_ROWS);
metadata.put(ComplianceConfigurationKeys.WORKUNIT_RECORDSREAD, recordsRead);
metadata.put(ComplianceConfigurationKeys.WORKUNIT_BYTESREAD, getDataSize(workUnit.getProp(ComplianceConfigurationKeys.RAW_DATA_SIZE), workUnit.getProp(ComplianceConfigurationKeys.TOTAL_SIZE)));
String partitionNameProp = workUnit.getProp(ComplianceConfigurationKeys.PARTITION_NAME);
Splitter AT_SPLITTER = Splitter.on("@").omitEmptyStrings().trimResults();
List<String> namesList = AT_SPLITTER.splitToList(partitionNameProp);
if (namesList.size() != 3) {
log.warn("Not submitting event. Invalid partition name: " + partitionNameProp);
return;
}
String dbName = namesList.get(0), tableName = namesList.get(1), partitionName = namesList.get(2);
org.apache.hadoop.hive.metastore.api.Partition apiPartition = null;
Partition qlPartition = null;
try {
Table table = new Table(this.client.getTable(dbName, tableName));
apiPartition = this.client.getPartition(dbName, tableName, partitionName);
qlPartition = new Partition(table, apiPartition);
} catch (Exception e) {
log.warn("Not submitting event. Failed to resolve partition '" + partitionName + "': " + e);
e.printStackTrace();
return;
}
HivePartitionDataset hivePartitionDataset = new HivePartitionDataset(qlPartition);
String recordsWritten = DatasetUtils.getProperty(hivePartitionDataset, ComplianceConfigurationKeys.NUM_ROWS, ComplianceConfigurationKeys.DEFAULT_NUM_ROWS);
String recordsPurged = Long.toString((Long.parseLong(recordsRead) - Long.parseLong(recordsWritten)));
metadata.put(ComplianceConfigurationKeys.WORKUNIT_RECORDSWRITTEN, recordsWritten);
metadata.put(ComplianceConfigurationKeys.WORKUNIT_BYTESWRITTEN, getDataSize(DatasetUtils.getProperty(hivePartitionDataset, ComplianceConfigurationKeys.RAW_DATA_SIZE, ComplianceConfigurationKeys.DEFAULT_RAW_DATA_SIZE), DatasetUtils.getProperty(hivePartitionDataset, ComplianceConfigurationKeys.TOTAL_SIZE, ComplianceConfigurationKeys.DEFAULT_TOTAL_SIZE)));
metadata.put(DatasetMetrics.DATABASE_NAME, hivePartitionDataset.getDbName());
metadata.put(DatasetMetrics.TABLE_NAME, hivePartitionDataset.getTableName());
metadata.put(DatasetMetrics.PARTITION_NAME, hivePartitionDataset.getName());
metadata.put(DatasetMetrics.RECORDS_PURGED, recordsPurged);
this.eventSubmitter.submit(name, metadata);
}
use of com.google.common.base.Splitter in project incubator-gobblin by apache.
the class RowLevelPolicyCheckerBuilder method createPolicyList.
@SuppressWarnings("unchecked")
private List<RowLevelPolicy> createPolicyList() throws Exception {
List<RowLevelPolicy> list = new ArrayList<>();
Splitter splitter = Splitter.on(",").omitEmptyStrings().trimResults();
String rowLevelPoliciesKey = ForkOperatorUtils.getPropertyNameForBranch(ConfigurationKeys.ROW_LEVEL_POLICY_LIST, this.index);
String rowLevelPolicyTypesKey = ForkOperatorUtils.getPropertyNameForBranch(ConfigurationKeys.ROW_LEVEL_POLICY_LIST_TYPE, this.index);
if (this.state.contains(rowLevelPoliciesKey) && this.state.contains(rowLevelPolicyTypesKey)) {
List<String> policies = Lists.newArrayList(splitter.split(this.state.getProp(rowLevelPoliciesKey)));
List<String> types = Lists.newArrayList(splitter.split(this.state.getProp(rowLevelPolicyTypesKey)));
if (policies.size() != types.size()) {
throw new Exception("Row Policies list and Row Policies list type are not the same length");
}
for (int i = 0; i < policies.size(); i++) {
try {
Class<? extends RowLevelPolicy> policyClass = (Class<? extends RowLevelPolicy>) Class.forName(policies.get(i));
Constructor<? extends RowLevelPolicy> policyConstructor = policyClass.getConstructor(State.class, RowLevelPolicy.Type.class);
RowLevelPolicy policy = policyConstructor.newInstance(this.state, RowLevelPolicy.Type.valueOf(types.get(i)));
list.add(policy);
} catch (Exception e) {
LOG.error(rowLevelPoliciesKey + " contains a class " + policies.get(i) + " which doesn't extend RowLevelPolicy.", e);
throw e;
}
}
}
return list;
}
use of com.google.common.base.Splitter in project incubator-gobblin by apache.
the class TaskLevelPolicyCheckerBuilder method createPolicyList.
@SuppressWarnings("unchecked")
private List<TaskLevelPolicy> createPolicyList() throws Exception {
List<TaskLevelPolicy> list = new ArrayList<>();
String taskLevelPoliciesKey = ForkOperatorUtils.getPropertyNameForBranch(ConfigurationKeys.TASK_LEVEL_POLICY_LIST, this.index);
String taskLevelPolicyTypesKey = ForkOperatorUtils.getPropertyNameForBranch(ConfigurationKeys.TASK_LEVEL_POLICY_LIST_TYPE, this.index);
if (this.state.contains(taskLevelPoliciesKey) && this.state.contains(taskLevelPolicyTypesKey)) {
Splitter splitter = Splitter.on(",").omitEmptyStrings().trimResults();
List<String> policies = Lists.newArrayList(splitter.split(this.state.getProp(taskLevelPoliciesKey)));
List<String> types = Lists.newArrayList(splitter.split(this.state.getProp(taskLevelPolicyTypesKey)));
if (policies.size() != types.size()) {
throw new Exception("TaskLevelPolicy list and TaskLevelPolicies type list are not the same length");
}
for (int i = 0; i < policies.size(); i++) {
try {
Class<? extends TaskLevelPolicy> policyClass = (Class<? extends TaskLevelPolicy>) Class.forName(policies.get(i));
Constructor<? extends TaskLevelPolicy> policyConstructor = policyClass.getConstructor(State.class, TaskLevelPolicy.Type.class);
TaskLevelPolicy policy = policyConstructor.newInstance(this.state, TaskLevelPolicy.Type.valueOf(types.get(i)));
list.add(policy);
} catch (Exception e) {
LOG.error(taskLevelPoliciesKey + " contains a class " + policies.get(i) + " which doesn't extend Policy.", e);
throw e;
}
}
}
return list;
}
use of com.google.common.base.Splitter in project metasfresh-webui-api by metasfresh.
the class ProductLookupDescriptor method addStorageAttributeKeysToQueryBuilder.
private void addStorageAttributeKeysToQueryBuilder(@NonNull final AvailableToPromiseQueryBuilder stockQueryBuilder) {
final ISysConfigBL sysConfigBL = Services.get(ISysConfigBL.class);
final int clientId = Env.getAD_Client_ID(Env.getCtx());
final int orgId = Env.getAD_Org_ID(Env.getCtx());
final String storageAttributesKeys = sysConfigBL.getValue(SYSCONFIG_ATP_ATTRIBUTES_KEYS, AttributesKey.ALL.getAsString(), clientId, orgId);
final Splitter splitter = Splitter.on(",").trimResults(CharMatcher.whitespace()).omitEmptyStrings();
for (final String storageAttributesKey : splitter.splitToList(storageAttributesKeys)) {
if ("<ALL_STORAGE_ATTRIBUTES_KEYS>".equals(storageAttributesKey)) {
stockQueryBuilder.storageAttributesKey(AttributesKey.ALL);
} else if ("<OTHER_STORAGE_ATTRIBUTES_KEYS>".equals(storageAttributesKey)) {
stockQueryBuilder.storageAttributesKey(AttributesKey.OTHER);
} else {
stockQueryBuilder.storageAttributesKey(AttributesKey.ofString(storageAttributesKey));
}
}
}
Aggregations