Search in sources :

Example 66 with QueryComponent

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);
    });
}
Also used : QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) RecordQuery(com.apple.foundationdb.record.query.RecordQuery) Test(org.junit.jupiter.api.Test)

Example 67 with QueryComponent

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));
}
Also used : QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 68 with QueryComponent

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));
}
Also used : IntStream(java.util.stream.IntStream) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Query(com.apple.foundationdb.record.query.expressions.Query) RecordQueryPlannerConfiguration(com.apple.foundationdb.record.query.plan.RecordQueryPlannerConfiguration) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Collectors(java.util.stream.Collectors) OrComponent(com.apple.foundationdb.record.query.expressions.OrComponent) ArrayList(java.util.ArrayList) Key(com.apple.foundationdb.record.metadata.Key) Test(org.junit.jupiter.api.Test) List(java.util.List) QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Nonnull(javax.annotation.Nonnull) QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) Test(org.junit.jupiter.api.Test)

Example 69 with QueryComponent

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)));
}
Also used : QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) Test(org.junit.jupiter.api.Test)

Example 70 with QueryComponent

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());
}
Also used : QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) Test(org.junit.jupiter.api.Test)

Aggregations

QueryComponent (com.apple.foundationdb.record.query.expressions.QueryComponent)96 RecordQueryPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan)58 RecordQuery (com.apple.foundationdb.record.query.RecordQuery)44 Test (org.junit.jupiter.api.Test)41 FDBRecordContext (com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext)37 ArrayList (java.util.ArrayList)30 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)29 FDBQueriedRecord (com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord)25 Index (com.apple.foundationdb.record.metadata.Index)24 Nonnull (javax.annotation.Nonnull)23 Comparisons (com.apple.foundationdb.record.query.expressions.Comparisons)22 Message (com.google.protobuf.Message)22 Query (com.apple.foundationdb.record.query.expressions.Query)20 RecordQueryPlanner (com.apple.foundationdb.record.query.plan.RecordQueryPlanner)20 List (java.util.List)20 Collections (java.util.Collections)19 Nullable (javax.annotation.Nullable)18 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)18 PlanHashable (com.apple.foundationdb.record.PlanHashable)17 Expressions.field (com.apple.foundationdb.record.metadata.Key.Expressions.field)17