Search in sources :

Example 46 with QueryComponent

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

the class BooleanNormalizerTest method bigCnfThatWouldOverflow.

@Test
public void bigCnfThatWouldOverflow() {
    // A CNF who's DNF size doesn't fit in an int.
    List<QueryComponent> conjuncts = new ArrayList<>();
    for (int i = 0; i < 32; i++) {
        List<QueryComponent> disjuncts = new ArrayList<>();
        for (int j = 0; j < 2; j++) {
            disjuncts.add(Query.field("f").equalsValue(i * 100 + j));
        }
        conjuncts.add(Query.or(disjuncts));
    }
    final QueryComponent cnf = Query.and(conjuncts);
    final BooleanNormalizer normalizer = BooleanNormalizer.getDefaultInstance();
    assertThrows(ArithmeticException.class, () -> normalizer.getNormalizedSize(cnf));
    assertThrows(BooleanNormalizer.DNFTooLargeException.class, () -> normalizer.normalize(cnf));
    assertEquals(cnf, normalizer.normalizeIfPossible(cnf));
}
Also used : QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 47 with QueryComponent

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

the class FilterSatisfiedMaskTest method getUnsatisfiedNested.

@Test
public void getUnsatisfiedNested() {
    final QueryComponent fieldA = Query.field("a").isNull();
    final QueryComponent nestedFieldB = Query.field("b").matches(fieldA);
    FilterSatisfiedMask nestedMask = FilterSatisfiedMask.of(nestedFieldB);
    nestedMask.getChild(fieldA).setSatisfied(true);
    assertThat(nestedMask.isSatisfied(), is(false));
    assertNull(nestedMask.getUnsatisfiedFilter());
    assertThat(nestedMask.isSatisfied(), is(true));
    nestedMask.reset();
    assertThat(nestedMask.getChild(fieldA).isSatisfied(), is(false));
    assertSame(nestedFieldB, nestedMask.getUnsatisfiedFilter());
    final QueryComponent oneOfNestedFieldB = Query.field("b").oneOfThem().matches(fieldA);
    FilterSatisfiedMask oneOfNestedMask = FilterSatisfiedMask.of(oneOfNestedFieldB);
    oneOfNestedMask.getChild(fieldA).setSatisfied(true);
    assertThat(oneOfNestedMask.isSatisfied(), is(false));
    assertNull(oneOfNestedMask.getUnsatisfiedFilter());
    assertThat(oneOfNestedMask.isSatisfied(), is(true));
    oneOfNestedMask.reset();
    assertThat(oneOfNestedMask.getChild(fieldA).isSatisfied(), is(false));
    assertSame(oneOfNestedFieldB, oneOfNestedMask.getUnsatisfiedFilter());
}
Also used : QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) Test(org.junit.jupiter.api.Test)

Example 48 with QueryComponent

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

the class FilterSatisfiedMaskTest method getUnsatisfiedNestedWithAnd.

@Test
public void getUnsatisfiedNestedWithAnd() {
    final QueryComponent fieldA = Query.field("a").lessThanOrEquals(3.14f);
    final QueryComponent fieldB = Query.field("b").isEmpty();
    final QueryComponent fieldC = Query.field("c").startsWith("prefix");
    final QueryComponent andFilter = Query.and(fieldA, fieldB, fieldC);
    final QueryComponent nestedFilter = Query.field("parent").matches(andFilter);
    FilterSatisfiedMask nestedMask = FilterSatisfiedMask.of(nestedFilter);
    nestedMask.getChild(andFilter).getChild(fieldB).setSatisfied(true);
    assertEquals(Query.field("parent").matches(Query.and(fieldA, fieldC)), nestedMask.getUnsatisfiedFilter());
    nestedMask.getChild(andFilter).getChild(fieldA).setSatisfied(true);
    assertEquals(Query.field("parent").matches(fieldC), nestedMask.getUnsatisfiedFilter());
    nestedMask.getChild(andFilter).getChild(fieldC).setSatisfied(true);
    assertNull(nestedMask.getUnsatisfiedFilter());
    nestedMask.reset();
    assertSame(nestedFilter, nestedMask.getUnsatisfiedFilter());
    final QueryComponent oneOfNestedFilter = Query.field("parent").oneOfThem().matches(andFilter);
    FilterSatisfiedMask oneOfNestedMask = FilterSatisfiedMask.of(oneOfNestedFilter);
    oneOfNestedMask.getChild(andFilter).getChild(fieldB).setSatisfied(true);
    assertSame(oneOfNestedFilter, oneOfNestedMask.getUnsatisfiedFilter());
    oneOfNestedMask.getChild(andFilter).getChild(fieldA).setSatisfied(true);
    assertSame(oneOfNestedFilter, oneOfNestedMask.getUnsatisfiedFilter());
    oneOfNestedMask.getChild(andFilter).getChild(fieldC).setSatisfied(true);
    assertNull(oneOfNestedMask.getUnsatisfiedFilter());
    oneOfNestedMask.reset();
    assertSame(oneOfNestedFilter, oneOfNestedMask.getUnsatisfiedFilter());
}
Also used : QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) Test(org.junit.jupiter.api.Test)

Example 49 with QueryComponent

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

the class FilterSatisfiedMaskTest method getChild.

@Test
public void getChild() {
    final QueryComponent fieldA = Query.field("a").equalsValue("dummy_value");
    FilterSatisfiedMask fieldAMask = FilterSatisfiedMask.of(fieldA);
    assertThrows(FilterSatisfiedMask.FilterNotFoundException.class, () -> fieldAMask.getChild(Query.field("b").equalsValue("blah")));
    final QueryComponent nestedFieldB = Query.field("b").matches(fieldA);
    FilterSatisfiedMask nestedFieldBMask = FilterSatisfiedMask.of(nestedFieldB);
    assertSame(fieldA, nestedFieldBMask.getChild(fieldA).getFilter());
    assertThrows(FilterSatisfiedMask.FilterNotFoundException.class, () -> nestedFieldBMask.getChild(Query.field("a").equalsValue("dummy_value")));
    final QueryComponent andComponent = Query.and(nestedFieldB, Query.field("c").equalsValue("something_else"));
    FilterSatisfiedMask andMask = FilterSatisfiedMask.of(andComponent);
    assertSame(nestedFieldB, andMask.getChild(nestedFieldB).getFilter());
    assertThrows(FilterSatisfiedMask.FilterNotFoundException.class, () -> andMask.getChild(Query.field("c").equalsValue("something_else")));
}
Also used : QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) Test(org.junit.jupiter.api.Test)

Example 50 with QueryComponent

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

the class FilterSatisfiedMaskTest method merge.

@Test
public void merge() {
    final QueryComponent fieldA = Query.field("a").equalsValue("hello");
    final QueryComponent fieldB = Query.field("b").equalsValue("world");
    final QueryComponent fieldC = Query.field("c").notEquals("!");
    final QueryComponent and = Query.and(fieldA, fieldB, fieldC);
    final FilterSatisfiedMask mask1 = FilterSatisfiedMask.of(and);
    final FilterSatisfiedMask mask2 = FilterSatisfiedMask.of(and);
    mask1.getChild(fieldA).setSatisfied(true);
    mask2.getChild(fieldC).setSatisfied(true);
    mask1.mergeWith(mask2);
    assertSame(fieldB, mask1.getUnsatisfiedFilter());
    assertEquals(Query.and(fieldA, fieldB), mask2.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