Search in sources :

Example 1 with Placeholder

use of com.apple.foundationdb.record.query.predicates.ValueComparisonRangePredicate.Placeholder in project fdb-record-layer by FoundationDB.

the class ValueIndexLikeExpansionVisitor method visitExpression.

@Nonnull
@Override
public GraphExpansion visitExpression(@Nonnull FieldKeyExpression fieldKeyExpression) {
    final String fieldName = fieldKeyExpression.getFieldName();
    final KeyExpression.FanType fanType = fieldKeyExpression.getFanType();
    final VisitorState state = getCurrentState();
    final List<String> fieldNamePrefix = state.getFieldNamePrefix();
    final CorrelationIdentifier baseAlias = state.getBaseAlias();
    final List<String> fieldNames = ImmutableList.<String>builder().addAll(fieldNamePrefix).add(fieldName).build();
    final Value value;
    final Placeholder predicate;
    switch(fanType) {
        case FanOut:
            // explode this field and prefixes of this field
            final Quantifier childBase = fieldKeyExpression.explodeField(baseAlias, fieldNamePrefix);
            value = state.registerValue(QuantifiedObjectValue.of(childBase.getAlias()));
            final GraphExpansion childExpansion;
            if (state.isKey()) {
                predicate = value.asPlaceholder(newParameterAlias());
                childExpansion = GraphExpansion.ofPlaceholder(value, predicate);
            } else {
                childExpansion = GraphExpansion.ofResultValue(value);
            }
            final SelectExpression selectExpression = childExpansion.buildSelectWithBase(childBase);
            final Quantifier childQuantifier = Quantifier.forEach(GroupExpressionRef.of(selectExpression));
            final GraphExpansion.Sealed sealedChildExpansion = childExpansion.seal();
            return sealedChildExpansion.derivedWithQuantifier(childQuantifier);
        case None:
            value = state.registerValue(new FieldValue(QuantifiedColumnValue.of(baseAlias, 0), fieldNames));
            if (state.isKey()) {
                predicate = value.asPlaceholder(newParameterAlias());
                return GraphExpansion.ofPlaceholder(value, predicate);
            }
            return GraphExpansion.ofResultValue(value);
        // TODO collect/concatenate function
        case Concatenate:
        default:
    }
    throw new UnsupportedOperationException();
}
Also used : Placeholder(com.apple.foundationdb.record.query.predicates.ValueComparisonRangePredicate.Placeholder) KeyExpression(com.apple.foundationdb.record.metadata.expressions.KeyExpression) FieldKeyExpression(com.apple.foundationdb.record.metadata.expressions.FieldKeyExpression) NestingKeyExpression(com.apple.foundationdb.record.metadata.expressions.NestingKeyExpression) ThenKeyExpression(com.apple.foundationdb.record.metadata.expressions.ThenKeyExpression) EmptyKeyExpression(com.apple.foundationdb.record.metadata.expressions.EmptyKeyExpression) SelectExpression(com.apple.foundationdb.record.query.plan.temp.expressions.SelectExpression) VisitorState(com.apple.foundationdb.record.query.plan.temp.ValueIndexLikeExpansionVisitor.VisitorState) QuantifiedObjectValue(com.apple.foundationdb.record.query.predicates.QuantifiedObjectValue) Value(com.apple.foundationdb.record.query.predicates.Value) EmptyValue(com.apple.foundationdb.record.query.predicates.EmptyValue) KeyExpressionWithValue(com.apple.foundationdb.record.metadata.expressions.KeyExpressionWithValue) FieldValue(com.apple.foundationdb.record.query.predicates.FieldValue) QuantifiedColumnValue(com.apple.foundationdb.record.query.predicates.QuantifiedColumnValue) FieldValue(com.apple.foundationdb.record.query.predicates.FieldValue) Nonnull(javax.annotation.Nonnull)

Example 2 with Placeholder

use of com.apple.foundationdb.record.query.predicates.ValueComparisonRangePredicate.Placeholder in project fdb-record-layer by FoundationDB.

