use of com.apple.foundationdb.record.query.expressions.QueryComponent in project fdb-record-layer by FoundationDB.
the class FieldWithComparisonCountProperty method evaluateAtExpression.
@Nonnull
@Override
public Integer evaluateAtExpression(@Nonnull RelationalExpression expression, @Nonnull List<Integer> childResults) {
int total = 0;
if (expression instanceof RecordQueryFilterPlan) {
QueryComponent filter = ((RecordQueryFilterPlan) expression).getConjunctedFilter();
total = getFieldWithComparisonCount(filter);
}
for (Integer childCount : childResults) {
if (childCount != null) {
total += childCount;
}
}
return total;
}
use of com.apple.foundationdb.record.query.expressions.QueryComponent in project fdb-record-layer by FoundationDB.
the class FDBInQueryTest method testNotInQueryParameterBad.
/**
* Verify that NOT IN is planned correctly, and fails if no binding is provided.
*/
@Test
void testNotInQueryParameterBad() throws Exception {
complexQuerySetup(NO_HOOK);
final QueryComponent filter = Query.not(Query.field("num_value_3_indexed").in("valueThrees"));
RecordQuery query = RecordQuery.newBuilder().setRecordType("MySimpleRecord").setFilter(filter).build();
// Scan(<,>) | [MySimpleRecord] | Not(num_value_3_indexed IN $valueThrees)
RecordQueryPlan plan = planner.plan(query);
assertMatchesExactly(plan, filterPlan(descendantPlans(scanPlan().where(scanComparisons(unbounded())))).where(queryComponents(exactly(equalsObject(filter)))));
assertEquals(1667070490, plan.planHash(PlanHashable.PlanHashKind.LEGACY));
assertEquals(1804602975, plan.planHash(PlanHashable.PlanHashKind.FOR_CONTINUATION));
assertEquals(1804602975, plan.planHash(PlanHashable.PlanHashKind.STRUCTURAL_WITHOUT_LITERALS));
assertEquals(100, querySimpleRecordStore(NO_HOOK, plan, () -> EvaluationContext.forBinding("valueThrees", Collections.emptyList()), myrec -> {
}, TestHelpers::assertDiscardedNone));
assertEquals(0, querySimpleRecordStore(NO_HOOK, plan, () -> EvaluationContext.forBinding("valueThrees", null), /* no binding for valueThrees */
myrec -> fail("There should be no results")));
}
use of com.apple.foundationdb.record.query.expressions.QueryComponent in project fdb-record-layer by FoundationDB.
the class FDBInQueryTest method testInQueryNoIndex.
/**
* Verify that an IN without an index is implemented as a filter on a scan, as opposed to a loop of a filter on a scan.
*/
@DualPlannerTest
void testInQueryNoIndex() throws Exception {
complexQuerySetup(NO_HOOK);
final QueryComponent filter = Query.field("num_value_2").in(asList(0, 2));
RecordQuery query = RecordQuery.newBuilder().setRecordType("MySimpleRecord").setFilter(filter).build();
// Scan(<,>) | [MySimpleRecord] | num_value_2 IN [0, 2]
RecordQueryPlan plan = planner.plan(query);
if (planner instanceof RecordQueryPlanner) {
assertMatchesExactly(plan, filterPlan(descendantPlans(scanPlan().where(scanComparisons(unbounded())))).where(queryComponents(exactly(equalsObject(filter)))));
assertEquals(-1139367278, plan.planHash(PlanHashable.PlanHashKind.LEGACY));
assertEquals(-1907300063, plan.planHash(PlanHashable.PlanHashKind.FOR_CONTINUATION));
assertEquals(-1694772440, plan.planHash(PlanHashable.PlanHashKind.STRUCTURAL_WITHOUT_LITERALS));
} else {
assertMatchesExactly(plan, predicatesFilterPlan(descendantPlans(scanPlan().where(scanComparisons(unbounded())))).where(predicates(valuePredicate(fieldValue("num_value_2"), new Comparisons.ListComparison(Comparisons.Type.IN, ImmutableList.of(0, 2))))));
assertEquals(997592219, plan.planHash(PlanHashable.PlanHashKind.LEGACY));
assertEquals(-1107686929, plan.planHash(PlanHashable.PlanHashKind.FOR_CONTINUATION));
assertEquals(-895159306, plan.planHash(PlanHashable.PlanHashKind.STRUCTURAL_WITHOUT_LITERALS));
}
assertEquals(67, querySimpleRecordStore(NO_HOOK, plan, EvaluationContext::empty, record -> assertThat(record.getNumValue2(), anyOf(is(0), is(2))), context -> assertDiscardedAtMost(33, context)));
}
use of com.apple.foundationdb.record.query.expressions.QueryComponent in project fdb-record-layer by FoundationDB.
the class FDBRecordStoreQueryTest method doesNotNormalizeLargeCnf.
/**
* Check that a query with a CNF filter predicate that would be very large in disjunctive normal form does not get
* normalized. For now, the predicate should be left alone as a filter.
* @see com.apple.foundationdb.record.query.plan.planning.BooleanNormalizer
*/
@Test
void doesNotNormalizeLargeCnf() throws Exception {
RecordMetaDataHook hook = complexQuerySetupHook();
complexQuerySetup(hook);
final QueryComponent cnf = Query.and(IntStream.rangeClosed(1, 9).boxed().map(i -> Query.or(IntStream.rangeClosed(1, 9).boxed().map(j -> Query.field("num_value_3_indexed").equalsValue(i * 9 + j)).collect(Collectors.toList()))).collect(Collectors.toList()));
final RecordQuery query = RecordQuery.newBuilder().setRecordType("MySimpleRecord").setFilter(cnf).build();
RecordQueryPlan plan = planner.plan(query);
assertMatchesExactly(plan, filterPlan(RecordQueryPlanMatchers.anyPlan()).where(queryComponents(only(equalsObject(cnf)))));
}
use of com.apple.foundationdb.record.query.expressions.QueryComponent in project fdb-record-layer by FoundationDB.
the class FDBRecordStoreQueryTest method doesNotNormalizeBigExpression.
/**
* Check that a query with a non-CNF filter predicate that would be very large in disjunctive normal form does not
* get normalized. For now, the predicate should be left alone as a filter.
* @see com.apple.foundationdb.record.query.plan.planning.BooleanNormalizer
*/
@Test
void doesNotNormalizeBigExpression() throws Exception {
RecordMetaDataHook hook = complexQuerySetupHook();
complexQuerySetup(hook);
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 RecordQuery query = RecordQuery.newBuilder().setRecordType("MySimpleRecord").setFilter(cnf).build();
RecordQueryPlan plan = planner.plan(query);
assertMatchesExactly(plan, filterPlan(RecordQueryPlanMatchers.anyPlan()).where(queryComponents(only(equalsObject(cnf)))));
}
Aggregations