protected void assertGet(K key, Collection<V> values) { assertEqualInOrder(values, multimap().get(key)); if (!values.isEmpty()) { assertEqualInOrder(values, multimap().asMap().get(key)); assertFalse(multimap().isEmpty()); } else { assertNull(multimap().asMap().get(key)); } assertEquals(values.size(), multimap().get(key).size()); assertEquals(values.size() > 0, multimap().containsKey(key)); assertEquals(values.size() > 0, multimap().keySet().contains(key)); assertEquals(values.size() > 0, multimap().keys().contains(key)); } }
public void copyPushedPredicates(RelNode operator, RelNode otherOperator) { if (this.registryPushedPredicates.containsKey(operator)) { for (Set<String> s : this.registryPushedPredicates.get(operator)) { this.registryPushedPredicates.put(otherOperator, Sets.newHashSet(s)); } } } }
@CheckForNull List<IssueChangeDto> getCommentsForIssueKey(String issueKey) { if (commentsByIssueKey.containsKey(issueKey)) { return commentsByIssueKey.get(issueKey); } return null; }
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "type of symbol 'output(_[0-9]+)?' is expected to be date, but the actual type is bigint") public void testInvalidUnion() { Symbol outputSymbol = symbolAllocator.newSymbol("output", DATE); ListMultimap<Symbol, Symbol> mappings = ImmutableListMultimap.<Symbol, Symbol>builder() .put(outputSymbol, columnD) .put(outputSymbol, columnA) // should be a symbol with DATE type .build(); PlanNode node = new UnionNode( newId(), ImmutableList.of(baseTableScan, baseTableScan), mappings, ImmutableList.copyOf(mappings.keySet())); assertTypesValid(node); }
@Override public PlanNode visitUnion(UnionNode node, RewriteContext<Set<Symbol>> context) { ListMultimap<Symbol, Symbol> rewrittenSymbolMapping = rewriteSetOperationSymbolMapping(node, context); ImmutableList<PlanNode> rewrittenSubPlans = rewriteSetOperationSubPlans(node, context, rewrittenSymbolMapping); return new UnionNode(node.getId(), rewrittenSubPlans, rewrittenSymbolMapping, ImmutableList.copyOf(rewrittenSymbolMapping.keySet())); }
ImmutableListMultimap.Builder<Symbol, Symbol> newSymbolMapping = ImmutableListMultimap.builder(); newSymbolMapping.putAll(node.getSymbolMapping()); ImmutableList.Builder<PlanNode> newSources = ImmutableList.builder(); for (int sourceId = 0; sourceId < node.getSources().size(); sourceId++) { outputToInputMap.put(outputSymbol, node.getSymbolMapping().get(outputSymbol).get(sourceId)); newSources.add(child.getNode()); new UnionNode( node.getId(), newSources.build(), newSymbolMapping.build(), ImmutableList.copyOf(newSymbolMapping.build().keySet())), newHashSymbols);
public void testFilteredKeysListMultimapGetBadValue() { ListMultimap<String, Integer> multimap = ArrayListMultimap.create(); multimap.put("foo", 1); multimap.put("bar", 2); multimap.put("baz", 3); multimap.put("bar", 4); List<Integer> bazList = filtered.get("baz"); assertThat(bazList).isEmpty(); try { bazList.addAll(ImmutableList.of(7, 8)); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { bazList.addAll(0, ImmutableList.of(9, 10)); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) {
@JsonCreator protected SetOperationNode( @JsonProperty("id") PlanNodeId id, @JsonProperty("sources") List<PlanNode> sources, @JsonProperty("outputToInputs") ListMultimap<Symbol, Symbol> outputToInputs, @JsonProperty("outputs") List<Symbol> outputs) { super(id); requireNonNull(sources, "sources is null"); checkArgument(!sources.isEmpty(), "Must have at least one source"); requireNonNull(outputToInputs, "outputToInputs is null"); requireNonNull(outputs, "outputs is null"); this.sources = ImmutableList.copyOf(sources); this.outputToInputs = ImmutableListMultimap.copyOf(outputToInputs); this.outputs = ImmutableList.copyOf(outputs); for (Collection<Symbol> inputs : this.outputToInputs.asMap().values()) { checkArgument(inputs.size() == this.sources.size(), "Every source needs to map its symbols to an output %s operation symbol", this.getClass().getSimpleName()); } // Make sure each source positionally corresponds to their Symbol values in the Multimap for (int i = 0; i < sources.size(); i++) { for (Collection<Symbol> expectedInputs : this.outputToInputs.asMap().values()) { checkArgument(sources.get(i).getOutputSymbols().contains(Iterables.get(expectedInputs, i)), "Source does not provide required symbols"); } } }
RatingMap(Builder builder) { Collections.sort(builder.global, ORDER); for (Long k : builder.group.keySet()) { Collections.sort(builder.group.get(k), ORDER); } this.global = ImmutableList.copyOf(builder.global); this.map = ImmutableListMultimap.copyOf(builder.group); this.resourceMap = builder.resources.build(); }
public void testFlatteningToMultimap() { Collector<String, ?, ListMultimap<Character, Character>> collector = Multimaps.flatteningToMultimap( str -> str.charAt(0), str -> str.substring(1).chars().mapToObj(c -> (char) c), MultimapBuilder.linkedHashKeys().arrayListValues()::build); BiPredicate<Multimap<?, ?>, Multimap<?, ?>> equivalence = Equivalence.equals() .onResultOf((Multimap<?, ?> mm) -> ImmutableList.copyOf(mm.asMap().entrySet())) .and(Equivalence.equals()); ListMultimap<Character, Character> empty = MultimapBuilder.linkedHashKeys().arrayListValues().build(); ListMultimap<Character, Character> filled = MultimapBuilder.linkedHashKeys().arrayListValues().build(); filled.putAll('b', Arrays.asList('a', 'n', 'a', 'n', 'a')); filled.putAll('a', Arrays.asList('p', 'p', 'l', 'e')); filled.putAll('c', Arrays.asList('a', 'r', 'r', 'o', 't')); filled.putAll('a', Arrays.asList('s', 'p', 'a', 'r', 'a', 'g', 'u', 's')); filled.putAll('c', Arrays.asList('h', 'e', 'r', 'r', 'y')); CollectorTester.of(collector, equivalence) .expectCollects(empty) .expectCollects(filled, "banana", "apple", "carrot", "asparagus", "cherry"); }
private ImmutableList<PlanNode> rewriteSetOperationSubPlans(SetOperationNode node, RewriteContext<Set<Symbol>> context, ListMultimap<Symbol, Symbol> rewrittenSymbolMapping) { // Find the corresponding input symbol to the remaining output symbols and prune the subplans ImmutableList.Builder<PlanNode> rewrittenSubPlans = ImmutableList.builder(); for (int i = 0; i < node.getSources().size(); i++) { ImmutableSet.Builder<Symbol> expectedInputSymbols = ImmutableSet.builder(); for (Collection<Symbol> symbols : rewrittenSymbolMapping.asMap().values()) { expectedInputSymbols.add(Iterables.get(symbols, i)); } rewrittenSubPlans.add(context.rewrite(node.getSources().get(i), expectedInputSymbols.build())); } return rewrittenSubPlans.build(); }
@Override public Result apply(TopNNode topNNode, Captures captures, Context context) { UnionNode unionNode = captures.get(CHILD); ImmutableList.Builder<PlanNode> sources = ImmutableList.builder(); for (PlanNode source : unionNode.getSources()) { SymbolMapper.Builder symbolMapper = SymbolMapper.builder(); Set<Symbol> sourceOutputSymbols = ImmutableSet.copyOf(source.getOutputSymbols()); for (Symbol unionOutput : unionNode.getOutputSymbols()) { Set<Symbol> inputSymbols = ImmutableSet.copyOf(unionNode.getSymbolMapping().get(unionOutput)); Symbol unionInput = getLast(intersection(inputSymbols, sourceOutputSymbols)); symbolMapper.put(unionOutput, unionInput); } sources.add(symbolMapper.build().map(topNNode, source, context.getIdAllocator().getNextId())); } return Result.ofPlanNode(new UnionNode( unionNode.getId(), sources.build(), unionNode.getSymbolMapping(), unionNode.getOutputSymbols())); } }
public void testUnmodifiableArrayListMultimapRandomAccess() { ListMultimap<String, Integer> delegate = ArrayListMultimap.create(); delegate.put("foo", 1); delegate.put("foo", 3); ListMultimap<String, Integer> multimap = Multimaps.unmodifiableListMultimap(delegate); assertTrue(multimap.get("foo") instanceof RandomAccess); assertTrue(multimap.get("bar") instanceof RandomAccess); }
public void testSynchronizedListMultimap() { ListMultimap<String, Integer> multimap = Multimaps.synchronizedListMultimap(ArrayListMultimap.<String, Integer>create()); multimap.putAll("foo", Arrays.asList(3, -1, 2, 4, 1)); multimap.putAll("bar", Arrays.asList(1, 2, 3, 1)); assertThat(multimap.removeAll("foo")).containsExactly(3, -1, 2, 4, 1).inOrder(); assertFalse(multimap.containsKey("foo")); assertThat(multimap.replaceValues("bar", Arrays.asList(6, 5))) .containsExactly(1, 2, 3, 1) .inOrder(); assertThat(multimap.get("bar")).containsExactly(6, 5).inOrder(); }
private Map<String, Collection<String>> buildPermissionsMap(Set<String> permissions) { final ListMultimap<String, String> all = ArrayListMultimap.create(); for (String permission : permissions) { final Iterator<String> split = Splitter.on(':').limit(2).split(permission).iterator(); final String group = split.next(); final String action = split.next(); all.put(group, action); } // Create an immutable copy of the map and the collections inside it. return ImmutableMap.copyOf(all.asMap().entrySet() .stream() .collect(Collectors.toMap( Map.Entry::getKey, e -> ImmutableSet.copyOf(e.getValue())))); } }
public void testSynchronizedLinkedListMultimapRandomAccess() { ListMultimap<String, Integer> delegate = LinkedListMultimap.create(); delegate.put("foo", 1); delegate.put("foo", 3); ListMultimap<String, Integer> multimap = Multimaps.synchronizedListMultimap(delegate); assertFalse(multimap.get("foo") instanceof RandomAccess); assertFalse(multimap.get("bar") instanceof RandomAccess); } }