Search in sources :

Example 1 with DualPlannerTest

use of com.apple.foundationdb.record.provider.foundationdb.query.DualPlannerTest in project fdb-record-layer by FoundationDB.

the class FDBSelectorPlanTest method testPlanValues.

@DualPlannerTest
void testPlanValues() throws Throwable {
    complexQuerySetup(NO_HOOK);
    RecordQuery query1 = RecordQuery.newBuilder().setRecordType("MySimpleRecord").build();
    RecordQuery query2 = RecordQuery.newBuilder().setRecordType("MySimpleRecord").setFilter(Query.field("num_value_2").equalsValue(1)).build();
    RecordQueryPlan plan = RecordQuerySelectorPlan.from(plan(query1, query2), List.of(50, 50));
    List<? extends Value> resultValues = plan.getResultValues();
    assertThat(resultValues.size(), is(1));
    ValuePickerValue value = (ValuePickerValue) resultValues.get(0);
    List<Value> subValues = ImmutableList.copyOf(value.getChildren());
    assertThat(subValues.size(), is(2));
    assertThat(subValues.get(0), is(plan.getQuantifiers().get(0).getFlowedValues().get(0)));
    assertThat(subValues.get(1), is(plan.getQuantifiers().get(1).getFlowedValues().get(0)));
}
Also used : ValuePickerValue(com.apple.foundationdb.record.query.predicates.ValuePickerValue) ValuePickerValue(com.apple.foundationdb.record.query.predicates.ValuePickerValue) Value(com.apple.foundationdb.record.query.predicates.Value) RecordQuery(com.apple.foundationdb.record.query.RecordQuery) DualPlannerTest(com.apple.foundationdb.record.provider.foundationdb.query.DualPlannerTest)

Example 2 with DualPlannerTest

use of com.apple.foundationdb.record.provider.foundationdb.query.DualPlannerTest in project fdb-record-layer by FoundationDB.

the class FDBComparatorPlanTest method testTwoDifferentInnerPlansReferenceEndsSooner.

@DualPlannerTest
void testTwoDifferentInnerPlansReferenceEndsSooner() throws Exception {
    complexQuerySetup(NO_HOOK);
    RecordQuery query1 = RecordQuery.newBuilder().setRecordType("MySimpleRecord").setFilter(Query.field("num_value_2").equalsValue(1)).build();
    // This plan has same records as the previous one, but end sooner
    RecordQuery query2 = RecordQuery.newBuilder().setRecordType("MySimpleRecord").setFilter(Query.and(Query.field("num_value_2").equalsValue(1), Query.field("rec_no").lessThan(5L))).build();
    // Note this time the reference plan is hte second one
    RecordQueryPlan planUnderTest = RecordQueryComparatorPlan.from(plan(query1, query2), primaryKey(), 1, abortOnComparisonFailure);
    assertDifferentPlans(planUnderTest, 1, 10, 2);
}
Also used : RecordQuery(com.apple.foundationdb.record.query.RecordQuery) DualPlannerTest(com.apple.foundationdb.record.provider.foundationdb.query.DualPlannerTest)

Example 3 with DualPlannerTest

use of com.apple.foundationdb.record.provider.foundationdb.query.DualPlannerTest in project fdb-record-layer by FoundationDB.

the class FDBComparatorPlanTest method testRepeatedKeyFails.

@DualPlannerTest
void testRepeatedKeyFails() throws Exception {
    // Test when the comparison key is a repeated field
    complexQuerySetup(NO_HOOK);
    RecordQuery query1 = RecordQuery.newBuilder().setRecordType("MySimpleRecord").setFilter(Query.field("num_value_2").equalsValue(1)).build();
    RecordQuery query2 = RecordQuery.newBuilder().setRecordType("MySimpleRecord").setFilter(Query.field("num_value_2").equalsValue(1)).build();
    Descriptors.FieldDescriptor comparisonKey = recordStore.getRecordMetaData().getRecordType("MySimpleRecord").getDescriptor().findFieldByName("repeater");
    KeyExpression keyExpression = Key.Expressions.fromDescriptor(comparisonKey);
    RecordQueryPlan planUnderTest = RecordQueryComparatorPlan.from(plan(query1, query2), keyExpression, 0, abortOnComparisonFailure);
    // Repeated keys will fail the comparison since they are not supported
    assertDifferentPlans(planUnderTest, 1, 134, 33);
}
Also used : KeyExpression(com.apple.foundationdb.record.metadata.expressions.KeyExpression) Descriptors(com.google.protobuf.Descriptors) RecordQuery(com.apple.foundationdb.record.query.RecordQuery) DualPlannerTest(com.apple.foundationdb.record.provider.foundationdb.query.DualPlannerTest)

Example 4 with DualPlannerTest

