@Override protected Multimap<String, org.apache.calcite.schema.Function> getFunctionMultimap() { final ImmutableMultimap.Builder<String, org.apache.calcite.schema.Function> builder = ImmutableMultimap.builder(); for (Map.Entry<String, DruidViewMacro> entry : viewManager.getViews().entrySet()) { builder.put(entry); } return builder.build(); }
AttributesByFirstLetter(Iterable<ValueAttribute> attributes) { ImmutableMultimap.Builder<Character, ValueAttribute> builder = ImmutableMultimap.builder(); for (ValueAttribute attribute : attributes) { String name = attribute.getMarshaledName(); char firstChar = name.charAt(0); builder.put(firstChar, attribute); } byFirst = builder.build(); asMap = byFirst.asMap(); }
private Set<RemoteTask> assignSplits(Multimap<Node, Split> splitAssignment, Multimap<Node, Lifespan> noMoreSplitsNotification) { ImmutableSet.Builder<RemoteTask> newTasks = ImmutableSet.builder(); ImmutableSet<Node> nodes = ImmutableSet.<Node>builder() .addAll(splitAssignment.keySet()) .addAll(noMoreSplitsNotification.keySet()) .build(); for (Node node : nodes) { // source partitioned tasks can only receive broadcast data; otherwise it would have a different distribution ImmutableMultimap<PlanNodeId, Split> splits = ImmutableMultimap.<PlanNodeId, Split>builder() .putAll(partitionedNode, splitAssignment.get(node)) .build(); ImmutableMultimap.Builder<PlanNodeId, Lifespan> noMoreSplits = ImmutableMultimap.builder(); if (noMoreSplitsNotification.containsKey(node)) { noMoreSplits.putAll(partitionedNode, noMoreSplitsNotification.get(node)); } newTasks.addAll(stage.scheduleSplits( node, splits, noMoreSplits.build())); } return newTasks.build(); }
private ImmutableMultimap<String, MethodInvocationTree> methodCallsForSymbol( Symbol sym, ClassTree classTree) { ImmutableMultimap.Builder<String, MethodInvocationTree> methodMap = ImmutableMultimap.builder(); classTree.accept( new TreeScanner<Void, Void>() { @Override public Void visitMethodInvocation(MethodInvocationTree callTree, Void unused) { final MethodSymbol methodSymbol = getSymbol(callTree); if (methodSymbol != null && sym.equals(methodSymbol)) { methodMap.put(methodSymbol.toString(), callTree); } return super.visitMethodInvocation(callTree, unused); } }, null); return methodMap.build(); }
@Override public Map<String, Collection<String>> getHeaders() { ImmutableMultimap.Builder<String, String> builder = ImmutableMultimap.builder(); for ( String name : fromEnumeration( req.getHeaderNames() ) ) { builder.putAll( name, fromEnumeration( req.getHeaders( name ) ) ); } return builder.build().asMap(); }
@Override public Map<String, Collection<String>> getParameters() { ImmutableMultimap.Builder<String, String> builder = ImmutableMultimap.builder(); for ( String name : fromEnumeration( req.getParameterNames() ) ) { builder.putAll( name, req.getParameterValues( name ) ); } return builder.build().asMap(); }
/** * Finds all method invocations on the given symbol, and constructs a map of the called method's * name, to the {@link MethodInvocationTree} in which it was called. */ private ImmutableMultimap<String, MethodInvocationTree> methodCallsForSymbol( Symbol sym, ClassTree classTree) { Builder<String, MethodInvocationTree> methodMap = ImmutableMultimap.builder(); // Populate map builder with names of method called : the tree in which it is called. classTree.accept( new TreeScanner<Void, Void>() { @Override public Void visitMethodInvocation(MethodInvocationTree callTree, Void unused) { if (sym.equals(getSymbol(getReceiver(callTree)))) { MethodSymbol methodSymbol = getSymbol(callTree); if (methodSymbol != null) { methodMap.put(methodSymbol.getSimpleName().toString(), callTree); } } return super.visitMethodInvocation(callTree, unused); } }, null); return methodMap.build(); } }
public DependenciesValidator(final JsonNode digest) { super("dependencies"); /* * Property dependencies */ final ImmutableMultimap.Builder<String, String> mapBuilder = ImmutableMultimap.builder(); final Map<String, JsonNode> map = JacksonUtils.asMap(digest.get("propertyDeps")); String key; for (final Map.Entry<String, JsonNode> entry: map.entrySet()) { key = entry.getKey(); for (final JsonNode element: entry.getValue()) mapBuilder.put(key, element.textValue()); } propertyDeps = mapBuilder.build(); /* * Schema dependencies */ final ImmutableSet.Builder<String> setBuilder = ImmutableSet.builder(); for (final JsonNode node: digest.get("schemaDeps")) setBuilder.add(node.textValue()); schemaDeps = setBuilder.build(); }
public Set<ContentPack> loadAllLatest() { final Set<ContentPack> allContentPacks = loadAll(); final ImmutableMultimap.Builder<ModelId, ContentPack> byIdBuilder = ImmutableMultimap.builder(); for (ContentPack contentPack : allContentPacks) { byIdBuilder.put(contentPack.id(), contentPack); } final ImmutableMultimap<ModelId, ContentPack> contentPacksById = byIdBuilder.build(); final ImmutableSet.Builder<ContentPack> latestContentPacks = ImmutableSet.builderWithExpectedSize(contentPacksById.keySet().size()); for (ModelId id : contentPacksById.keySet()) { final ImmutableCollection<ContentPack> contentPacks = contentPacksById.get(id); final ContentPack latestContentPackRevision = Collections.max(contentPacks, Comparator.comparingInt(Revisioned::revision)); latestContentPacks.add(latestContentPackRevision); } return latestContentPacks.build(); }
/** * Creates a graph from a list of node pairs (encoded as strings, e.g. "ab" means that this graph * has an edge between 'a' and 'b'). * * <p>The {@code successors} are always returned in alphabetical order. */ private static SuccessorsFunction<Character> createGraph(boolean directed, String... edges) { ImmutableMultimap.Builder<Character, Character> graphMapBuilder = ImmutableMultimap.builder(); for (String edge : edges) { checkArgument( edge.length() == 2, "Expecting each edge to consist of 2 characters but got %s", edge); char node1 = edge.charAt(0); char node2 = edge.charAt(1); graphMapBuilder.put(node1, node2); if (!directed) { graphMapBuilder.put(node2, node1); } } final ImmutableMultimap<Character, Character> graphMap = graphMapBuilder.build(); return new SuccessorsFunction<Character>() { @Override public Iterable<? extends Character> successors(Character node) { checkArgument( graphMap.containsKey(node) || graphMap.containsValue(node), "Node %s is not an element of this graph", node); return Ordering.natural().immutableSortedCopy(graphMap.get(node)); } }; }
private static PrincipalPrivileges buildInitialPrivilegeSet(String tableOwner) { return new PrincipalPrivileges( ImmutableMultimap.<String, HivePrivilegeInfo>builder() .put(tableOwner, new HivePrivilegeInfo(HivePrivilege.SELECT, true)) .put(tableOwner, new HivePrivilegeInfo(HivePrivilege.INSERT, true)) .put(tableOwner, new HivePrivilegeInfo(HivePrivilege.UPDATE, true)) .put(tableOwner, new HivePrivilegeInfo(HivePrivilege.DELETE, true)) .build(), ImmutableMultimap.of()); }
final ImmutableMultimap.Builder<String, FieldValue> builder = ImmutableMultimap.builder(); final ImmutableSet.Builder<String> disallowedKeys = ImmutableSet.builder(); builder.put(defaultField, createFieldValue(defaultFieldKey, entry, false)); continue; builder.put(translatedKey.getDbField(), createFieldValue(translatedKey, v, negate)); } else { builder.put(defaultField, createFieldValue(defaultFieldKey, v, negate)); return new SearchQuery(queryString, builder.build(), disallowedKeys.build());
/** * Returns a Multimap from fieldName Strings to their getter Methods. * * It expects to be called only from TaskSerDe. Multimap is used inside org.embulk.config. */ static Multimap<String, Method> fieldGetters(Class<?> iface) { ImmutableMultimap.Builder<String, Method> builder = ImmutableMultimap.builder(); for (Method method : iface.getMethods()) { String methodName = method.getName(); String fieldName = getterFieldNameOrNull(methodName); if (fieldName != null && hasExpectedArgumentLength(method, 0) && (!method.isDefault() || method.getAnnotation(Config.class) != null)) { // If the method has default implementation, and @Config is not annotated there, the method is kept. builder.put(fieldName, method); } } return builder.build(); }
protected Multimap<String, FieldEntry> getterMappings(Class<?> iface) { ImmutableMultimap.Builder<String, FieldEntry> builder = ImmutableMultimap.builder(); for (Map.Entry<String, Method> getter : TaskInvocationHandler.fieldGetters(iface).entries()) { Method getterMethod = getter.getValue(); String fieldName = getter.getKey(); if (getterMethod.getAnnotation(ConfigInject.class) != null) { // InjectEntry continue; } Type fieldType = getterMethod.getGenericReturnType(); final Optional<String> jsonKey = getJsonKey(getterMethod, fieldName); if (!jsonKey.isPresent()) { // skip this field continue; } final Optional<String> defaultJsonString = getDefaultJsonString(getterMethod); builder.put(jsonKey.get(), new FieldEntry(fieldName, fieldType, defaultJsonString)); } return builder.build(); }
ImmutableMultimap.Builder<ByteBuffer, ByteBuffer> indexColumnsBuilder = ImmutableMultimap.builder(); Map<ByteBuffer, Map<ByteBuffer, Type>> indexColumnTypesBuilder = new HashMap<>(); indexColumnsBuilder.put(family, qualifier); indexColumns = indexColumnsBuilder.build(); indexColumnTypes = ImmutableMap.copyOf(indexColumnTypesBuilder);
private JoinGraph joinWith(JoinGraph other, List<JoinNode.EquiJoinClause> joinClauses, Context context, PlanNodeId newRoot) { for (PlanNode node : other.nodes) { checkState(!edges.containsKey(node.getId()), format("Node [%s] appeared in two JoinGraphs", node)); } List<PlanNode> nodes = ImmutableList.<PlanNode>builder() .addAll(this.nodes) .addAll(other.nodes) .build(); ImmutableMultimap.Builder<PlanNodeId, Edge> edges = ImmutableMultimap.<PlanNodeId, Edge>builder() .putAll(this.edges) .putAll(other.edges); List<Expression> joinedFilters = ImmutableList.<Expression>builder() .addAll(this.filters) .addAll(other.filters) .build(); for (JoinNode.EquiJoinClause edge : joinClauses) { Symbol leftSymbol = edge.getLeft(); Symbol rightSymbol = edge.getRight(); checkState(context.containsSymbol(leftSymbol)); checkState(context.containsSymbol(rightSymbol)); PlanNode left = context.getSymbolSource(leftSymbol); PlanNode right = context.getSymbolSource(rightSymbol); edges.put(left.getId(), new Edge(right, leftSymbol, rightSymbol)); edges.put(right.getId(), new Edge(left, rightSymbol, leftSymbol)); } return new JoinGraph(nodes, edges.build(), newRoot, joinedFilters, Optional.empty()); }
private Multimap<Symbol, Symbol> extractCorrelatedSymbolsMapping(List<Expression> correlatedConjuncts) { // TODO: handle coercions and non-direct column references ImmutableMultimap.Builder<Symbol, Symbol> mapping = ImmutableMultimap.builder(); for (Expression conjunct : correlatedConjuncts) { if (!(conjunct instanceof ComparisonExpression)) { continue; } ComparisonExpression comparison = (ComparisonExpression) conjunct; if (!(comparison.getLeft() instanceof SymbolReference && comparison.getRight() instanceof SymbolReference && comparison.getOperator().equals(EQUAL))) { continue; } Symbol left = Symbol.from(comparison.getLeft()); Symbol right = Symbol.from(comparison.getRight()); if (correlation.contains(left) && !correlation.contains(right)) { mapping.put(left, right); } if (correlation.contains(right) && !correlation.contains(left)) { mapping.put(right, left); } } return mapping.build(); }
private synchronized void computeImportedByMap(Optional<Config> runtimeConfig) { if (this.fullImportedByMap != null) { return; } ImmutableMultimap.Builder<ConfigKeyPath, ConfigKeyPath> importedByBuilder = ImmutableMultimap.builder(); // breath first search the whole topology to build ownImports map and ownImportedByMap // calls to retrieve cache / set cache if not present Collection<ConfigKeyPath> currentLevel = this.getChildren(SingleLinkedListConfigKeyPath.ROOT); List<ConfigKeyPath> rootImports = this.getOwnImports(SingleLinkedListConfigKeyPath.ROOT, runtimeConfig); Preconditions.checkArgument(rootImports == null || rootImports.size() == 0, "Root can not import other nodes, otherwise circular dependency will happen"); while (!currentLevel.isEmpty()) { Collection<ConfigKeyPath> nextLevel = new ArrayList<>(); for (ConfigKeyPath configKeyPath : currentLevel) { // calls to retrieve cache / set cache if not present List<ConfigKeyPath> ownImports = this.getOwnImports(configKeyPath, runtimeConfig); this.ownImportMap.put(configKeyPath, ownImports); for (ConfigKeyPath importedPath : ownImports) { importedByBuilder.put(importedPath, configKeyPath); } // calls to retrieve cache / set cache if not present Collection<ConfigKeyPath> tmp = this.getChildren(configKeyPath); nextLevel.addAll(tmp); } currentLevel = nextLevel; } this.fullImportedByMap = importedByBuilder.build(); }
public synchronized void addExchangeLocations(PlanFragmentId fragmentId, Set<RemoteTask> sourceTasks, boolean noMoreExchangeLocations) { requireNonNull(fragmentId, "fragmentId is null"); requireNonNull(sourceTasks, "sourceTasks is null"); RemoteSourceNode remoteSource = exchangeSources.get(fragmentId); checkArgument(remoteSource != null, "Unknown remote source %s. Known sources are %s", fragmentId, exchangeSources.keySet()); this.sourceTasks.putAll(remoteSource.getId(), sourceTasks); for (RemoteTask task : getAllTasks()) { ImmutableMultimap.Builder<PlanNodeId, Split> newSplits = ImmutableMultimap.builder(); for (RemoteTask sourceTask : sourceTasks) { URI exchangeLocation = sourceTask.getTaskStatus().getSelf(); newSplits.put(remoteSource.getId(), createRemoteSplitFor(task.getTaskId(), exchangeLocation)); } task.addSplits(newSplits.build()); } if (noMoreExchangeLocations) { completeSourceFragments.add(fragmentId); // is the source now complete? if (completeSourceFragments.containsAll(remoteSource.getSourceFragmentIds())) { completeSources.add(remoteSource.getId()); for (RemoteTask task : getAllTasks()) { task.noMoreSplits(remoteSource.getId()); } } } }