Search in sources :

Example 1 with BoundRecordQuery

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

the class FDBQueryCompatibilityTest method testParameterBindings.

@DualPlannerTest
public void testParameterBindings() throws Exception {
    RecordMetaDataHook hook = complexQuerySetupHook();
    complexQuerySetup(hook);
    BoundRecordQuery boundQuery = RecordQuery.newBuilder().setRecordType("MySimpleRecord").setFilter(Query.and(Query.field("str_value_indexed").equalsParameter("p1"), Query.field("str_value_indexed").equalsParameter("p2"), Query.field("num_value_3_indexed").equalsParameter("p3"), Query.field("num_value_2").equalsValue(0))).buildAndBind(recordStore, Bindings.newBuilder().set("p1", "whatever").set("p2", "whatever").set("p3", "-10").build());
    final RecordQueryPlan plan = planner.plan(boundQuery.getRecordQuery());
    try (FDBRecordContext context = openContext()) {
        openSimpleRecordStore(context, hook);
        final Bindings compatibleBindings = Bindings.newBuilder().set("p1", "even").set("p2", "even").set("p3", 3).build();
        assertTrue(boundQuery.isCompatible(recordStore, compatibleBindings));
        final Bindings incompatibleBindings = Bindings.newBuilder().set("p1", "even").set("p2", "odd").set("p3", 3).build();
        assertFalse(boundQuery.isCompatible(recordStore, incompatibleBindings));
        int i = 0;
        try (RecordCursorIterator<FDBQueriedRecord<Message>> cursor = plan.execute(recordStore, EvaluationContext.forBindings(compatibleBindings)).asIterator()) {
            while (cursor.hasNext()) {
                FDBQueriedRecord<Message> rec = cursor.next();
                TestRecords1Proto.MySimpleRecord.Builder myrec = TestRecords1Proto.MySimpleRecord.newBuilder();
                myrec.mergeFrom(Objects.requireNonNull(rec).getRecord());
                assertEquals("even", myrec.getStrValueIndexed());
                assertEquals(0, (myrec.getNumValue2() % 3));
                assertEquals(3, (myrec.getNumValue3Indexed() % 5));
                i++;
            }
        }
        assertEquals(3, i);
        TestHelpers.assertDiscardedNone(context);
    }
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) BoundRecordQuery(com.apple.foundationdb.record.query.BoundRecordQuery) FDBQueriedRecord(com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord) Message(com.google.protobuf.Message) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) Bindings(com.apple.foundationdb.record.Bindings)

Example 2 with BoundRecordQuery

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

the class FDBQueryCompatibilityTest method testQueryCompatibilityUniqueUsages.

@Test
void testQueryCompatibilityUniqueUsages() throws Exception {
    RecordMetaDataHook hook = complexQuerySetupHook();
    complexQuerySetup(hook);
    BoundRecordQuery query = RecordQuery.newBuilder().setRecordType("MySimpleRecord").setFilter(Query.and(Query.field("str_value_indexed").equalsParameter("p1"), Query.field("num_value_3_indexed").equalsParameter("p2"), Query.field("num_value_2").equalsParameter("p3"))).buildAndBind(recordStore, Bindings.newBuilder().set("p1", "even").set("p2", 3).set("p3", 0).build());
    BoundRecordQuery query2 = RecordQuery.newBuilder().setRecordType("MySimpleRecord").setFilter(Query.and(Query.field("str_value_indexed").equalsParameter("p1"), Query.field("num_value_3_indexed").equalsParameter("p2"), Query.field("num_value_2").equalsParameter("p3"))).buildAndBind(recordStore, Bindings.newBuilder().set("p1", "even").set("p2", 3).set("p3", 0).build());
    assertEquals(query.hashCode(), query2.hashCode());
    assertEquals(query2, query);
}
Also used : BoundRecordQuery(com.apple.foundationdb.record.query.BoundRecordQuery) Test(org.junit.jupiter.api.Test)

Example 3 with BoundRecordQuery

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

the class FDBQueryCompatibilityTest method testQueryCompatibilityConstraintComplex.

@Test
void testQueryCompatibilityConstraintComplex() throws Exception {
    RecordMetaDataHook hook = complexQuerySetupHook();
    complexQuerySetup(hook);
    final RecordQuery query = RecordQuery.newBuilder().setRecordType("MySimpleRecord").setFilter(Query.and(Query.field("str_value_indexed").equalsParameter("p1"), Query.field("str_value_indexed").equalsParameter("p2"), Query.field("str_value_indexed").equalsParameter("p3"), Query.field("str_value_indexed").equalsParameter("p4"), Query.field("str_value_indexed").equalsParameter("p5"), Query.field("str_value_indexed").equalsParameter("p6"), Query.field("str_value_indexed").equalsParameter("p7"), Query.field("str_value_indexed").equalsParameter("p8"), Query.field("num_value_3_indexed").equalsParameter("p9"), Query.field("num_value_2").equalsParameter("p10"))).build();
    BoundRecordQuery boundQuery = query.bind(recordStore, Bindings.newBuilder().set("p1", "even").set("p2", "even").set("p3", "even").set("p4", "even").set("p5", "even").set("p6", "even").set("p7", "even").set("p8", "even").set("p9", 3).set("p10", 0).build());
    BoundRecordQuery boundQuery2 = query.bind(recordStore, Bindings.newBuilder().set("p1", "even").set("p2", "even").set("p3", "even").set("p4", "odd").set("p5", "odd").set("p6", "even").set("p7", "even").set("p8", "even").set("p9", 3).set("p10", 0).build());
    assertNotEquals(boundQuery.hashCode(), boundQuery2.hashCode());
    assertNotEquals(boundQuery2, boundQuery);
    boundQuery2 = query.bind(recordStore, Bindings.newBuilder().set("p1", "odd").set("p2", "odd").set("p3", "odd").set("p4", "odd").set("p5", "odd").set("p6", "odd").set("p7", "odd").set("p8", "odd").set("p9", 3).set("p10", 0).build());
    assertEquals(boundQuery.hashCode(), boundQuery2.hashCode());
    assertEquals(boundQuery2, boundQuery);
}
Also used : BoundRecordQuery(com.apple.foundationdb.record.query.BoundRecordQuery) BoundRecordQuery(com.apple.foundationdb.record.query.BoundRecordQuery) RecordQuery(com.apple.foundationdb.record.query.RecordQuery) Test(org.junit.jupiter.api.Test)

