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()));
}
}
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()));
}
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))));
}
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;
}
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);
}
Aggregations