private Set<NullableValue> filterValues(Set<NullableValue> nullableValues, TpchColumn<?> column, Constraint<ColumnHandle> constraint) { return nullableValues.stream() .filter(convertToPredicate(constraint.getSummary(), toColumnHandle(column))) .filter(value -> !constraint.predicate().isPresent() || constraint.predicate().get().test(ImmutableMap.of(toColumnHandle(column), value))) .collect(toSet()); }
private void checkUnknownParameters(Map<String, ValueReference> parameters, Set<String> contentPackParameterNames) { final Predicate<String> containsContentPackParameter = contentPackParameterNames::contains; final Set<String> unknownParameters = parameters.keySet().stream() .filter(containsContentPackParameter.negate()) .collect(Collectors.toSet()); if (!unknownParameters.isEmpty()) { // Ignore unknown parameters for now LOG.debug("Unknown parameters: {}", unknownParameters); } }
/** * Adds a filter to the walked paths. * * @param pathFilter the filter. {@code pathFilter} returns {@code true} if the path should be * accepted and {@code false} otherwise. * @return this */ public DirectoryWalker filter(Predicate<Path> pathFilter) { this.pathFilter = this.pathFilter.and(pathFilter); return this; }
public static boolean containsType(Type type, Predicate<Type> predicate, Predicate<Type>... orPredicates) { for (Predicate<Type> orPredicate : orPredicates) { predicate = predicate.or(orPredicate); } if (predicate.test(type)) { return true; } return type.getTypeParameters().stream().anyMatch(predicate); } }
public Set<QualifiedTablePrefix> calculatePrefixesWithTableName( ConnectorSession connectorSession, Set<QualifiedTablePrefix> prefixes, TupleDomain<ColumnHandle> constraint, Optional<Predicate<Map<ColumnHandle, NullableValue>>> predicate) { Session session = ((FullConnectorSession) connectorSession).getSession(); Optional<Set<String>> tables = filterString(constraint, TABLE_NAME_COLUMN_HANDLE); if (tables.isPresent()) { return prefixes.stream() .flatMap(prefix -> tables.get().stream() .filter(this::isLowerCase) .map(table -> table.toLowerCase(ENGLISH)) .map(table -> new QualifiedObjectName(catalogName, prefix.getSchemaName().get(), table))) .filter(objectName -> metadata.getTableHandle(session, objectName).isPresent() || metadata.getView(session, objectName).isPresent()) .map(QualifiedObjectName::asQualifiedTablePrefix) .collect(toImmutableSet()); } return prefixes.stream() .flatMap(prefix -> Stream.concat( metadata.listTables(session, prefix).stream(), metadata.listViews(session, prefix).stream())) .filter(objectName -> !predicate.isPresent() || predicate.get().test(asFixedValues(objectName))) .map(QualifiedObjectName::asQualifiedTablePrefix) .collect(toImmutableSet()); }
private Set<QualifiedTablePrefix> calculatePrefixesWithSchemaName( ConnectorSession connectorSession, TupleDomain<ColumnHandle> constraint, Optional<Predicate<Map<ColumnHandle, NullableValue>>> predicate) { Optional<Set<String>> schemas = filterString(constraint, SCHEMA_COLUMN_HANDLE); if (schemas.isPresent()) { return schemas.get().stream() .filter(this::isLowerCase) .map(schema -> new QualifiedTablePrefix(catalogName, schema)) .collect(toImmutableSet()); } Session session = ((FullConnectorSession) connectorSession).getSession(); return metadata.listSchemaNames(session, catalogName).stream() .filter(schema -> !predicate.isPresent() || predicate.get().test(schemaAsFixedValues(schema))) .map(schema -> new QualifiedTablePrefix(catalogName, schema)) .collect(toImmutableSet()); }
@Override public Expression visitProject(ProjectNode node, Void context) { // TODO: add simple algebraic solver for projection translation (right now only considers identity projections) Expression underlyingPredicate = node.getSource().accept(this, context); List<Expression> projectionEqualities = node.getAssignments().entrySet().stream() .filter(SYMBOL_MATCHES_EXPRESSION.negate()) .map(ENTRY_TO_EQUALITY) .collect(toImmutableList()); return pullExpressionThroughSymbols(combineConjuncts( ImmutableList.<Expression>builder() .addAll(projectionEqualities) .add(underlyingPredicate) .build()), node.getOutputSymbols()); }
private Mono<Map<String, Object>> initAttributes(ServerWebExchange exchange) { if (this.sessionAttributePredicate == null) { return EMPTY_ATTRIBUTES; } return exchange.getSession().map(session -> session.getAttributes().entrySet().stream() .filter(entry -> this.sessionAttributePredicate.test(entry.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); }
leftProjections.putAll(node.getLeft() .getOutputSymbols().stream() .collect(Collectors.toMap(key -> key, Symbol::toSymbolReference))); .collect(Collectors.toMap(key -> key, Symbol::toSymbolReference))); ImmutableList.Builder<Expression> joinFilterBuilder = ImmutableList.builder(); for (Expression conjunct : extractConjuncts(newJoinPredicate)) { if (joinEqualityExpression(node.getLeft().getOutputSymbols()).test(conjunct)) { ComparisonExpression equality = (ComparisonExpression) conjunct; Optional<Expression> newJoinFilter = Optional.of(combineConjuncts(joinFilterBuilder.build())); if (newJoinFilter.get() == TRUE_LITERAL) { newJoinFilter = Optional.empty(); rightSource, equiJoinClauses, ImmutableList.<Symbol>builder() .addAll(leftSource.getOutputSymbols()) .addAll(rightSource.getOutputSymbols())
private Set<String> getSessions(Flag... flags) { Locality locality = new CacheLocality(this.cache); try (Stream<Key<String>> keys = this.cache.getAdvancedCache().withFlags(flags).keySet().stream()) { return keys.filter(this.filter.and(key -> locality.isLocal(key))).map(key -> key.getValue()).collect(Collectors.toSet()); } }
private static ListenableFuture<?> whenAllStages(Collection<SqlStageExecution> stages, Predicate<StageState> predicate) { checkArgument(!stages.isEmpty(), "stages is empty"); Set<StageId> stageIds = newConcurrentHashSet(stages.stream() .map(SqlStageExecution::getStageId) .collect(toSet())); SettableFuture<?> future = SettableFuture.create(); for (SqlStageExecution stage : stages) { stage.addStateChangeListener(state -> { if (predicate.test(state) && stageIds.remove(stage.getStageId()) && stageIds.isEmpty()) { future.set(null); } }); } return future; }
private PlanNode replaceAllRecursive(PlanNode node, PlanNode nodeToReplace) { node = lookup.resolve(node); if (where.test(node)) { return nodeToReplace; } if (recurseOnlyWhen.test(node)) { List<PlanNode> sources = node.getSources().stream() .map(source -> replaceAllRecursive(source, nodeToReplace)) .collect(toImmutableList()); return replaceChildren(node, sources); } return node; }
private ImmutableSet<ModuleSplit> subsetWithTargeting( ImmutableList<ModuleSplit> splits, Predicate<ApkTargeting> predicate) { return splits.stream() .filter(split -> predicate.test(split.getApkTargeting())) .filter(split -> deviceSpec.map(spec -> splitMatchesDeviceSpec(split, spec)).orElse(true)) .collect(toImmutableSet()); }
/** * Discards any cached role associations for principals satisfying * the given predicate. * * @param predicate a predicate to filter credentials */ public void invalidateAll(Predicate<? super P> predicate) { final Set<ImmutablePair<P, String>> keys = cache.asMap().keySet().stream() .filter(cacheKey -> predicate.test(cacheKey.getLeft())) .collect(Collectors.toSet()); cache.invalidateAll(keys); }
/** Removes XML elements among the direct children that satisfies the given predicate. */ public XmlProtoElementBuilder removeChildrenElementsIf(Predicate<XmlProtoNodeBuilder> filter) { ImmutableList<XmlNode> keptChildren = getChildren() .filter(filter.negate()) .map(builder -> builder.build().getProto()) .collect(toImmutableList()); if (getProtoChildrenList().size() != keptChildren.size()) { element.clearChild().addAllChild(keptChildren); } return this; } }
@SuppressWarnings("unchecked") private <U> void doEmit(Predicate<SubscriptionQueryMessage<?, ?, U>> filter, SubscriptionQueryUpdateMessage<U> update) { updateHandlers.keySet() .stream() .filter(sqm -> filter.test((SubscriptionQueryMessage<?, ?, U>) sqm)) .forEach(query -> Optional.ofNullable(updateHandlers.get(query)) .ifPresent(uh -> doEmit(query, uh, update))); }