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