the class GraphExpansion method seal.

/**
 * Method to <em>seal</em> a graph expansion in an instance of {@link Sealed}. A sealed graph expansion is immutable
 * and can only be used to (repeatedly) build actual expressions.
 * A graph expansion object may contain duplicate information that have been added to it by callers. That is allowed
 * and supported. In fact, in most cases, duplicates among e.g. {@link QueryPredicate}s come from merging individual
 * {@link GraphExpansion}s into more complex ones. This method normalizes all elements beforehand in order to
 * eventually return a sealed version of itself (which is not allowed to contain duplicates).
 *
 * @return a sealed graph expansion
 */
@Nonnull
public Sealed seal() {
    final GraphExpansion graphExpansion;
    if (!placeholders.isEmpty()) {
        // There may be placeholders in the current (local) expansion step that are equivalent to each other but we
        // don't know that yet.
        final ImmutableSet<QueryPredicate> localPredicates = ImmutableSet.copyOf(getPredicates());
        final List<Placeholder> resultPlaceHolders = Lists.newArrayList(placeholders);
        final List<Pair<Placeholder, Integer>> localPlaceHolderPairs = IntStream.range(0, placeholders.size()).mapToObj(i -> Pair.of(placeholders.get(i), i)).filter(p -> localPredicates.contains(p.getKey())).collect(Collectors.toList());
        final List<QueryPredicate> resultPredicates = Lists.newArrayList();
        for (final QueryPredicate queryPredicate : getPredicates()) {
            if (queryPredicate instanceof Placeholder) {
                final Placeholder localPlaceHolder = (Placeholder) queryPredicate;
                final AliasMap identities = AliasMap.identitiesFor(localPlaceHolder.getCorrelatedTo());
                final Iterator<Pair<Placeholder, Integer>> iterator = localPlaceHolderPairs.iterator();
                int foundAtOrdinal = -1;
                while (iterator.hasNext()) {
                    final Pair<Placeholder, Integer> currentPlaceholderPair = iterator.next();
                    final Placeholder currentPlaceHolder = currentPlaceholderPair.getKey();
                    if (localPlaceHolder.semanticEqualsWithoutParameterAlias(currentPlaceHolder, identities)) {
                        if (foundAtOrdinal < 0) {
                            foundAtOrdinal = currentPlaceholderPair.getRight();
                            resultPredicates.add(currentPlaceHolder);
                        } else {
                            resultPlaceHolders.set(currentPlaceholderPair.getRight(), resultPlaceHolders.get(foundAtOrdinal));
                        }
                        iterator.remove();
                    }
                }
            } else {
                resultPredicates.add(queryPredicate);
            }
        }
        graphExpansion = new GraphExpansion(resultValues, resultPredicates, getQuantifiers(), resultPlaceHolders);
    } else {
        graphExpansion = new GraphExpansion(resultValues, getPredicates(), getQuantifiers(), ImmutableList.of());
    }
    return graphExpansion.new Sealed();
}
Also used : IntStream(java.util.stream.IntStream) Verify(com.google.common.base.Verify) ImmutableSet(com.google.common.collect.ImmutableSet) Iterator(java.util.Iterator) QueryPredicate(com.apple.foundationdb.record.query.predicates.QueryPredicate) SelectExpression(com.apple.foundationdb.record.query.plan.temp.expressions.SelectExpression) ValueComparisonRangePredicate(com.apple.foundationdb.record.query.predicates.ValueComparisonRangePredicate) AndPredicate(com.apple.foundationdb.record.query.predicates.AndPredicate) Collectors(java.util.stream.Collectors) Value(com.apple.foundationdb.record.query.predicates.Value) List(java.util.List) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Pair(org.apache.commons.lang3.tuple.Pair) Placeholder(com.apple.foundationdb.record.query.predicates.ValueComparisonRangePredicate.Placeholder) QuantifiedColumnValue(com.apple.foundationdb.record.query.predicates.QuantifiedColumnValue) Nonnull(javax.annotation.Nonnull) Placeholder(com.apple.foundationdb.record.query.predicates.ValueComparisonRangePredicate.Placeholder) QueryPredicate(com.apple.foundationdb.record.query.predicates.QueryPredicate) Pair(org.apache.commons.lang3.tuple.Pair) Nonnull(javax.annotation.Nonnull)

