use of com.apple.foundationdb.record.query.expressions.QueryComponent in project fdb-record-layer by FoundationDB.
the class JoinedRecordPlanner method buildQuery.
@Nonnull
private RecordQuery buildQuery(@Nonnull PendingType pendingType) {
final List<QueryComponent> conditions = new ArrayList<>();
for (PendingJoin pendingJoin : pendingType.pendingJoins) {
final boolean bound;
final KeyExpression expression;
if (pendingJoin.pendingLeft == pendingType) {
bound = pendingJoin.rightBound;
expression = pendingJoin.join.getLeftExpression();
} else if (pendingJoin.pendingRight == pendingType) {
bound = pendingJoin.leftBound;
expression = pendingJoin.join.getRightExpression();
} else {
throw notFoundEitherSide();
}
if (bound) {
final Comparisons.Comparison comparison = new Comparisons.ParameterComparison(pendingJoin.singleton ? Comparisons.Type.EQUALS : Comparisons.Type.IN, pendingJoin.bindingName);
conditions.add(buildCondition(expression, comparison));
pendingJoins.remove(pendingJoin);
}
}
RecordQuery.Builder builder = RecordQuery.newBuilder();
builder.setRecordType(pendingType.joinConstituent.getRecordType().getName());
if (!conditions.isEmpty()) {
builder.setFilter(conditions.size() > 1 ? Query.and(conditions) : conditions.get(0));
}
// An alternative would be to add duplicate elimination on the result of the join before forming the synthetic records.
// But until the planner is able to push that down / eliminate it when the scan does not produce duplicates, it's better to give it here,
// since the planner at least understands the simple cases of the elimination.
builder.setRemoveDuplicates(true);
return builder.build();
}
Aggregations