Search in sources :

Example 1 with ExistsPredicate

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

the class OneOfThemWithComparison method expand.

@Override
public GraphExpansion expand(@Nonnull final CorrelationIdentifier baseAlias, @Nonnull final List<String> fieldNamePrefix) {
    List<String> fieldNames = ImmutableList.<String>builder().addAll(fieldNamePrefix).add(getFieldName()).build();
    final Quantifier childBase = Quantifier.forEach(GroupExpressionRef.of(ExplodeExpression.explodeField(baseAlias, 0, fieldNames)));
    final SelectExpression selectExpression = GraphExpansion.ofPredicate(QuantifiedObjectValue.of(childBase.getAlias()).withComparison(comparison)).buildSelectWithBase(childBase);
    final Quantifier.Existential childQuantifier = Quantifier.existential(GroupExpressionRef.of(selectExpression));
    // create a query component that creates a path to this prefix and then applies this to it
    // this is needed for reapplication of the component if the sub query cannot be matched or only matched with
    // compensation
    QueryComponent withPrefix = this;
    for (int i = fieldNamePrefix.size() - 1; i >= 0; i--) {
        final String fieldName = fieldNames.get(i);
        withPrefix = Query.field(fieldName).matches(withPrefix);
    }
    return GraphExpansion.ofPredicateAndQuantifier(new ExistsPredicate(childQuantifier.getAlias(), withPrefix), childQuantifier);
}
Also used : ExistsPredicate(com.apple.foundationdb.record.query.predicates.ExistsPredicate) Quantifier(com.apple.foundationdb.record.query.plan.temp.Quantifier) SelectExpression(com.apple.foundationdb.record.query.plan.temp.expressions.SelectExpression)

Example 2 with ExistsPredicate

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

the class OneOfThemWithComponent method expand.

@Override
public GraphExpansion expand(@Nonnull final CorrelationIdentifier baseAlias, @Nonnull final List<String> fieldNamePrefix) {
    List<String> fieldNames = ImmutableList.<String>builder().addAll(fieldNamePrefix).add(getFieldName()).build();
    final Quantifier.ForEach childBase = Quantifier.forEach(GroupExpressionRef.of(ExplodeExpression.explodeField(baseAlias, 0, fieldNames)));
    final GraphExpansion graphExpansion = getChild().expand(childBase.getAlias(), Collections.emptyList());
    final SelectExpression selectExpression = graphExpansion.buildSelectWithBase(childBase);
    Quantifier.Existential childQuantifier = Quantifier.existential(GroupExpressionRef.of(selectExpression));
    // create a query component that creates a path to this prefix and then applies this to it
    // this is needed for reapplication of the component if the sub query cannot be matched or only matched with
    // compensation
    QueryComponent withPrefix = this;
    for (int i = fieldNamePrefix.size() - 1; i >= 0; i--) {
        final String fieldName = fieldNames.get(i);
        withPrefix = Query.field(fieldName).matches(withPrefix);
    }
    return GraphExpansion.ofPredicateAndQuantifier(new ExistsPredicate(childQuantifier.getAlias(), withPrefix), childQuantifier);
}
Also used : GraphExpansion(com.apple.foundationdb.record.query.plan.temp.GraphExpansion) ExistsPredicate(com.apple.foundationdb.record.query.predicates.ExistsPredicate) Quantifier(com.apple.foundationdb.record.query.plan.temp.Quantifier) SelectExpression(com.apple.foundationdb.record.query.plan.temp.expressions.SelectExpression)

Aggregations

Quantifier (com.apple.foundationdb.record.query.plan.temp.Quantifier)2 SelectExpression (com.apple.foundationdb.record.query.plan.temp.expressions.SelectExpression)2 ExistsPredicate (com.apple.foundationdb.record.query.predicates.ExistsPredicate)2 GraphExpansion (com.apple.foundationdb.record.query.plan.temp.GraphExpansion)1