use of com.apple.foundationdb.record.provider.foundationdb.query.DualPlannerTest in project fdb-record-layer by FoundationDB.

the class FDBComparatorPlanTest method testTwoDifferentInnerPlansWithScannedRowLimit.

@DualPlannerTest
void testTwoDifferentInnerPlansWithScannedRowLimit() throws Throwable {
    // This test has the non-reference plan ends but the cursor continues until the end of the reference plan
    complexQuerySetup(NO_HOOK);
    RecordQuery query1 = RecordQuery.newBuilder().setRecordType("MySimpleRecord").setFilter(Query.field("num_value_2").equalsValue(1)).build();
    // This plan has same records as the previous one, but end sooner
    RecordQuery query2 = RecordQuery.newBuilder().setRecordType("MySimpleRecord").setFilter(Query.and(Query.field("num_value_2").equalsValue(1), Query.field("rec_no").lessThan(50L))).build();
    // This will select plan 1 for the first execution and later some illegal value. The idea is that after the
    // first iteration, the continuation should determine the selected plan and not the relative priorities
    RecordQueryPlan planUnderTest = RecordQueryComparatorPlan.from(plan(query1, query2), primaryKey(), 0, abortOnComparisonFailure);
    // Iteration 1, start with empty continuation
    // The plans are the "same" here since we haven't reached the point at which the second scan ends (yet)
    RecordCursorResult<FDBQueriedRecord<Message>> result = assertSamePlansWithContinuation(planUnderTest, null, 0, 200, 17, 1, 68, false, RecordCursor.NoNextReason.SCAN_LIMIT_REACHED);
    // Iteration 2, start with previous continuation, reach end (before limit)
    byte[] continuation = result.getContinuation().toBytes();
    assertDifferentPlansWithContinuation(planUnderTest, continuation, 0, 200, 16, 1, 66, false, RecordCursor.NoNextReason.SOURCE_EXHAUSTED);
}
Also used : FDBQueriedRecord(com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord) RecordQuery(com.apple.foundationdb.record.query.RecordQuery) DualPlannerTest(com.apple.foundationdb.record.provider.foundationdb.query.DualPlannerTest)

Example 5 with DualPlannerTest

use of com.apple.foundationdb.record.provider.foundationdb.query.DualPlannerTest in project fdb-record-layer by FoundationDB.

the class FDBComparatorPlanTest method testIllegalReferencePlanIndex.

@DualPlannerTest
void testIllegalReferencePlanIndex() throws Exception {
    complexQuerySetup(NO_HOOK);
    RecordQuery query1 = RecordQuery.newBuilder().setRecordType("MySimpleRecord").setFilter(Query.field("num_value_2").equalsValue(1)).build();
    RecordQuery query2 = RecordQuery.newBuilder().setRecordType("MySimpleRecord").setFilter(Query.field("num_value_2").equalsValue(1)).build();
    assertThrows(RecordCoreArgumentException.class, () -> RecordQueryComparatorPlan.from(plan(query1, query2), primaryKey(), 3, abortOnComparisonFailure));
}
Also used : RecordQuery(com.apple.foundationdb.record.query.RecordQuery) DualPlannerTest(com.apple.foundationdb.record.provider.foundationdb.query.DualPlannerTest)

Aggregations

DualPlannerTest (com.apple.foundationdb.record.provider.foundationdb.query.DualPlannerTest)16 RecordQuery (com.apple.foundationdb.record.query.RecordQuery)16 FDBQueriedRecord (com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord)5 EvaluationContext (com.apple.foundationdb.record.EvaluationContext)3 Value (com.apple.foundationdb.record.query.predicates.Value)2 ValuePickerValue (com.apple.foundationdb.record.query.predicates.ValuePickerValue)2 ExecuteProperties (com.apple.foundationdb.record.ExecuteProperties)1 RecordCoreArgumentException (com.apple.foundationdb.record.RecordCoreArgumentException)1 RecordCursor (com.apple.foundationdb.record.RecordCursor)1 RecordCursorResult (com.apple.foundationdb.record.RecordCursorResult)1 TestHelpers.assertDiscardedAtMost (com.apple.foundationdb.record.TestHelpers.assertDiscardedAtMost)1 KeyExpression (com.apple.foundationdb.record.metadata.expressions.KeyExpression)1 FDBRecordStoreQueryTestBase (com.apple.foundationdb.record.provider.foundationdb.query.FDBRecordStoreQueryTestBase)1 Query (com.apple.foundationdb.record.query.expressions.Query)1 Tags (com.apple.test.Tags)1 ImmutableList (com.google.common.collect.ImmutableList)1 Descriptors (com.google.protobuf.Descriptors)1 Message (com.google.protobuf.Message)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1