Example 3 with Placeholder

use of com.apple.foundationdb.record.query.predicates.ValueComparisonRangePredicate.Placeholder in project fdb-record-layer by FoundationDB.

the class SelectExpression method subsumedBy.

@Nonnull
@Override
public Iterable<MatchInfo> subsumedBy(@Nonnull final RelationalExpression candidateExpression, @Nonnull final AliasMap aliasMap, @Nonnull final IdentityBiMap<Quantifier, PartialMatch> partialMatchMap) {
    // TODO This method should be simplified by adding some structure to it.
    final Collection<MatchInfo> matchInfos = PartialMatch.matchesFromMap(partialMatchMap);
    Verify.verify(this != candidateExpression);
    if (getClass() != candidateExpression.getClass()) {
        return ImmutableList.of();
    }
    final SelectExpression otherSelectExpression = (SelectExpression) candidateExpression;
    // merge parameter maps -- early out if a binding clashes
    final ImmutableList<Map<CorrelationIdentifier, ComparisonRange>> parameterBindingMaps = matchInfos.stream().map(MatchInfo::getParameterBindingMap).collect(ImmutableList.toImmutableList());
    final Optional<Map<CorrelationIdentifier, ComparisonRange>> mergedParameterBindingMapOptional = MatchInfo.tryMergeParameterBindings(parameterBindingMaps);
    if (!mergedParameterBindingMapOptional.isPresent()) {
        return ImmutableList.of();
    }
    final Map<CorrelationIdentifier, ComparisonRange> mergedParameterBindingMap = mergedParameterBindingMapOptional.get();
    final ImmutableSet.Builder<CorrelationIdentifier> matchedCorrelatedToBuilder = ImmutableSet.builder();
    // for-each quantifiers. Also keep track of all aliases the matched quantifiers are correlated to.
    for (final Quantifier quantifier : getQuantifiers()) {
        if (partialMatchMap.containsKeyUnwrapped(quantifier)) {
            if (quantifier instanceof Quantifier.ForEach) {
                // current quantifier is matched
                final PartialMatch childPartialMatch = Objects.requireNonNull(partialMatchMap.getUnwrapped(quantifier));
                if (!childPartialMatch.getQueryExpression().computeUnmatchedForEachQuantifiers(childPartialMatch).isEmpty()) {
                    return ImmutableList.of();
                }
            }
            matchedCorrelatedToBuilder.addAll(quantifier.getCorrelatedTo());
        }
    }
    for (final Value resultValue : getResultValues()) {
        matchedCorrelatedToBuilder.addAll(resultValue.getCorrelatedTo());
    }
    final ImmutableSet<CorrelationIdentifier> matchedCorrelatedTo = matchedCorrelatedToBuilder.build();
    if (getQuantifiers().stream().anyMatch(quantifier -> quantifier instanceof Quantifier.ForEach && !partialMatchMap.containsKeyUnwrapped(quantifier))) {
        return ImmutableList.of();
    }
    final boolean allNonMatchedQuantifiersIndependent = getQuantifiers().stream().filter(quantifier -> !partialMatchMap.containsKeyUnwrapped(quantifier)).noneMatch(quantifier -> matchedCorrelatedTo.contains(quantifier.getAlias()));
    if (!allNonMatchedQuantifiersIndependent) {
        return ImmutableList.of();
    }
    // Loop through all for each quantifiers on the other side to ensure that they are all matched.
    // If any are not matched we cannot establish a match at all.
    final boolean allOtherForEachQuantifiersMatched = otherSelectExpression.getQuantifiers().stream().filter(quantifier -> quantifier instanceof Quantifier.ForEach).allMatch(quantifier -> aliasMap.containsTarget(quantifier.getAlias()));
    // would help us here to make sure the additional non-matched quantifier is not eliminating records.
    if (!allOtherForEachQuantifiersMatched) {
        return ImmutableList.of();
    }
    // 
    // Map predicates on the query side to predicates on the candidate side. Record parameter bindings and/or
    // compensations for each mapped predicate.
    // A predicate on this side (the query side) can cause us to filter out rows, a mapped predicate (for that
    // predicate) can only filter out fewer rows which is correct and can be compensated for. The important part
    // is that we must not have predicates on the other (candidate) side at the end of this mapping process which
    // would mean that the candidate eliminates records that the query side may not eliminate. If we detect that
    // case we MUST not create a match.
    // 
    final ImmutableList.Builder<Iterable<PredicateMapping>> predicateMappingsBuilder = ImmutableList.builder();
    // 
    if (getPredicates().isEmpty()) {
        final boolean allNonFiltering = otherSelectExpression.getPredicates().stream().allMatch(queryPredicate -> queryPredicate instanceof Placeholder || queryPredicate.isTautology());
        if (allNonFiltering) {
            return MatchInfo.tryMerge(partialMatchMap, mergedParameterBindingMap, PredicateMap.empty()).map(ImmutableList::of).orElse(ImmutableList.of());
        } else {
            return ImmutableList.of();
        }
    }
    for (final QueryPredicate predicate : getPredicates()) {
        final Set<PredicateMapping> impliedMappingsForPredicate = predicate.findImpliedMappings(aliasMap, otherSelectExpression.getPredicates());
        predicateMappingsBuilder.add(impliedMappingsForPredicate);
    }
    // 
    // We now have a multimap from predicates on the query side to predicates on the candidate side. In the trivial
    // case this multimap only contains singular mappings for a query predicate. If it doesn't we need to enumerate
    // through their cross product exhaustively. Each complete and non-contradictory element of that cross product
    // can lead to a match.
    // 
    final EnumeratingIterable<PredicateMapping> crossedMappings = CrossProduct.crossProduct(predicateMappingsBuilder.build());
    return IterableHelpers.flatMap(crossedMappings, predicateMappings -> {
        final Set<QueryPredicate> unmappedOtherPredicates = Sets.newIdentityHashSet();
        unmappedOtherPredicates.addAll(otherSelectExpression.getPredicates());
        final Map<CorrelationIdentifier, ComparisonRange> parameterBindingMap = Maps.newHashMap();
        final PredicateMap.Builder predicateMapBuilder = PredicateMap.builder();
        for (final PredicateMapping predicateMapping : predicateMappings) {
            predicateMapBuilder.put(predicateMapping.getQueryPredicate(), predicateMapping);
            unmappedOtherPredicates.remove(predicateMapping.getCandidatePredicate());
            final Optional<CorrelationIdentifier> parameterAliasOptional = predicateMapping.getParameterAliasOptional();
            final Optional<ComparisonRange> comparisonRangeOptional = predicateMapping.getComparisonRangeOptional();
            if (parameterAliasOptional.isPresent() && comparisonRangeOptional.isPresent()) {
                parameterBindingMap.put(parameterAliasOptional.get(), comparisonRangeOptional.get());
            }
        }
        // 
        // Last chance for unmapped predicates - if there is a placeholder or a tautology on the other side that is still
        // unmapped, we can (and should) remove it from the unmapped other set now. The reasoning is that this predicate is
        // not filtering so it does not cause records to be filtered that are not filtered on the query side.
        // 
        unmappedOtherPredicates.removeIf(queryPredicate -> queryPredicate instanceof Placeholder || queryPredicate.isTautology());
        if (!unmappedOtherPredicates.isEmpty()) {
            return ImmutableList.of();
        }
        final Optional<? extends PredicateMap> predicateMapOptional = predicateMapBuilder.buildMaybe();
        return predicateMapOptional.map(predicateMap -> {
            final Optional<Map<CorrelationIdentifier, ComparisonRange>> allParameterBindingMapOptional = MatchInfo.tryMergeParameterBindings(ImmutableList.of(mergedParameterBindingMap, parameterBindingMap));
            return allParameterBindingMapOptional.flatMap(allParameterBindingMap -> MatchInfo.tryMerge(partialMatchMap, allParameterBindingMap, predicateMap)).map(ImmutableList::of).orElse(ImmutableList.of());
        }).orElse(ImmutableList.of());
    });
}
Also used : ValuePredicate(com.apple.foundationdb.record.query.predicates.ValuePredicate) RelationalExpressionWithPredicates(com.apple.foundationdb.record.query.plan.temp.RelationalExpressionWithPredicates) Quantifier(com.apple.foundationdb.record.query.plan.temp.Quantifier) PredicateWithValue(com.apple.foundationdb.record.query.predicates.PredicateWithValue) ValueComparisonRangePredicate(com.apple.foundationdb.record.query.predicates.ValueComparisonRangePredicate) Function(java.util.function.Function) PredicateMap(com.apple.foundationdb.record.query.plan.temp.PredicateMap) Multimaps(com.google.common.collect.Multimaps) PartialMatch(com.apple.foundationdb.record.query.plan.temp.PartialMatch) HashMultimap(com.google.common.collect.HashMultimap) ImmutableList(com.google.common.collect.ImmutableList) ComparisonRange(com.apple.foundationdb.record.query.plan.temp.ComparisonRange) IterableHelpers(com.apple.foundationdb.record.query.plan.temp.IterableHelpers) Map(java.util.Map) Compensation(com.apple.foundationdb.record.query.plan.temp.Compensation) IdentityBiMap(com.apple.foundationdb.record.query.plan.temp.IdentityBiMap) Placeholder(com.apple.foundationdb.record.query.predicates.ValueComparisonRangePredicate.Placeholder) AliasMap(com.apple.foundationdb.record.query.plan.temp.AliasMap) Nonnull(javax.annotation.Nonnull) PredicateMapping(com.apple.foundationdb.record.query.plan.temp.PredicateMultiMap.PredicateMapping) Verify(com.google.common.base.Verify) ImmutableSet(com.google.common.collect.ImmutableSet) Equivalence(com.google.common.base.Equivalence) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) Set(java.util.Set) InternalPlannerGraphRewritable(com.apple.foundationdb.record.query.plan.temp.explain.InternalPlannerGraphRewritable) QueryPredicate(com.apple.foundationdb.record.query.predicates.QueryPredicate) EnumeratingIterable(com.apple.foundationdb.record.query.combinatorics.EnumeratingIterable) Streams(com.google.common.collect.Streams) AndPredicate(com.apple.foundationdb.record.query.predicates.AndPredicate) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) RelationalExpression(com.apple.foundationdb.record.query.plan.temp.RelationalExpression) Objects(java.util.Objects) Value(com.apple.foundationdb.record.query.predicates.Value) Comparisons(com.apple.foundationdb.record.query.expressions.Comparisons) List(java.util.List) Stream(java.util.stream.Stream) Sargable(com.apple.foundationdb.record.query.predicates.ValueComparisonRangePredicate.Sargable) CorrelationIdentifier(com.apple.foundationdb.record.query.plan.temp.CorrelationIdentifier) CrossProduct(com.apple.foundationdb.record.query.combinatorics.CrossProduct) MatchInfo(com.apple.foundationdb.record.query.plan.temp.MatchInfo) Optional(java.util.Optional) API(com.apple.foundationdb.annotation.API) PlannerGraph(com.apple.foundationdb.record.query.plan.temp.explain.PlannerGraph) Placeholder(com.apple.foundationdb.record.query.predicates.ValueComparisonRangePredicate.Placeholder) EnumeratingIterable(com.apple.foundationdb.record.query.combinatorics.EnumeratingIterable) ImmutableList(com.google.common.collect.ImmutableList) PredicateMap(com.apple.foundationdb.record.query.plan.temp.PredicateMap) ImmutableSet(com.google.common.collect.ImmutableSet) PartialMatch(com.apple.foundationdb.record.query.plan.temp.PartialMatch) QueryPredicate(com.apple.foundationdb.record.query.predicates.QueryPredicate) Optional(java.util.Optional) PredicateMapping(com.apple.foundationdb.record.query.plan.temp.PredicateMultiMap.PredicateMapping) MatchInfo(com.apple.foundationdb.record.query.plan.temp.MatchInfo) CorrelationIdentifier(com.apple.foundationdb.record.query.plan.temp.CorrelationIdentifier) PredicateWithValue(com.apple.foundationdb.record.query.predicates.PredicateWithValue) Value(com.apple.foundationdb.record.query.predicates.Value) Quantifier(com.apple.foundationdb.record.query.plan.temp.Quantifier) ComparisonRange(com.apple.foundationdb.record.query.plan.temp.ComparisonRange) PredicateMap(com.apple.foundationdb.record.query.plan.temp.PredicateMap) Map(java.util.Map) IdentityBiMap(com.apple.foundationdb.record.query.plan.temp.IdentityBiMap) AliasMap(com.apple.foundationdb.record.query.plan.temp.AliasMap) ImmutableMap(com.google.common.collect.ImmutableMap) Nonnull(javax.annotation.Nonnull)