Example 4 with BoundRecordQuery

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

the class FDBQueryCompatibilityTest method testQueryCompatibilityConstraintSimple.

@Test
void testQueryCompatibilityConstraintSimple() throws Exception {
    RecordMetaDataHook hook = complexQuerySetupHook();
    complexQuerySetup(hook);
    final RecordQuery query = RecordQuery.newBuilder().setRecordType("MySimpleRecord").setFilter(Query.and(Query.field("str_value_indexed").equalsParameter("p1"), Query.field("str_value_indexed").equalsParameter("p2"), Query.field("num_value_3_indexed").equalsParameter("p3"), Query.field("num_value_2").equalsParameter("p4"))).build();
    BoundRecordQuery boundQuery = query.bind(recordStore, Bindings.newBuilder().set("p1", "even").set("p2", "even").set("p3", 3).set("p4", 0).build());
    BoundRecordQuery boundQuery2 = query.bind(recordStore, Bindings.newBuilder().set("p1", "even").set("p2", "even").set("p3", 3).set("p4", 0).build());
    assertEquals(boundQuery.hashCode(), boundQuery2.hashCode());
    assertEquals(boundQuery2, boundQuery);
    boundQuery2 = query.bind(recordStore, Bindings.newBuilder().set("p1", "even").set("p2", "odd").set("p3", 3).set("p4", 0).build());
    assertNotEquals(boundQuery.hashCode(), boundQuery2.hashCode());
    assertNotEquals(boundQuery2, boundQuery);
    boundQuery2 = query.bind(recordStore, Bindings.newBuilder().set("p1", "odd").set("p2", "odd").set("p3", 3).set("p4", 0).build());
    assertEquals(boundQuery.hashCode(), boundQuery2.hashCode());
    assertEquals(boundQuery2, boundQuery);
}
Also used : BoundRecordQuery(com.apple.foundationdb.record.query.BoundRecordQuery) BoundRecordQuery(com.apple.foundationdb.record.query.BoundRecordQuery) RecordQuery(com.apple.foundationdb.record.query.RecordQuery) Test(org.junit.jupiter.api.Test)

Example 5 with BoundRecordQuery

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

the class FDBQueryCompatibilityTest method testQueryCompatibilityDifferentStructure.

/**
 * Verify that a complex query with an appropriate multi-field index uses the index.
 */
@Test
void testQueryCompatibilityDifferentStructure() throws Exception {
    RecordMetaDataHook hook = complexQuerySetupHook();
    complexQuerySetup(hook);
    BoundRecordQuery query = RecordQuery.newBuilder().setRecordType("MySimpleRecord1").setFilter(Query.and(Query.field("str_value_indexed").equalsParameter("p1"), Query.field("num_value_3_indexed").equalsParameter("p2"), Query.field("num_value_2").equalsParameter("p3"))).buildAndBind(recordStore, Bindings.newBuilder().set("p1", "even").set("p2", 3).set("p3", 0).build());
    BoundRecordQuery query2 = RecordQuery.newBuilder().setRecordType("MySimpleRecord").setFilter(Query.and(Query.field("str_value_indexed").equalsParameter("p1"), Query.field("num_value_3_indexed").equalsParameter("p2"), Query.field("num_value_2").equalsParameter("p3"))).buildAndBind(recordStore, Bindings.newBuilder().set("p1", "even").set("p2", 3).set("p3", 0).build());
    assertNotEquals(query.hashCode(), query2.hashCode());
    assertNotEquals(query, query2);
}
Also used : BoundRecordQuery(com.apple.foundationdb.record.query.BoundRecordQuery) Test(org.junit.jupiter.api.Test)

Aggregations

BoundRecordQuery (com.apple.foundationdb.record.query.BoundRecordQuery)8 Test (org.junit.jupiter.api.Test)7 RecordQuery (com.apple.foundationdb.record.query.RecordQuery)4 Bindings (com.apple.foundationdb.record.Bindings)1 FDBQueriedRecord (com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord)1 FDBRecordContext (com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext)1 RecordQueryPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan)1 Message (com.google.protobuf.Message)1