Search in sources :

Example 11 with RelationalExpression

use of com.apple.foundationdb.record.query.plan.temp.RelationalExpression in project fdb-record-layer by FoundationDB.

the class PlannerRepl method printlnReference.

void printlnReference(@Nonnull final ExpressionRef<? extends RelationalExpression> reference, final String prefix) {
    printlnKeyValue(prefix + "class", reference.getClass().getSimpleName());
    getSilently("reference.toString()", reference::toString).ifPresent(referenceAsString -> printlnKeyValue(prefix + "reference", referenceAsString));
    printlnKeyValue(prefix + "name", nameForObjectOrNotInCache(reference));
    printlnKeyValue(prefix + "  members", "");
    for (final RelationalExpression member : reference.getMembers()) {
        printlnKeyValue(prefix + "  " + nameForObjectOrNotInCache(member), "");
        printlnKeyValue(prefix + "      toString()", String.valueOf(member.toString()));
    }
}
Also used : RelationalExpression(com.apple.foundationdb.record.query.plan.temp.RelationalExpression)

Example 12 with RelationalExpression

use of com.apple.foundationdb.record.query.plan.temp.RelationalExpression in project fdb-record-layer by FoundationDB.

the class SelectDataAccessRule method inject.

@Nonnull
@Override
protected ExpressionRef<? extends RelationalExpression> inject(@Nonnull SelectExpression selectExpression, @Nonnull List<? extends PartialMatch> completeMatches, @Nonnull final ExpressionRef<? extends RelationalExpression> compensatedScanGraph) {
    final Set<Quantifier.ForEach> unmatchedQuantifiers = computeIntersectedUnmatchedForEachQuantifiers(selectExpression, completeMatches);
    if (unmatchedQuantifiers.isEmpty()) {
        return compensatedScanGraph;
    }
    // 
    // Create a new SelectExpression that contains all the unmatched for each quantifiers as well as the
    // compensated scan graph.
    // 
    final ImmutableList.Builder<Quantifier.ForEach> allQuantifiersBuilder = ImmutableList.builder();
    unmatchedQuantifiers.stream().map(quantifier -> Quantifier.forEachBuilder().from(quantifier).build(quantifier.getRangesOver())).forEach(allQuantifiersBuilder::add);
    final Quantifier.ForEach compensatedScanQuantifier = Quantifier.forEach(compensatedScanGraph);
    allQuantifiersBuilder.add(compensatedScanQuantifier);
    return GroupExpressionRef.of(new SelectExpression(compensatedScanQuantifier.getFlowedValues(), allQuantifiersBuilder.build(), ImmutableList.of()));
}
Also used : CascadesPlanner(com.apple.foundationdb.record.query.plan.temp.CascadesPlanner) MatchPartitionMatchers.ofExpressionAndMatches(com.apple.foundationdb.record.query.plan.temp.matchers.MatchPartitionMatchers.ofExpressionAndMatches) Quantifier(com.apple.foundationdb.record.query.plan.temp.Quantifier) MatchPartition(com.apple.foundationdb.record.query.plan.temp.MatchPartition) Set(java.util.Set) PartialMatchMatchers.completeMatch(com.apple.foundationdb.record.query.plan.temp.matchers.PartialMatchMatchers.completeMatch) SelectExpression(com.apple.foundationdb.record.query.plan.temp.expressions.SelectExpression) GroupExpressionRef(com.apple.foundationdb.record.query.plan.temp.GroupExpressionRef) RelationalExpressionMatchers.ofType(com.apple.foundationdb.record.query.plan.temp.matchers.RelationalExpressionMatchers.ofType) RelationalExpression(com.apple.foundationdb.record.query.plan.temp.RelationalExpression) PartialMatch(com.apple.foundationdb.record.query.plan.temp.PartialMatch) List(java.util.List) BindingMatcher(com.apple.foundationdb.record.query.plan.temp.matchers.BindingMatcher) ImmutableList(com.google.common.collect.ImmutableList) API(com.apple.foundationdb.annotation.API) ExpressionRef(com.apple.foundationdb.record.query.plan.temp.ExpressionRef) MultiMatcher.some(com.apple.foundationdb.record.query.plan.temp.matchers.MultiMatcher.some) Nonnull(javax.annotation.Nonnull) ImmutableList(com.google.common.collect.ImmutableList) Quantifier(com.apple.foundationdb.record.query.plan.temp.Quantifier) SelectExpression(com.apple.foundationdb.record.query.plan.temp.expressions.SelectExpression) Nonnull(javax.annotation.Nonnull)

Example 13 with RelationalExpression

use of com.apple.foundationdb.record.query.plan.temp.RelationalExpression in project fdb-record-layer by FoundationDB.

the class MatchPartitionMatchers method ofExpressionOptionalAndMatches.

public static <O extends Optional<RelationalExpression>, C extends Collection<? extends PartialMatch>> BindingMatcher<MatchPartition> ofExpressionOptionalAndMatches(@Nonnull final BindingMatcher<O> downstreamExpressionOptional, @Nonnull final BindingMatcher<C> downstreamMatches) {
    return typedWithDownstream(MatchPartition.class, Extractor.identity(), AllOfMatcher.matchingAllOf(MatchPartition.class, ImmutableList.of(typedWithDownstream(MatchPartition.class, Extractor.of(matchPartition -> {
        final Set<PartialMatch> partialMatches = matchPartition.getPartialMatches();
        final Iterator<PartialMatch> iterator = partialMatches.iterator();
        RelationalExpression lastExpression = null;
        while (iterator.hasNext()) {
            final PartialMatch partialMatch = iterator.next();
            if (lastExpression == null) {
                lastExpression = partialMatch.getQueryExpression();
            } else if (lastExpression != partialMatch.getQueryExpression()) {
                return Optional.empty();
            }
        }
        return Optional.ofNullable(lastExpression);
    }, name -> "expressionOptional(" + name + ")"), downstreamExpressionOptional), typedWithDownstream(MatchPartition.class, Extractor.of(MatchPartition::getPartialMatches, name -> "partialMatches(" + name + ")"), downstreamMatches))));
}
Also used : RelationalExpression(com.apple.foundationdb.record.query.plan.temp.RelationalExpression) PartialMatch(com.apple.foundationdb.record.query.plan.temp.PartialMatch) MatchPartition(com.apple.foundationdb.record.query.plan.temp.MatchPartition)

