Search in sources :

Example 71 with QueryComponent

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

the class FilterSatisfiedMaskTest method getUnsatisfiedSimple.

@Test
public void getUnsatisfiedSimple() {
    final QueryComponent fieldA = Query.field("a").text().containsPhrase("this isn't a real field");
    FilterSatisfiedMask fieldAMask = FilterSatisfiedMask.of(fieldA);
    fieldAMask.setSatisfied(true);
    assertNull(fieldAMask.getUnsatisfiedFilter());
    fieldAMask.reset();
    assertSame(fieldA, fieldAMask.getUnsatisfiedFilter());
    final QueryComponent oneOfFieldA = Query.field("a").oneOfThem().in("$in_param");
    FilterSatisfiedMask oneOfFieldAMask = FilterSatisfiedMask.of(oneOfFieldA);
    oneOfFieldAMask.setSatisfied(true);
    assertNull(oneOfFieldAMask.getUnsatisfiedFilter());
    oneOfFieldAMask.reset();
    assertSame(oneOfFieldA, oneOfFieldAMask.getUnsatisfiedFilter());
}
Also used : QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) Test(org.junit.jupiter.api.Test)

Example 72 with QueryComponent

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

the class FilterSatisfiedMaskTest method create.

@Test
public void create() {
    // Scalar field
    final QueryComponent fieldA = Query.field("a").equalsValue("dummy_value");
    validateMask(fieldA, Collections.emptyList());
    // Repeated field
    final QueryComponent oneOfFieldA = Query.field("a").oneOfThem().equalsValue("dummy_value");
    validateMask(oneOfFieldA, Collections.emptyList());
    // Nested field
    final QueryComponent nestedFieldB = Query.field("b").matches(fieldA);
    validateMask(nestedFieldB, Collections.singletonList(fieldA));
    // Nested repeated field
    final QueryComponent oneOfNestedFieldB = Query.field("b").oneOfThem().matches(fieldA);
    validateMask(oneOfNestedFieldB, Collections.singletonList(fieldA));
    // Not component
    final QueryComponent notFieldA = Query.not(fieldA);
    validateMask(notFieldA, Collections.singletonList(fieldA));
    // Or component
    final QueryComponent orFilter = Query.or(notFieldA, oneOfNestedFieldB);
    validateMask(orFilter, Arrays.asList(notFieldA, oneOfNestedFieldB));
    // And component
    final QueryComponent andFilter = Query.and(nestedFieldB, fieldA, orFilter);
    validateMask(andFilter, Arrays.asList(nestedFieldB, fieldA, orFilter));
}
Also used : QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) Test(org.junit.jupiter.api.Test)

Example 73 with QueryComponent

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

the class FilterSatisfiedMaskTest method getUnsatisfiedList.

@Test
public void getUnsatisfiedList() {
    final QueryComponent fieldA = Query.field("a").notEquals("something");
    final QueryComponent fieldB = Query.field("b").equalsValue("something_else");
    final QueryComponent andFilter = Query.and(fieldA, fieldB);
    FilterSatisfiedMask andMask = FilterSatisfiedMask.of(andFilter);
    assertEquals(Arrays.asList(fieldA, fieldB), andMask.getUnsatisfiedFilters());
    andMask.getChild(fieldA).setSatisfied(true);
    assertEquals(Collections.singletonList(fieldB), andMask.getUnsatisfiedFilters());
    andMask.getChild(fieldB).setSatisfied(true);
    assertEquals(Collections.emptyList(), andMask.getUnsatisfiedFilters());
    andMask.reset();
    andMask.setSatisfied(true);
    assertEquals(Collections.emptyList(), andMask.getUnsatisfiedFilters());
    final QueryComponent nestedField = Query.field("c").matches(fieldA);
    FilterSatisfiedMask nestedMask = FilterSatisfiedMask.of(nestedField);
    assertEquals(Collections.singletonList(nestedField), nestedMask.getUnsatisfiedFilters());
    nestedMask.getChild(fieldA).setSatisfied(true);
    assertEquals(Collections.emptyList(), nestedMask.getUnsatisfiedFilters());
    final QueryComponent nestedAndFilter = Query.field("parent").matches(andFilter);
    FilterSatisfiedMask nestedAndMask = FilterSatisfiedMask.of(nestedAndFilter);
    assertEquals(Collections.singletonList(nestedAndFilter), nestedAndMask.getUnsatisfiedFilters());
    nestedAndMask.getChild(andFilter).getChild(fieldA).setSatisfied(true);
    assertEquals(Collections.singletonList(Query.field("parent").matches(fieldB)), nestedAndMask.getUnsatisfiedFilters());
    nestedAndMask.getChild(andFilter).getChild(fieldB).setSatisfied(true);
    assertEquals(Collections.emptyList(), nestedAndMask.getUnsatisfiedFilters());
}
Also used : QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) Test(org.junit.jupiter.api.Test)

Example 74 with QueryComponent

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

the class FilterSatisfiedMaskTest method getUnsatisfiedWithAnd.

@Test
public void getUnsatisfiedWithAnd() {
    final QueryComponent fieldA = Query.field("a").text().containsAny("not a real field");
    final QueryComponent fieldB = Query.field("b").lessThan(100);
    final QueryComponent fieldC = Query.field("c").equalsParameter("$fake_param");
    final QueryComponent andFilter = Query.and(fieldA, fieldB, fieldC);
    FilterSatisfiedMask andMask = FilterSatisfiedMask.of(andFilter);
    andMask.getChild(fieldB).setSatisfied(true);
    assertEquals(Query.and(fieldA, fieldC), andMask.getUnsatisfiedFilter());
    andMask.getChild(fieldA).setSatisfied(true);
    assertSame(fieldC, andMask.getUnsatisfiedFilter());
    andMask.getChild(fieldC).setSatisfied(true);
    assertNull(andMask.getUnsatisfiedFilter());
    andMask.reset();
    assertSame(andFilter, andMask.getUnsatisfiedFilter());
}
Also used : QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) Test(org.junit.jupiter.api.Test)

Example 75 with QueryComponent

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

the class FilterSatisfiedMaskTest method getUnsatisfiedNot.

@Test
public void getUnsatisfiedNot() {
    final QueryComponent fieldA = Query.field("a").equalsValue("something");
    final QueryComponent notFilter = Query.not(fieldA);
    FilterSatisfiedMask notMask = FilterSatisfiedMask.of(notFilter);
    notMask.getChild(fieldA).setSatisfied(true);
    assertSame(notFilter, notMask.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