Search in sources :

Example 1 with OneOfThemWithComparison

use of com.apple.foundationdb.record.query.expressions.OneOfThemWithComparison in project fdb-record-layer by FoundationDB.

the class InExtractor method extractInClauses.

@SuppressWarnings("unchecked")
private QueryComponent extractInClauses() {
    final AtomicInteger bindingIndex = new AtomicInteger();
    return mapClauses(filter, (withComparison, fields) -> {
        if (withComparison.getComparison().getType() == Comparisons.Type.IN) {
            String bindingName = Bindings.Internal.IN.bindingName(withComparison.getName() + "__" + bindingIndex.getAndIncrement());
            List<FieldKeyExpression> nestedFields = null;
            if (fields != null && (withComparison instanceof FieldWithComparison || withComparison instanceof OneOfThemWithComparison)) {
                nestedFields = new ArrayList<>(fields);
                nestedFields.add(Key.Expressions.field(((BaseField) withComparison).getFieldName(), withComparison instanceof FieldWithComparison ? KeyExpression.FanType.None : KeyExpression.FanType.FanOut));
            }
            KeyExpression orderingKey = getOrderingKey(nestedFields);
            if (withComparison.getComparison() instanceof Comparisons.ComparisonWithParameter) {
                final String parameterName = ((Comparisons.ComparisonWithParameter) withComparison.getComparison()).getParameter();
                inClauses.add(new InParameterClause(bindingName, parameterName, orderingKey));
            } else {
                final List<Object> comparand = (List<Object>) withComparison.getComparison().getComparand();
                // ListComparison does not allow empty/null
                if (comparand != null && comparand.size() == 1) {
                    return withComparison.withOtherComparison(new Comparisons.SimpleComparison(Comparisons.Type.EQUALS, comparand.get(0)));
                }
                inClauses.add(new InValuesClause(bindingName, comparand, orderingKey));
            }
            return withComparison.withOtherComparison(new Comparisons.ParameterComparison(Comparisons.Type.EQUALS, bindingName, Bindings.Internal.IN));
        } else {
            return withComparison;
        }
    }, Collections.emptyList());
}
Also used : BaseField(com.apple.foundationdb.record.query.expressions.BaseField) OneOfThemWithComparison(com.apple.foundationdb.record.query.expressions.OneOfThemWithComparison) FieldKeyExpression(com.apple.foundationdb.record.metadata.expressions.FieldKeyExpression) NestingKeyExpression(com.apple.foundationdb.record.metadata.expressions.NestingKeyExpression) KeyExpression(com.apple.foundationdb.record.metadata.expressions.KeyExpression) FieldKeyExpression(com.apple.foundationdb.record.metadata.expressions.FieldKeyExpression) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Comparisons(com.apple.foundationdb.record.query.expressions.Comparisons) FieldWithComparison(com.apple.foundationdb.record.query.expressions.FieldWithComparison) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List)

Aggregations

FieldKeyExpression (com.apple.foundationdb.record.metadata.expressions.FieldKeyExpression)1 KeyExpression (com.apple.foundationdb.record.metadata.expressions.KeyExpression)1 NestingKeyExpression (com.apple.foundationdb.record.metadata.expressions.NestingKeyExpression)1 BaseField (com.apple.foundationdb.record.query.expressions.BaseField)1 Comparisons (com.apple.foundationdb.record.query.expressions.Comparisons)1 FieldWithComparison (com.apple.foundationdb.record.query.expressions.FieldWithComparison)1 OneOfThemWithComparison (com.apple.foundationdb.record.query.expressions.OneOfThemWithComparison)1 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1