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