use of com.google.common.base.Splitter in project gerrit by GerritCodeReview.
the class SchemaUtil method getNameParts.
public static Set<String> getNameParts(String name, Iterable<String> emails) {
Splitter at = Splitter.on('@');
Splitter s = Splitter.on(CharMatcher.anyOf("@.- /_")).omitEmptyStrings();
HashSet<String> parts = new HashSet<>();
for (String email : emails) {
if (email == null) {
continue;
}
String lowerEmail = email.toLowerCase(Locale.US);
parts.add(lowerEmail);
Iterables.addAll(parts, at.split(lowerEmail));
Iterables.addAll(parts, s.split(lowerEmail));
}
if (name != null) {
Iterables.addAll(parts, s.split(name.toLowerCase(Locale.US)));
}
return parts;
}
use of com.google.common.base.Splitter in project incubator-gobblin by apache.
the class RestApiExtractor method extractMetadata.
@Override
public void extractMetadata(String schema, String entity, WorkUnit workUnit) throws SchemaException {
log.info("Extract Metadata using Rest Api");
JsonArray columnArray = new JsonArray();
String inputQuery = workUnitState.getProp(ConfigurationKeys.SOURCE_QUERYBASED_QUERY);
List<String> columnListInQuery = null;
JsonArray array = null;
if (!Strings.isNullOrEmpty(inputQuery)) {
columnListInQuery = Utils.getColumnListFromQuery(inputQuery);
}
String excludedColumns = workUnitState.getProp(ConfigurationKeys.SOURCE_QUERYBASED_EXCLUDED_COLUMNS);
List<String> columnListExcluded = ImmutableList.<String>of();
if (Strings.isNullOrEmpty(inputQuery) && !Strings.isNullOrEmpty(excludedColumns)) {
Splitter splitter = Splitter.on(",").omitEmptyStrings().trimResults();
columnListExcluded = splitter.splitToList(excludedColumns.toLowerCase());
}
try {
boolean success = this.connector.connect();
if (!success) {
throw new SchemaException("Failed to connect.");
}
log.debug("Connected successfully.");
List<Command> cmds = this.getSchemaMetadata(schema, entity);
CommandOutput<?, ?> response = this.connector.getResponse(cmds);
array = this.getSchema(response);
for (JsonElement columnElement : array) {
Schema obj = GSON.fromJson(columnElement, Schema.class);
String columnName = obj.getColumnName();
obj.setWaterMark(this.isWatermarkColumn(workUnitState.getProp("extract.delta.fields"), columnName));
if (this.isWatermarkColumn(workUnitState.getProp("extract.delta.fields"), columnName)) {
obj.setNullable(false);
} else if (this.getPrimarykeyIndex(workUnitState.getProp("extract.primary.key.fields"), columnName) == 0) {
// set all columns as nullable except primary key and watermark columns
obj.setNullable(true);
}
obj.setPrimaryKey(this.getPrimarykeyIndex(workUnitState.getProp("extract.primary.key.fields"), columnName));
String jsonStr = GSON.toJson(obj);
JsonObject jsonObject = GSON.fromJson(jsonStr, JsonObject.class).getAsJsonObject();
// Else, consider only the columns mentioned in the column list
if (inputQuery == null || columnListInQuery == null || (columnListInQuery.size() == 1 && columnListInQuery.get(0).equals("*")) || (columnListInQuery.size() >= 1 && this.isMetadataColumn(columnName, columnListInQuery))) {
if (!columnListExcluded.contains(columnName.trim().toLowerCase())) {
this.columnList.add(columnName);
columnArray.add(jsonObject);
}
}
}
this.updatedQuery = buildDataQuery(inputQuery, entity);
log.info("Schema:" + columnArray);
this.setOutputSchema(columnArray);
} catch (RuntimeException | RestApiConnectionException | RestApiProcessingException | IOException | SchemaException e) {
throw new SchemaException("Failed to get schema using rest api; error - " + e.getMessage(), e);
}
}
use of com.google.common.base.Splitter in project incubator-gobblin by apache.
the class AzkabanJobLauncher method isCurrentTimeInRange.
/**
* Uses the properties {@link ConfigurationKeys#AZKABAN_EXECUTION_DAYS_LIST},
* {@link ConfigurationKeys#AZKABAN_EXECUTION_TIME_RANGE}, and
* {@link TimeRangeChecker#isTimeInRange(List, String, String, DateTime)} to determine if the current job should
* continue its execution based on the extra scheduled parameters defined in the config.
*
* @return true if this job should be launched, false otherwise.
*/
private boolean isCurrentTimeInRange() {
Splitter splitter = Splitter.on(",").omitEmptyStrings().trimResults();
if (this.props.contains(ConfigurationKeys.AZKABAN_EXECUTION_DAYS_LIST) && this.props.contains(ConfigurationKeys.AZKABAN_EXECUTION_TIME_RANGE)) {
List<String> executionTimeRange = splitter.splitToList(this.props.getProperty(ConfigurationKeys.AZKABAN_EXECUTION_TIME_RANGE));
List<String> executionDays = splitter.splitToList(this.props.getProperty(ConfigurationKeys.AZKABAN_EXECUTION_DAYS_LIST));
Preconditions.checkArgument(executionTimeRange.size() == 2, "The property " + ConfigurationKeys.AZKABAN_EXECUTION_DAYS_LIST + " should be a comma separated list of two entries");
return TimeRangeChecker.isTimeInRange(executionDays, executionTimeRange.get(0), executionTimeRange.get(1), new DateTime(DateTimeZone.forID(ConfigurationKeys.PST_TIMEZONE_NAME)));
}
return true;
}
use of com.google.common.base.Splitter in project incubator-gobblin by apache.
the class AvroUtils method getMultiFieldValue.
public static Map<String, Object> getMultiFieldValue(GenericRecord record, String fieldLocation) {
Preconditions.checkNotNull(record);
Preconditions.checkArgument(!Strings.isNullOrEmpty(fieldLocation));
Splitter splitter = Splitter.on(FIELD_LOCATION_DELIMITER).omitEmptyStrings().trimResults();
List<String> pathList = splitter.splitToList(fieldLocation);
if (pathList.size() == 0) {
return Collections.emptyMap();
}
HashMap<String, Object> retVal = new HashMap<String, Object>();
AvroUtils.getFieldHelper(retVal, record, pathList, 0);
return retVal;
}
use of com.google.common.base.Splitter in project mylyn.docs by eclipse.
the class HtmlEntities method readHtmlEntities.
private static ListMultimap<String, String> readHtmlEntities() {
ImmutableListMultimap.Builder<String, String> builder = ImmutableListMultimap.builder();
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(HtmlDocumentBuilder.class.getResourceAsStream("html-entity-references.txt"), // $NON-NLS-1$
Charsets.UTF_8));
try {
Splitter splitter = Splitter.on(CharMatcher.WHITESPACE).trimResults().omitEmptyStrings();
String line;
while ((line = reader.readLine()) != null) {
List<String> lineItems = splitter.splitToList(line);
checkState(lineItems.size() > 1);
for (int x = 1; x < lineItems.size(); ++x) {
builder.put(lineItems.get(0), lineItems.get(x));
}
}
} finally {
reader.close();
}
} catch (IOException e) {
throw Throwables.propagate(e);
}
return builder.build();
}
Aggregations