Example 14 with RelationalExpression

use of com.apple.foundationdb.record.query.plan.temp.RelationalExpression in project fdb-record-layer by FoundationDB.

the class PlannerRepl method processIdentifiers.

boolean processIdentifiers(final String potentialIdentifier, final Consumer<RelationalExpression> expressionConsumer, final Consumer<ExpressionRef<? extends RelationalExpression>> referenceConsumer, final Consumer<Quantifier> quantifierConsumer) {
    final State state = getCurrentState();
    final String upperCasePotentialIdentifier = potentialIdentifier.toUpperCase();
    if (upperCasePotentialIdentifier.startsWith("EXP")) {
        @Nullable final RelationalExpression expression = lookupInCache(state.getExpressionCache(), upperCasePotentialIdentifier, "EXP");
        if (expression == null) {
            return false;
        }
        expressionConsumer.accept(expression);
        return true;
    } else if (upperCasePotentialIdentifier.startsWith("REF")) {
        @Nullable final ExpressionRef<? extends RelationalExpression> reference = lookupInCache(state.getReferenceCache(), upperCasePotentialIdentifier, "REF");
        if (reference == null) {
            return false;
        }
        referenceConsumer.accept(reference);
        return true;
    } else if (upperCasePotentialIdentifier.startsWith("QUN")) {
        @Nullable final Quantifier quantifier = lookupInCache(state.getQuantifierCache(), upperCasePotentialIdentifier, "QUN");
        if (quantifier == null) {
            return false;
        }
        quantifierConsumer.accept(quantifier);
        return true;
    }
    return false;
}
Also used : RelationalExpression(com.apple.foundationdb.record.query.plan.temp.RelationalExpression) ExpressionRef(com.apple.foundationdb.record.query.plan.temp.ExpressionRef) Quantifier(com.apple.foundationdb.record.query.plan.temp.Quantifier) Nullable(javax.annotation.Nullable)

Example 15 with RelationalExpression

use of com.apple.foundationdb.record.query.plan.temp.RelationalExpression in project fdb-record-layer by FoundationDB.

the class ExpressionMatcherTest method singleTypeMatcher.

@Test
public void singleTypeMatcher() {
    // we already have a different RecordQueryIndexPlan matcher, but this should still work
    BindingMatcher<RecordQueryIndexPlan> matcher = RecordQueryPlanMatchers.indexPlan();
    final IndexScanParameters fullValueScan = IndexScanComparisons.byValue();
    final ExpressionRef<RelationalExpression> root = GroupExpressionRef.of(new RecordQueryIndexPlan("an_index", fullValueScan, true));
    Optional<PlannerBindings> newBindings = matcher.bindMatches(PlannerBindings.empty(), root.get()).findFirst();
    // check the the bindings are what we expect, and that none of the existing ones were clobbered
    assertTrue(newBindings.isPresent());
    PlannerBindings allBindings = newBindings.get().mergedWith(getExistingBindings());
    assertExistingBindingsSurvived(allBindings);
    assertTrue(newBindings.get().containsKey(matcher));
    assertTrue(allBindings.containsKey(matcher));
    RecordQueryIndexPlan matched = allBindings.get(matcher);
    assertEquals(root.get(), matched);
}
Also used : IndexScanParameters(com.apple.foundationdb.record.provider.foundationdb.IndexScanParameters) RelationalExpression(com.apple.foundationdb.record.query.plan.temp.RelationalExpression) RecordQueryIndexPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryIndexPlan) Test(org.junit.jupiter.api.Test)

Aggregations

RelationalExpression (com.apple.foundationdb.record.query.plan.temp.RelationalExpression)26 ExpressionRef (com.apple.foundationdb.record.query.plan.temp.ExpressionRef)12 Quantifier (com.apple.foundationdb.record.query.plan.temp.Quantifier)11 Nonnull (javax.annotation.Nonnull)10 ImmutableList (com.google.common.collect.ImmutableList)9 List (java.util.List)9 Test (org.junit.jupiter.api.Test)9 PartialMatch (com.apple.foundationdb.record.query.plan.temp.PartialMatch)8 API (com.apple.foundationdb.annotation.API)7 GroupExpressionRef (com.apple.foundationdb.record.query.plan.temp.GroupExpressionRef)7 MatchCandidate (com.apple.foundationdb.record.query.plan.temp.MatchCandidate)7 Collection (java.util.Collection)7 Map (java.util.Map)7 Nullable (javax.annotation.Nullable)7 RecordQueryScanPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryScanPlan)6 PlannerBindings (com.apple.foundationdb.record.query.plan.temp.matchers.PlannerBindings)6 QueryPredicate (com.apple.foundationdb.record.query.predicates.QueryPredicate)6 ImmutableSet (com.google.common.collect.ImmutableSet)6 Optional (java.util.Optional)6 Set (java.util.Set)6