Example 4 with Placeholder

use of com.apple.foundationdb.record.query.predicates.ValueComparisonRangePredicate.Placeholder in project fdb-record-layer by FoundationDB.

the class ValueIndexLikeExpansionVisitor method visitExpression.

@Nonnull
@Override
public GraphExpansion visitExpression(@Nonnull final KeyExpressionWithValue keyExpressionWithValue) {
    final VisitorState state = getCurrentState();
    final Value value = state.registerValue(keyExpressionWithValue.toValue(state.getBaseAlias(), state.getFieldNamePrefix()));
    if (state.isKey()) {
        final Placeholder predicate = value.asPlaceholder(newParameterAlias());
        return GraphExpansion.ofPlaceholder(value, predicate);
    }
    return GraphExpansion.ofResultValue(value);
}
Also used : Placeholder(com.apple.foundationdb.record.query.predicates.ValueComparisonRangePredicate.Placeholder) VisitorState(com.apple.foundationdb.record.query.plan.temp.ValueIndexLikeExpansionVisitor.VisitorState) QuantifiedObjectValue(com.apple.foundationdb.record.query.predicates.QuantifiedObjectValue) Value(com.apple.foundationdb.record.query.predicates.Value) EmptyValue(com.apple.foundationdb.record.query.predicates.EmptyValue) KeyExpressionWithValue(com.apple.foundationdb.record.metadata.expressions.KeyExpressionWithValue) FieldValue(com.apple.foundationdb.record.query.predicates.FieldValue) QuantifiedColumnValue(com.apple.foundationdb.record.query.predicates.QuantifiedColumnValue) Nonnull(javax.annotation.Nonnull)

