Search in sources :

Example 11 with DualPlannerTest

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

the class FDBSelectorPlanTest method testTwoInnerPlansWithContinuation.

@DualPlannerTest
void testTwoInnerPlansWithContinuation() 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();
    // 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 = RecordQuerySelectorPlan.from(plan(query1, query2), mockSelector());
    // Iteration 1, start with empty continuation
    RecordCursorResult<FDBQueriedRecord<Message>> result = querySimpleRecordStoreWithContinuation(NO_HOOK, planUnderTest, EvaluationContext::empty, null, ExecuteProperties.newBuilder().setReturnedRowLimit(15).build(), count -> assertThat(count, is(15)), record -> assertThat(record.getNumValue2(), is(1)), context -> assertDiscardedAtMost(30, context));
    assertThat(result.getNoNextReason(), is(RecordCursor.NoNextReason.RETURN_LIMIT_REACHED));
    // Iteration 2, start with previous continuation
    byte[] continuation = result.getContinuation().toBytes();
    result = querySimpleRecordStoreWithContinuation(NO_HOOK, planUnderTest, EvaluationContext::empty, continuation, ExecuteProperties.newBuilder().setReturnedRowLimit(15).build(), count -> assertThat(count, is(15)), record -> assertThat(record.getNumValue2(), is(1)), context -> assertDiscardedAtMost(30, context));
    assertThat(result.getNoNextReason(), is(RecordCursor.NoNextReason.RETURN_LIMIT_REACHED));
    // Iteration 3, start with previous continuation, reach end
    continuation = result.getContinuation().toBytes();
    result = querySimpleRecordStoreWithContinuation(NO_HOOK, planUnderTest, EvaluationContext::empty, continuation, ExecuteProperties.newBuilder().setReturnedRowLimit(15).build(), count -> assertThat(count, is(3)), record -> assertThat(record.getNumValue2(), is(1)), context -> assertDiscardedAtMost(8, context));
    assertThat(result.hasNext(), is(false));
    assertThat(result.getNoNextReason(), is(RecordCursor.NoNextReason.SOURCE_EXHAUSTED));
}
Also used : FDBRecordStoreQueryTestBase(com.apple.foundationdb.record.provider.foundationdb.query.FDBRecordStoreQueryTestBase) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ValuePickerValue(com.apple.foundationdb.record.query.predicates.ValuePickerValue) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) RecordQuery(com.apple.foundationdb.record.query.RecordQuery) ExecuteProperties(com.apple.foundationdb.record.ExecuteProperties) RecordCursorResult(com.apple.foundationdb.record.RecordCursorResult) ImmutableList(com.google.common.collect.ImmutableList) DualPlannerTest(com.apple.foundationdb.record.provider.foundationdb.query.DualPlannerTest) Tag(org.junit.jupiter.api.Tag) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Nonnull(javax.annotation.Nonnull) Query(com.apple.foundationdb.record.query.expressions.Query) Tags(com.apple.test.Tags) RecordCoreArgumentException(com.apple.foundationdb.record.RecordCoreArgumentException) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) Value(com.apple.foundationdb.record.query.predicates.Value) List(java.util.List) TestHelpers.assertDiscardedAtMost(com.apple.foundationdb.record.TestHelpers.assertDiscardedAtMost) EvaluationContext(com.apple.foundationdb.record.EvaluationContext) FDBQueriedRecord(com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord) Message(com.google.protobuf.Message) RecordCursor(com.apple.foundationdb.record.RecordCursor) Matchers.is(org.hamcrest.Matchers.is) Collections(java.util.Collections) FDBQueriedRecord(com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord) EvaluationContext(com.apple.foundationdb.record.EvaluationContext) RecordQuery(com.apple.foundationdb.record.query.RecordQuery) DualPlannerTest(com.apple.foundationdb.record.provider.foundationdb.query.DualPlannerTest)

Example 12 with DualPlannerTest

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

the class FDBComparatorPlanTest method testTwoSameInnerPlans.

@DualPlannerTest
void testTwoSameInnerPlans() 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();
    RecordQueryPlan planUnderTest = RecordQueryComparatorPlan.from(plan(query1, query2), primaryKey(), 0, abortOnComparisonFailure);
    assertSamePlans(planUnderTest, 1, 134, 33);
}
Also used : RecordQuery(com.apple.foundationdb.record.query.RecordQuery) DualPlannerTest(com.apple.foundationdb.record.provider.foundationdb.query.DualPlannerTest)

Example 13 with DualPlannerTest

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

the class FDBComparatorPlanTest method testTwoDifferentInnerPlansIndex1.

@DualPlannerTest
void testTwoDifferentInnerPlansIndex1() 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(2)).build();
    // Note the reference index is now 1
    RecordQueryPlan planUnderTest = RecordQueryComparatorPlan.from(plan(query1, query2), primaryKey(), 1, abortOnComparisonFailure);
    assertDifferentPlans(planUnderTest, 2, 134, 33);
}
Also used : RecordQuery(com.apple.foundationdb.record.query.RecordQuery) DualPlannerTest(com.apple.foundationdb.record.provider.foundationdb.query.DualPlannerTest)

Example 14 with DualPlannerTest

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

the class FDBComparatorPlanTest method testTwoSameInnerPlansWithContinuation.

@DualPlannerTest
void testTwoSameInnerPlansWithContinuation() throws Throwable {
    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();
    // 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
    RecordCursorResult<FDBQueriedRecord<Message>> result = assertSamePlansWithContinuation(planUnderTest, null, 15, 0, 15, 1, 60, false, RecordCursor.NoNextReason.RETURN_LIMIT_REACHED);
    // Iteration 2, start with previous continuation
    byte[] continuation = result.getContinuation().toBytes();
    result = assertSamePlansWithContinuation(planUnderTest, continuation, 15, 0, 15, 1, 60, false, RecordCursor.NoNextReason.RETURN_LIMIT_REACHED);
    // Iteration 3, start with previous continuation, reach end
    continuation = result.getContinuation().toBytes();
    assertSamePlansWithContinuation(planUnderTest, continuation, 15, 0, 3, 1, 16, 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 15 with DualPlannerTest

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

the class FDBComparatorPlanTest method testTwoDifferentInnerPlansWithContinuation.

@DualPlannerTest
void testTwoDifferentInnerPlansWithContinuation() 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, 15, 0, 15, 1, 60, false, RecordCursor.NoNextReason.RETURN_LIMIT_REACHED);
    // Iteration 2, start with previous continuation
    // For this iteration, the second plan ends sooner, so the comparison fails
    byte[] continuation = result.getContinuation().toBytes();
    result = assertDifferentPlansWithContinuation(planUnderTest, continuation, 15, 0, 15, 1, 60, false, RecordCursor.NoNextReason.RETURN_LIMIT_REACHED);
    if (result != null) {
        // Iteration 3, start with previous continuation, reach end
        // (in case we have a result from the first iteration)
        continuation = result.getContinuation().toBytes();
        assertDifferentPlansWithContinuation(planUnderTest, continuation, 15, 0, 3, 1, 16, 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)

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