List of usage examples for com.google.common.collect ImmutableList.Builder addAll
boolean addAll(Collection<? extends E> c);
From source file:com.spotify.heroic.metric.FetchData.java
public static Collector<Result, Result> collectResult(final QueryTrace.Identifier what) { final QueryTrace.NamedWatch w = QueryTrace.watch(what); return results -> { final ImmutableList.Builder<QueryTrace> traces = ImmutableList.builder(); final ImmutableList.Builder<RequestError> errors = ImmutableList.builder(); for (final Result result : results) { traces.add(result.trace);//from w ww . j a v a2 s. co m errors.addAll(result.errors); } return new Result(w.end(traces.build()), errors.build()); }; }
From source file:com.google.devtools.build.lib.analysis.TopLevelArtifactHelper.java
/** * Utility function to form a list of all test output Artifacts of the given targets to test. *//*from ww w .j av a 2 s . c o m*/ public static ImmutableCollection<Artifact> getAllArtifactsToTest( Iterable<? extends TransitiveInfoCollection> targets) { if (targets == null) { return ImmutableList.of(); } ImmutableList.Builder<Artifact> allTestArtifacts = ImmutableList.builder(); for (TransitiveInfoCollection target : targets) { allTestArtifacts.addAll(TestProvider.getTestStatusArtifacts(target)); } return allTestArtifacts.build(); }
From source file:com.spotify.heroic.ingestion.Ingestion.java
public static Collector<Ingestion, Ingestion> reduce() { return results -> { final ImmutableList.Builder<RequestError> errors = ImmutableList.builder(); final ImmutableList.Builder<Long> times = ImmutableList.builder(); for (final Ingestion r : results) { errors.addAll(r.errors); times.addAll(r.times);/*from w w w . j a va 2s . c o m*/ } return new Ingestion(errors.build(), times.build()); }; }
From source file:io.prestosql.plugin.accumulo.model.Row.java
/** * Creates a new {@link Row} from the given delimited string based on the given {@link RowSchema} * * @param schema Row's schema/*from w w w.ja v a 2 s . c o m*/ * @param str String to parse * @param delimiter Delimiter of the string * @return A new Row * @throws PrestoException If the length of the split string is not equal to the length of the schema * @throws PrestoException If the schema contains an unsupported type */ public static Row fromString(RowSchema schema, String str, char delimiter) { Row row = new Row(); ImmutableList.Builder<String> builder = ImmutableList.builder(); List<String> fields = builder.addAll(Splitter.on(delimiter).split(str)).build(); if (fields.size() != schema.getLength()) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format( "Number of split tokens is not equal to schema length. Expected %s received %s. Schema: %s, fields {%s}, delimiter %s", schema.getLength(), fields.size(), schema, StringUtils.join(fields, ","), delimiter)); } for (int i = 0; i < fields.size(); ++i) { Type type = schema.getColumn(i).getType(); row.addField(valueFromString(fields.get(i), type), type); } return row; }
From source file:com.google.template.soy.jssrc.dsl.Concatenation.java
static Concatenation create(Iterable<? extends Expression> parts) { ImmutableList.Builder<Statement> initialStatements = ImmutableList.builder(); ImmutableList.Builder<Expression> partsBuilder = ImmutableList.builder(); for (Expression part : parts) { initialStatements.addAll(part.initialStatements()); if (part instanceof Concatenation) { partsBuilder.addAll(((Concatenation) part).parts()); } else if (part instanceof BinaryOperation) { BinaryOperation binaryOp = (BinaryOperation) part; if (binaryOp.operator().equals(Operator.PLUS.getTokenString())) { partsBuilder.add(binaryOp.arg1()); partsBuilder.add(binaryOp.arg2()); } else { partsBuilder.add(part);//from w w w .jav a 2 s . c om } } else { partsBuilder.add(part); } } return new AutoValue_Concatenation(initialStatements.build(), partsBuilder.build()); }
From source file:org.apache.calcite.schema.impl.ModifiableViewTable.java
/** * Creates a mapping from the view index to the index in the underlying table. */// www .j a v a 2 s . c o m private static ImmutableIntList getNewColumnMapping(Table underlying, ImmutableIntList oldColumnMapping, List<RelDataTypeField> extendedColumns, RelDataTypeFactory typeFactory) { final List<RelDataTypeField> baseColumns = underlying.getRowType(typeFactory).getFieldList(); final Map<String, Integer> nameToIndex = mapNameToIndex(baseColumns); final ImmutableList.Builder<Integer> newMapping = ImmutableList.builder(); newMapping.addAll(oldColumnMapping); int newMappedIndex = baseColumns.size(); for (RelDataTypeField extendedColumn : extendedColumns) { if (nameToIndex.containsKey(extendedColumn.getName())) { // The extended column duplicates a column in the underlying table. // Map to the index in the underlying table. newMapping.add(nameToIndex.get(extendedColumn.getName())); } else { // The extended column is not in the underlying table. newMapping.add(newMappedIndex++); } } return ImmutableIntList.copyOf(newMapping.build()); }
From source file:gobblin.cluster.ContainerMetrics.java
private static List<Tag<?>> tagsForContainer(State containerState, String applicationName, String taskRunnerId) {//from ww w . j ava 2 s . com ImmutableList.Builder<Tag<?>> tags = new ImmutableList.Builder<>(); tags.add(new Tag<>(GobblinClusterMetricTagNames.APPLICATION_NAME, applicationName)); tags.add(new Tag<>(GobblinClusterMetricTagNames.TASK_RUNNER_ID, taskRunnerId)); tags.addAll(getCustomTagsFromState(containerState)); return tags.build(); }
From source file:org.apache.calcite.plan.RelOptMaterializations.java
/** * Returns a list of RelNode transformed from all possible combination of * materialized view uses. Big queries will likely have more than one * transformed RelNode, e.g., (t1 group by c1) join (t2 group by c2). * @param rel the original RelNode * @param materializations the materialized view list * @return the list of transformed RelNode together with their corresponding * materialized views used in the transformation. *///from ww w. j av a 2 s. c o m public static List<Pair<RelNode, List<RelOptMaterialization>>> useMaterializedViews(final RelNode rel, List<RelOptMaterialization> materializations) { final List<RelOptMaterialization> applicableMaterializations = getApplicableMaterializations(rel, materializations); final List<Pair<RelNode, List<RelOptMaterialization>>> applied = new ArrayList<>(); applied.add(Pair.<RelNode, List<RelOptMaterialization>>of(rel, ImmutableList.<RelOptMaterialization>of())); for (RelOptMaterialization m : applicableMaterializations) { int count = applied.size(); for (int i = 0; i < count; i++) { Pair<RelNode, List<RelOptMaterialization>> current = applied.get(i); List<RelNode> sub = substitute(current.left, m); if (!sub.isEmpty()) { ImmutableList.Builder<RelOptMaterialization> builder = ImmutableList.builder(); builder.addAll(current.right); builder.add(m); List<RelOptMaterialization> uses = builder.build(); for (RelNode rel2 : sub) { applied.add(Pair.of(rel2, uses)); } } } } return applied.subList(1, applied.size()); }
From source file:io.druid.sql.calcite.planner.Rules.java
private static List<RelOptRule> baseRuleSet(final PlannerContext plannerContext, final QueryMaker queryMaker) { final PlannerConfig plannerConfig = plannerContext.getPlannerConfig(); final ImmutableList.Builder<RelOptRule> rules = ImmutableList.builder(); // Calcite rules. rules.addAll(DEFAULT_RULES); rules.addAll(MISCELLANEOUS_RULES);// w w w. j a v a 2 s . c o m rules.addAll(CONSTANT_REDUCTION_RULES); rules.addAll(VOLCANO_ABSTRACT_RULES); rules.addAll(RELOPTUTIL_ABSTRACT_RULES); rules.addAll(SUB_QUERY_REMOVE_RULES); if (!plannerConfig.isUseApproximateCountDistinct()) { // We'll need this to expand COUNT DISTINCTs. // Avoid AggregateExpandDistinctAggregatesRule.INSTANCE; it uses grouping sets and we don't support those. rules.add(AggregateExpandDistinctAggregatesRule.JOIN); } if (plannerConfig.isUseFallback()) { rules.add(DruidRelToBindableRule.instance()); } rules.add(SortCollapseRule.instance()); rules.add(CaseFilteredAggregatorRule.instance()); // Druid-specific rules. rules.add(new DruidTableScanRule(queryMaker)); rules.addAll(DruidRules.rules()); if (plannerConfig.getMaxSemiJoinRowsInMemory() > 0) { rules.add(DruidSemiJoinRule.instance()); } return rules.build(); }
From source file:com.facebook.presto.util.MaterializedResult.java
public static Builder resultBuilder(List<TupleInfo> tupleInfos) { ImmutableList.Builder<Type> types = ImmutableList.builder(); for (TupleInfo sourceTupleInfo : checkNotNull(tupleInfos, "sourceTupleInfos is null")) { types.addAll(sourceTupleInfo.getTypes()); }// w w w . ja va2s. c o m return new Builder(new TupleInfo(types.build())); }