use of com.apple.foundationdb.record.query.expressions.QueryComponent in project fdb-record-layer by FoundationDB.
the class FDBRecordStoreQueryTest method queryComplexityLimit.
@Test
void queryComplexityLimit() throws Exception {
RecordMetaDataHook hook = complexQuerySetupHook();
complexQuerySetup(hook);
List<QueryComponent> clauses = Lists.newArrayList(Query.field("num_value_unique").greaterThanOrEquals(-1));
for (int i = 0; i < RecordQueryPlanner.DEFAULT_COMPLEXITY_THRESHOLD + 10; i++) {
clauses.add(Query.field("num_value_unique").greaterThanOrEquals(i));
}
RecordQuery query = RecordQuery.newBuilder().setRecordType("MySimpleRecord").setFilter(Query.or(clauses)).build();
assertThrows(RecordQueryPlanComplexityException.class, () -> {
planner.plan(query);
});
}
use of com.apple.foundationdb.record.query.expressions.QueryComponent in project fdb-record-layer by FoundationDB.
the class BooleanNormalizerTest method cnf.
@Test
public void cnf() {
List<QueryComponent> conjuncts = new ArrayList<>();
for (int i = 0; i < 5; i++) {
List<QueryComponent> disjuncts = new ArrayList<>();
for (int j = 0; j < 5; j++) {
disjuncts.add(Query.field("f").equalsValue(i * 4 + j));
}
conjuncts.add(Query.or(disjuncts));
}
final QueryComponent cnf = Query.and(conjuncts);
final BooleanNormalizer normalizer = BooleanNormalizer.getDefaultInstance();
assertNotEquals(cnf, normalizer.normalize(cnf));
assertEquals(numberOfTerms(normalizer.normalize(cnf)), normalizer.getNormalizedSize(cnf));
final BooleanNormalizer lowLimitNormalizer = BooleanNormalizer.withLimit(2);
assertThrows(BooleanNormalizer.DNFTooLargeException.class, () -> lowLimitNormalizer.normalize(cnf));
assertEquals(cnf, lowLimitNormalizer.normalizeIfPossible(cnf));
}
use of com.apple.foundationdb.record.query.expressions.QueryComponent in project fdb-record-layer by FoundationDB.
the class BooleanNormalizerTest method bigNonCnf.
@Test
public void bigNonCnf() {
final QueryComponent cnf = Query.and(IntStream.rangeClosed(1, 9).boxed().map(i -> Query.or(IntStream.rangeClosed(1, 9).boxed().map(j -> Query.and(Query.field("num_value_3_indexed").equalsValue(i * 9 + j), Query.field("str_value_indexed").equalsValue("foo"))).collect(Collectors.toList()))).collect(Collectors.toList()));
final BooleanNormalizer plannerNormalizer = BooleanNormalizer.forConfiguration(RecordQueryPlannerConfiguration.builder().build());
assertThrows(BooleanNormalizer.DNFTooLargeException.class, () -> plannerNormalizer.normalize(cnf));
assertEquals(cnf, plannerNormalizer.normalizeIfPossible(cnf));
}
use of com.apple.foundationdb.record.query.expressions.QueryComponent in project fdb-record-layer by FoundationDB.
the class FilterSatisfiedMaskTest method unsuccessfulMerge.
@Test
public void unsuccessfulMerge() {
final QueryComponent fieldA = Query.field("a").equalsValue("a");
final QueryComponent fieldB = Query.field("b").equalsValue("b");
assertThrows(FilterSatisfiedMask.FilterMismatchException.class, () -> FilterSatisfiedMask.of(fieldA).mergeWith(FilterSatisfiedMask.of(fieldB)));
}
use of com.apple.foundationdb.record.query.expressions.QueryComponent in project fdb-record-layer by FoundationDB.
the class FilterSatisfiedMaskTest method getUnsatisfiedOr.
@Test
public void getUnsatisfiedOr() {
final QueryComponent fieldA = Query.field("a").isEmpty();
final QueryComponent fieldB = Query.field("b").greaterThanOrEquals(2.171828);
final QueryComponent orFilter = Query.or(fieldA, fieldB);
FilterSatisfiedMask orMask = FilterSatisfiedMask.of(orFilter);
orMask.getChild(fieldA).setSatisfied(true);
assertSame(orFilter, orMask.getUnsatisfiedFilter());
orMask.getChild(fieldB).setSatisfied(true);
assertNull(orMask.getUnsatisfiedFilter());
}
Aggregations