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