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());
}
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));
}
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());
}
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());
}
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());
}
Aggregations