Example 5 with Placeholder

use of com.apple.foundationdb.record.query.predicates.ValueComparisonRangePredicate.Placeholder in project fdb-record-layer by FoundationDB.

the class MatchableSortExpression method forPartialMatch.

/**
 * This synthesizes a list of {@link BoundKeyPart}s from the current partial match and the ordering information
 * contained in this expression. Using the list of parameter ids, each {@link BoundKeyPart} links together the
 * (1) normalized key expression that originally produced the key (from index, or common primary key)
 * (2) a comparison range for this parameter which is contained in the already existent partial match
 * (3) the predicate on the query part that participated and bound this parameter (and implicitly was used to
 *     synthesize the comparison range in (2)
 * (4) the candidate predicate on the candidate side that is the {@link Placeholder} for the parameter
 * @param partialMatch the pre-existing partial match on {@code (expression, this)} that the caller wants to adjust.
 * @return a list of bound key parts that express the order of the outgoing data stream and their respective mappings
 *         between query and match candidate
 */
@Nonnull
private List<BoundKeyPart> forPartialMatch(@Nonnull PartialMatch partialMatch) {
    final MatchCandidate matchCandidate = partialMatch.getMatchCandidate();
    final MatchInfo matchInfo = partialMatch.getMatchInfo();
    final Map<CorrelationIdentifier, ComparisonRange> parameterBindingMap = matchInfo.getParameterBindingMap();
    final PredicateMap accumulatedPredicateMap = matchInfo.getAccumulatedPredicateMap();
    final ImmutableMap<CorrelationIdentifier, QueryPredicate> parameterBindingPredicateMap = accumulatedPredicateMap.entries().stream().filter(entry -> {
        final PredicateMapping predicateMapping = entry.getValue();
        return predicateMapping.getParameterAliasOptional().isPresent();
    }).collect(ImmutableMap.toImmutableMap(entry -> {
        final PredicateMapping predicateMapping = entry.getValue();
        return Objects.requireNonNull(predicateMapping.getParameterAliasOptional().orElseThrow(() -> new RecordCoreException("parameter alias should have been set")));
    }, entry -> Objects.requireNonNull(entry.getKey())));
    final List<KeyExpression> normalizedKeys = matchCandidate.getAlternativeKeyExpression().normalizeKeyForPositions();
    final ImmutableList.Builder<BoundKeyPart> builder = ImmutableList.builder();
    final List<CorrelationIdentifier> candidateParameterIds = matchCandidate.getParameters();
    for (final CorrelationIdentifier parameterId : sortParameterIds) {
        final int ordinalInCandidate = candidateParameterIds.indexOf(parameterId);
        Verify.verify(ordinalInCandidate >= 0);
        final KeyExpression normalizedKey = normalizedKeys.get(ordinalInCandidate);
        Objects.requireNonNull(parameterId);
        Objects.requireNonNull(normalizedKey);
        @Nullable final ComparisonRange comparisonRange = parameterBindingMap.get(parameterId);
        @Nullable final QueryPredicate queryPredicate = parameterBindingPredicateMap.get(parameterId);
        Verify.verify(comparisonRange == null || comparisonRange.getRangeType() == ComparisonRange.Type.EMPTY || queryPredicate != null);
        builder.add(BoundKeyPart.of(normalizedKey, comparisonRange == null ? ComparisonRange.Type.EMPTY : comparisonRange.getRangeType(), queryPredicate, isReverse));
    }
    return builder.build();
}
Also used : Iterables(com.google.common.collect.Iterables) Quantifier(com.apple.foundationdb.record.query.plan.temp.Quantifier) GroupExpressionRef(com.apple.foundationdb.record.query.plan.temp.GroupExpressionRef) Supplier(java.util.function.Supplier) PredicateMap(com.apple.foundationdb.record.query.plan.temp.PredicateMap) PartialMatch(com.apple.foundationdb.record.query.plan.temp.PartialMatch) ImmutableList(com.google.common.collect.ImmutableList) RecordCoreException(com.apple.foundationdb.record.RecordCoreException) ComparisonRange(com.apple.foundationdb.record.query.plan.temp.ComparisonRange) Attribute(com.apple.foundationdb.record.query.plan.temp.explain.Attribute) Map(java.util.Map) MatchCandidate(com.apple.foundationdb.record.query.plan.temp.MatchCandidate) Placeholder(com.apple.foundationdb.record.query.predicates.ValueComparisonRangePredicate.Placeholder) AliasMap(com.apple.foundationdb.record.query.plan.temp.AliasMap) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) PredicateMapping(com.apple.foundationdb.record.query.plan.temp.PredicateMultiMap.PredicateMapping) KeyExpression(com.apple.foundationdb.record.metadata.expressions.KeyExpression) AdjustMatchRule(com.apple.foundationdb.record.query.plan.temp.rules.AdjustMatchRule) Verify(com.google.common.base.Verify) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) InternalPlannerGraphRewritable(com.apple.foundationdb.record.query.plan.temp.explain.InternalPlannerGraphRewritable) QueryPredicate(com.apple.foundationdb.record.query.predicates.QueryPredicate) RelationalExpression(com.apple.foundationdb.record.query.plan.temp.RelationalExpression) Objects(java.util.Objects) BoundKeyPart(com.apple.foundationdb.record.query.plan.temp.BoundKeyPart) Value(com.apple.foundationdb.record.query.predicates.Value) List(java.util.List) CorrelationIdentifier(com.apple.foundationdb.record.query.plan.temp.CorrelationIdentifier) MatchInfo(com.apple.foundationdb.record.query.plan.temp.MatchInfo) Optional(java.util.Optional) RemoveSortRule(com.apple.foundationdb.record.query.plan.temp.rules.RemoveSortRule) API(com.apple.foundationdb.annotation.API) PlannerGraph(com.apple.foundationdb.record.query.plan.temp.explain.PlannerGraph) NodeInfo(com.apple.foundationdb.record.query.plan.temp.explain.NodeInfo) QueryPredicate(com.apple.foundationdb.record.query.predicates.QueryPredicate) ImmutableList(com.google.common.collect.ImmutableList) KeyExpression(com.apple.foundationdb.record.metadata.expressions.KeyExpression) PredicateMap(com.apple.foundationdb.record.query.plan.temp.PredicateMap) BoundKeyPart(com.apple.foundationdb.record.query.plan.temp.BoundKeyPart) PredicateMapping(com.apple.foundationdb.record.query.plan.temp.PredicateMultiMap.PredicateMapping) RecordCoreException(com.apple.foundationdb.record.RecordCoreException) MatchInfo(com.apple.foundationdb.record.query.plan.temp.MatchInfo) CorrelationIdentifier(com.apple.foundationdb.record.query.plan.temp.CorrelationIdentifier) MatchCandidate(com.apple.foundationdb.record.query.plan.temp.MatchCandidate) ComparisonRange(com.apple.foundationdb.record.query.plan.temp.ComparisonRange) Nullable(javax.annotation.Nullable) Nonnull(javax.annotation.Nonnull)

Aggregations

Value (com.apple.foundationdb.record.query.predicates.Value)5 Placeholder (com.apple.foundationdb.record.query.predicates.ValueComparisonRangePredicate.Placeholder)5 Nonnull (javax.annotation.Nonnull)5 QuantifiedColumnValue (com.apple.foundationdb.record.query.predicates.QuantifiedColumnValue)3 QueryPredicate (com.apple.foundationdb.record.query.predicates.QueryPredicate)3 Verify (com.google.common.base.Verify)3 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 List (java.util.List)3 API (com.apple.foundationdb.annotation.API)2 KeyExpression (com.apple.foundationdb.record.metadata.expressions.KeyExpression)2 KeyExpressionWithValue (com.apple.foundationdb.record.metadata.expressions.KeyExpressionWithValue)2 AliasMap (com.apple.foundationdb.record.query.plan.temp.AliasMap)2 ComparisonRange (com.apple.foundationdb.record.query.plan.temp.ComparisonRange)2 CorrelationIdentifier (com.apple.foundationdb.record.query.plan.temp.CorrelationIdentifier)2 MatchInfo (com.apple.foundationdb.record.query.plan.temp.MatchInfo)2 PartialMatch (com.apple.foundationdb.record.query.plan.temp.PartialMatch)2 PredicateMap (com.apple.foundationdb.record.query.plan.temp.PredicateMap)2 PredicateMapping (com.apple.foundationdb.record.query.plan.temp.PredicateMultiMap.PredicateMapping)2 Quantifier (com.apple.foundationdb.record.query.plan.temp.Quantifier)2