Search in sources :

Example 11 with FDBRecordContext

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

the class FDBFilterCoalescingQueryTest method versionRangeCoalesce.

/**
 * Validate that a query for all values within a given range of versions will be coalesced into a single scan.
 * This is similar to the {@link #simpleRangeCoalesce()} test above, but it is for version key expressions in
 * particular.
 */
@Test
public void versionRangeCoalesce() throws Exception {
    Index versionIndex = new Index("MySimpleRecord$version", VersionKeyExpression.VERSION, IndexTypes.VERSION);
    RecordMetaDataHook hook = metaData -> {
        metaData.setStoreRecordVersions(true);
        metaData.addIndex("MySimpleRecord", versionIndex);
    };
    complexQuerySetup(hook);
    try (FDBRecordContext context = openContext()) {
        openSimpleRecordStore(context, hook);
        long readVersion = context.getReadVersion();
        FDBRecordVersion lowBoundary = FDBRecordVersion.firstInDBVersion(0);
        FDBRecordVersion highBoundary = FDBRecordVersion.lastInDBVersion(readVersion);
        RecordQuery query = RecordQuery.newBuilder().setRecordType("MySimpleRecord").setFilter(Query.and(Query.version().greaterThan(lowBoundary), Query.version().lessThan(highBoundary))).build();
        RecordQueryPlan plan = planner.plan(query);
        assertThat(plan, indexScan(allOf(indexName(versionIndex.getName()), bounds(hasTupleString("([" + lowBoundary.toVersionstamp() + "],[" + highBoundary.toVersionstamp() + "])")))));
        try (RecordCursorIterator<FDBQueriedRecord<Message>> cursor = recordStore.executeQuery(plan).asIterator()) {
            int i = 0;
            while (cursor.hasNext()) {
                FDBQueriedRecord<Message> rec = cursor.next();
                FDBRecordVersion version = rec.getVersion();
                assertNotNull(version);
                assertThat(version, allOf(lessThan(highBoundary), greaterThan(lowBoundary)));
                i++;
            }
            assertEquals(100, i);
            assertDiscardedNone(context);
        }
    }
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) PlanMatchers.indexScan(com.apple.foundationdb.record.query.plan.match.PlanMatchers.indexScan) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) FDBRecordVersion(com.apple.foundationdb.record.provider.foundationdb.FDBRecordVersion) RecordQuery(com.apple.foundationdb.record.query.RecordQuery) Collections2(com.google.common.collect.Collections2) RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) PlanMatchers.bounds(com.apple.foundationdb.record.query.plan.match.PlanMatchers.bounds) PlanHashable(com.apple.foundationdb.record.PlanHashable) TestHelpers.assertDiscardedNone(com.apple.foundationdb.record.TestHelpers.assertDiscardedNone) VersionKeyExpression(com.apple.foundationdb.record.metadata.expressions.VersionKeyExpression) RecordCursorIterator(com.apple.foundationdb.record.RecordCursorIterator) Matchers.lessThan(org.hamcrest.Matchers.lessThan) Tag(org.junit.jupiter.api.Tag) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PlanMatchers.coveringIndexScan(com.apple.foundationdb.record.query.plan.match.PlanMatchers.coveringIndexScan) Query(com.apple.foundationdb.record.query.expressions.Query) Matchers.greaterThanOrEqualTo(org.hamcrest.Matchers.greaterThanOrEqualTo) TestRecords1Proto(com.apple.foundationdb.record.TestRecords1Proto) Tags(com.apple.test.Tags) Matchers.allOf(org.hamcrest.Matchers.allOf) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) PlanMatchers.hasTupleString(com.apple.foundationdb.record.query.plan.match.PlanMatchers.hasTupleString) List(java.util.List) PlanMatchers.indexName(com.apple.foundationdb.record.query.plan.match.PlanMatchers.indexName) Index(com.apple.foundationdb.record.metadata.Index) EvaluationContext(com.apple.foundationdb.record.EvaluationContext) FDBQueriedRecord(com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord) Message(com.google.protobuf.Message) IndexTypes(com.apple.foundationdb.record.metadata.IndexTypes) PlanMatchers.descendant(com.apple.foundationdb.record.query.plan.match.PlanMatchers.descendant) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) Matchers.anyOf(org.hamcrest.Matchers.anyOf) RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) Message(com.google.protobuf.Message) Index(com.apple.foundationdb.record.metadata.Index) FDBRecordVersion(com.apple.foundationdb.record.provider.foundationdb.FDBRecordVersion) FDBQueriedRecord(com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) RecordQuery(com.apple.foundationdb.record.query.RecordQuery) Test(org.junit.jupiter.api.Test)

Example 12 with FDBRecordContext

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

the class FDBRecordStoreIndexTest method scanIndexWithValue.

/**
 * Verify that explicit (i.e. bypassing the planner) index scans work .
 */
@Test
public void scanIndexWithValue() throws Exception {
    RecordMetaDataHook hook = metaData -> {
        metaData.removeIndex("MySimpleRecord$num_value_unique");
        metaData.addIndex("MySimpleRecord", new Index("multi_index_value", Key.Expressions.field("num_value_unique"), Key.Expressions.field("num_value_2"), IndexTypes.VALUE, IndexOptions.UNIQUE_OPTIONS));
    };
    complexQuerySetup(hook);
    try (FDBRecordContext context = openContext()) {
        openSimpleRecordStore(context, hook);
        int i = 0;
        try (RecordCursorIterator<IndexEntry> cursor = recordStore.scanIndex(recordStore.getRecordMetaData().getIndex("multi_index_value"), IndexScanType.BY_VALUE, new TupleRange(Tuple.from(900L), Tuple.from(950L), EndpointType.RANGE_INCLUSIVE, EndpointType.RANGE_INCLUSIVE), null, ScanProperties.FORWARD_SCAN).asIterator()) {
            while (cursor.hasNext()) {
                IndexEntry tuples = cursor.next();
                Tuple key = tuples.getKey();
                Tuple value = tuples.getValue();
                assertEquals(2, key.size());
                assertEquals(1, value.size());
                assertTrue(key.getLong(0) >= 900);
                assertTrue(key.getLong(0) <= 950);
                assertTrue(value.getLong(0) == (999 - i) % 3);
                i++;
            }
        }
        assertEquals(50, i);
        assertDiscardedNone(context);
    }
}
Also used : IndexEntry(com.apple.foundationdb.record.IndexEntry) Arrays(java.util.Arrays) Descriptors(com.google.protobuf.Descriptors) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) RecordQuery(com.apple.foundationdb.record.query.RecordQuery) Function(java.util.function.Function) Key(com.apple.foundationdb.record.metadata.Key) TestHelpers.assertDiscardedNone(com.apple.foundationdb.record.TestHelpers.assertDiscardedNone) IndexScanType(com.apple.foundationdb.record.IndexScanType) Tuple(com.apple.foundationdb.tuple.Tuple) TestHelpers(com.apple.foundationdb.record.TestHelpers) EndpointType(com.apple.foundationdb.record.EndpointType) ScanProperties(com.apple.foundationdb.record.ScanProperties) TestHelpers.assertDiscardedAtLeast(com.apple.foundationdb.record.TestHelpers.assertDiscardedAtLeast) RecordCursorIterator(com.apple.foundationdb.record.RecordCursorIterator) Tag(org.junit.jupiter.api.Tag) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Nullable(javax.annotation.Nullable) FDBRecordStoreBase(com.apple.foundationdb.record.provider.foundationdb.FDBRecordStoreBase) TestRecords4Proto(com.apple.foundationdb.record.TestRecords4Proto) Query(com.apple.foundationdb.record.query.expressions.Query) TestRecords1Proto(com.apple.foundationdb.record.TestRecords1Proto) IndexOptions(com.apple.foundationdb.record.metadata.IndexOptions) FDBStoreTimer(com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer) Tags(com.apple.test.Tags) TupleRange(com.apple.foundationdb.record.TupleRange) Test(org.junit.jupiter.api.Test) Objects(java.util.Objects) Index(com.apple.foundationdb.record.metadata.Index) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Message(com.google.protobuf.Message) IndexTypes(com.apple.foundationdb.record.metadata.IndexTypes) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) IndexEntry(com.apple.foundationdb.record.IndexEntry) Index(com.apple.foundationdb.record.metadata.Index) TupleRange(com.apple.foundationdb.record.TupleRange) Tuple(com.apple.foundationdb.tuple.Tuple) Test(org.junit.jupiter.api.Test)

Example 13 with FDBRecordContext

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

the class FDBRecordStoreNullQueryTest method testProto3.

// Proto3 scalar fields do not distinguish missing from default value, even if set explicitly.
// They both return false for hasField, which means they look like null by default.
// Key.Evaluated.NullStandin.NOT_NULL gives consistent behavior for Proto 2 and Proto 3.
@ParameterizedTest(name = "testProto3({0})")
@MethodSource("testProto3Params")
public void testProto3(String testName, boolean buildDynamic, boolean scalarFieldsNotNull) {
    try (FDBRecordContext context = openContext()) {
        createOrOpenRecordStore(context, scalarFieldsNotNull ? proto3ScalarNotNullMetaData() : proto3MetaData());
        saveTestRecords(buildDynamic ? FDBRecordStoreNullQueryTest::buildRecord3Dynamic : FDBRecordStoreNullQueryTest::buildRecord3);
        assertThat(executeQuery(RecordQuery.newBuilder().setRecordType("MyNullRecord").setFilter(Query.field("int_value").equalsValue(2)).build()), is(Collections.singletonList("two")));
        assertThat(executeQuery(RecordQuery.newBuilder().setRecordType("MyNullRecord").setFilter(Query.field("string_value").equalsValue("B")).build()), is(Collections.singletonList("two")));
        assertThat(executeQuery(RecordQuery.newBuilder().setRecordType("MyNullRecord").setFilter(Query.field("int_value").isNull()).build()), is(scalarFieldsNotNull ? Collections.emptyList() : isProto3() ? Arrays.asList("default", "empty") : Collections.singletonList("empty")));
        assertThat(executeQuery(RecordQuery.newBuilder().setRecordType("MyNullRecord").setFilter(Query.field("int_value").equalsValue(0)).build()), is(scalarFieldsNotNull ? Arrays.asList("default", "empty") : isProto3() ? Collections.emptyList() : Collections.singletonList("default")));
        assertThat(executeQuery(RecordQuery.newBuilder().setRecordType("MyNullRecord").setFilter(Query.field("string_value").isNull()).build()), is(scalarFieldsNotNull ? Collections.emptyList() : isProto3() ? Arrays.asList("default", "empty") : Collections.singletonList("empty")));
        assertThat(executeQuery(RecordQuery.newBuilder().setRecordType("MyNullRecord").setFilter(Query.field("string_value").equalsValue("")).build()), is(scalarFieldsNotNull ? Arrays.asList("default", "empty") : isProto3() ? Collections.emptyList() : Collections.singletonList("default")));
        assertThat(executeQuery(RecordQuery.newBuilder().setRecordType("MyNullRecord").setSort(Key.Expressions.field("int_value")).build()), is(scalarFieldsNotNull ? Arrays.asList("minus", "default", "empty", "one", "two") : isProto3() ? Arrays.asList("default", "empty", "minus", "one", "two") : Arrays.asList("empty", "minus", "default", "one", "two")));
    }
}
Also used : FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 14 with FDBRecordContext

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

the class FDBRecordStoreNullQueryTest method testTupleFields.

@Test
public void testTupleFields() throws Exception {
    final UUID nullId = UUID.randomUUID();
    final UUID emptyId = UUID.randomUUID();
    final UUID defaultId = UUID.randomUUID();
    final UUID otherId = UUID.randomUUID();
    final TestRecordsTupleFieldsProto.MyFieldsRecord nullRecord = TestRecordsTupleFieldsProto.MyFieldsRecord.newBuilder().setUuid(TupleFieldsHelper.toProto(nullId)).build();
    final TestRecordsTupleFieldsProto.MyFieldsRecord emptyRecord = TestRecordsTupleFieldsProto.MyFieldsRecord.newBuilder().setUuid(TupleFieldsHelper.toProto(emptyId)).setFdouble(TupleFieldsProto.NullableDouble.getDefaultInstance()).setFfloat(TupleFieldsProto.NullableFloat.getDefaultInstance()).setFint32(TupleFieldsProto.NullableInt32.getDefaultInstance()).setFint64(TupleFieldsProto.NullableInt64.getDefaultInstance()).setFbool(TupleFieldsProto.NullableBool.getDefaultInstance()).setFstring(TupleFieldsProto.NullableString.getDefaultInstance()).setFbytes(TupleFieldsProto.NullableBytes.getDefaultInstance()).build();
    final TestRecordsTupleFieldsProto.MyFieldsRecord defaultRecord = TestRecordsTupleFieldsProto.MyFieldsRecord.newBuilder().setUuid(TupleFieldsHelper.toProto(defaultId)).setFdouble(TupleFieldsHelper.toProto(0.0)).setFfloat(TupleFieldsHelper.toProto(0.0f)).setFint32(TupleFieldsHelper.toProto(0)).setFint64(TupleFieldsHelper.toProto(0L)).setFbool(TupleFieldsHelper.toProto(false)).setFstring(TupleFieldsHelper.toProto("")).setFbytes(TupleFieldsHelper.toProto(ByteString.EMPTY)).build();
    final TestRecordsTupleFieldsProto.MyFieldsRecord otherRecord = TestRecordsTupleFieldsProto.MyFieldsRecord.newBuilder().setUuid(TupleFieldsHelper.toProto(otherId)).setFdouble(TupleFieldsHelper.toProto(1.0)).setFfloat(TupleFieldsHelper.toProto(1.0f)).setFint32(TupleFieldsHelper.toProto(1)).setFint64(TupleFieldsHelper.toProto(1L)).setFbool(TupleFieldsHelper.toProto(true)).setFstring(TupleFieldsHelper.toProto(" ")).setFbytes(TupleFieldsHelper.toProto(ByteString.copyFrom(" ", "UTF-8"))).build();
    try (FDBRecordContext context = openContext()) {
        createOrOpenRecordStore(context, tupleFieldsMetaData());
        recordStore.saveRecord(nullRecord);
        recordStore.saveRecord(emptyRecord);
        recordStore.saveRecord(defaultRecord);
        recordStore.saveRecord(otherRecord);
        context.commit();
    }
    try (FDBRecordContext context = openContext()) {
        createOrOpenRecordStore(context, tupleFieldsMetaData());
        assertEquals(nullId, fieldsRecordId(recordStore.loadRecord(Tuple.from(nullId))));
        assertEquals(otherId, fieldsRecordId(recordStore.loadRecord(Tuple.from(otherId))));
        assertEquals(Collections.singleton(nullId), fieldsRecordQuery(context, Query.field("fdouble").isNull()));
        assertEquals(Collections.singleton(nullId), fieldsRecordQuery(context, Query.field("ffloat").isNull()));
        assertEquals(Collections.singleton(nullId), fieldsRecordQuery(context, Query.field("fint32").isNull()));
        assertEquals(Collections.singleton(nullId), fieldsRecordQuery(context, Query.field("fint64").isNull()));
        assertEquals(Collections.singleton(nullId), fieldsRecordQuery(context, Query.field("fbool").isNull()));
        assertEquals(Collections.singleton(nullId), fieldsRecordQuery(context, Query.field("fstring").isNull()));
        assertEquals(Collections.singleton(nullId), fieldsRecordQuery(context, Query.field("fbytes").isNull()));
        assertEquals(ImmutableSet.of(emptyId, defaultId), fieldsRecordQuery(context, Query.field("fdouble").equalsValue(0.0)));
        assertEquals(ImmutableSet.of(emptyId, defaultId), fieldsRecordQuery(context, Query.field("ffloat").equalsValue(0.0f)));
        assertEquals(ImmutableSet.of(emptyId, defaultId), fieldsRecordQuery(context, Query.field("fint32").equalsValue(0)));
        assertEquals(ImmutableSet.of(emptyId, defaultId), fieldsRecordQuery(context, Query.field("fint64").equalsValue(0L)));
        assertEquals(ImmutableSet.of(emptyId, defaultId), fieldsRecordQuery(context, Query.field("fbool").equalsValue(false)));
        assertEquals(ImmutableSet.of(emptyId, defaultId), fieldsRecordQuery(context, Query.field("fstring").equalsValue("")));
        assertEquals(ImmutableSet.of(emptyId, defaultId), fieldsRecordQuery(context, Query.field("fbytes").equalsValue(ByteString.EMPTY)));
        assertEquals(Collections.singleton(otherId), fieldsRecordQuery(context, Query.field("fdouble").equalsValue(1.0)));
        assertEquals(Collections.singleton(otherId), fieldsRecordQuery(context, Query.field("ffloat").equalsValue(1.0f)));
        assertEquals(Collections.singleton(otherId), fieldsRecordQuery(context, Query.field("fint32").equalsValue(1)));
        assertEquals(Collections.singleton(otherId), fieldsRecordQuery(context, Query.field("fint64").equalsValue(1L)));
        assertEquals(Collections.singleton(otherId), fieldsRecordQuery(context, Query.field("fbool").equalsValue(true)));
        assertEquals(Collections.singleton(otherId), fieldsRecordQuery(context, Query.field("fstring").equalsValue(" ")));
        assertEquals(Collections.singleton(otherId), fieldsRecordQuery(context, Query.field("fbytes").equalsValue(ByteString.copyFrom(" ", "UTF-8"))));
        {
            final RecordQueryPlan coveringPlan = planner.plan(RecordQuery.newBuilder().setRecordType("MyFieldsRecord").setFilter(Query.field("fint64").greaterThan(0L)).setRequiredResults(Stream.of("uuid", "fint64").map(Key.Expressions::field).collect(Collectors.toList())).build());
            assertThat(coveringPlan, PlanMatchers.coveringIndexScan(PlanMatchers.indexScan(PlanMatchers.indexName("MyFieldsRecord$fint64"))));
            final List<Pair<UUID, Long>> results = recordStore.executeQuery(coveringPlan).map(rec -> {
                final TestRecordsTupleFieldsProto.MyFieldsRecord myrec = TestRecordsTupleFieldsProto.MyFieldsRecord.newBuilder().mergeFrom(rec.getRecord()).build();
                return Pair.of(TupleFieldsHelper.fromProto(myrec.getUuid()), TupleFieldsHelper.fromProto(myrec.getFint64()));
            }).asList().join();
            assertEquals(Collections.singletonList(Pair.of(otherId, 1L)), results);
        }
        context.commit();
    }
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) RecordMetaData(com.apple.foundationdb.record.RecordMetaData) Arrays(java.util.Arrays) DynamicMessage(com.google.protobuf.DynamicMessage) FDBRecord(com.apple.foundationdb.record.provider.foundationdb.FDBRecord) Descriptors(com.google.protobuf.Descriptors) TestRecordsNulls2Proto(com.apple.foundationdb.record.TestRecordsNulls2Proto) Matchers.not(org.hamcrest.Matchers.not) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) RecordQuery(com.apple.foundationdb.record.query.RecordQuery) TestRecordsTupleFieldsProto(com.apple.foundationdb.record.TestRecordsTupleFieldsProto) RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) Key(com.apple.foundationdb.record.metadata.Key) PlanMatchers(com.apple.foundationdb.record.query.plan.match.PlanMatchers) HashSet(java.util.HashSet) Tuple(com.apple.foundationdb.tuple.Tuple) Pair(org.apache.commons.lang3.tuple.Pair) Tag(org.junit.jupiter.api.Tag) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ProtoVersionSupplier(com.apple.foundationdb.record.ProtoVersionSupplier) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) MethodSource(org.junit.jupiter.params.provider.MethodSource) Query(com.apple.foundationdb.record.query.expressions.Query) KeyExpression(com.apple.foundationdb.record.metadata.expressions.KeyExpression) ImmutableSet(com.google.common.collect.ImmutableSet) RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) TupleFieldsHelper(com.apple.foundationdb.record.metadata.expressions.TupleFieldsHelper) Tags(com.apple.test.Tags) Set(java.util.Set) TupleFieldsProto(com.apple.foundationdb.record.TupleFieldsProto) UUID(java.util.UUID) Arguments(org.junit.jupiter.params.provider.Arguments) Collectors(java.util.stream.Collectors) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) List(java.util.List) Stream(java.util.stream.Stream) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Message(com.google.protobuf.Message) QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) Matchers.is(org.hamcrest.Matchers.is) TestRecordsNulls3Proto(com.apple.foundationdb.record.TestRecordsNulls3Proto) Collections(java.util.Collections) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) List(java.util.List) UUID(java.util.UUID) TestRecordsTupleFieldsProto(com.apple.foundationdb.record.TestRecordsTupleFieldsProto) Key(com.apple.foundationdb.record.metadata.Key) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 15 with FDBRecordContext

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

the class FDBRecordStoreQueryTest method query.

@DualPlannerTest
void query() throws Exception {
    try (FDBRecordContext context = openContext()) {
        openSimpleRecordStore(context);
        for (int i = 0; i < 100; i++) {
            TestRecords1Proto.MySimpleRecord.Builder recBuilder = TestRecords1Proto.MySimpleRecord.newBuilder();
            recBuilder.setRecNo(i);
            recBuilder.setStrValueIndexed((i & 1) == 1 ? "odd" : "even");
            recBuilder.setNumValueUnique(i + 1000);
            recordStore.saveRecord(recBuilder.build());
        }
        commit(context);
    }
    RecordQuery query = RecordQuery.newBuilder().setRecordType("MySimpleRecord").setFilter(Query.field("str_value_indexed").equalsValue("even")).build();
    RecordQueryPlan plan = planner.plan(query);
    try (FDBRecordContext context = openContext()) {
        openSimpleRecordStore(context);
        int i = 0;
        try (RecordCursorIterator<FDBQueriedRecord<Message>> cursor = recordStore.executeQuery(plan).asIterator()) {
            while (cursor.hasNext()) {
                FDBQueriedRecord<Message> rec = Objects.requireNonNull(cursor.next());
                TestRecords1Proto.MySimpleRecord.Builder myrec = TestRecords1Proto.MySimpleRecord.newBuilder();
                myrec.mergeFrom(rec.getRecord());
                assertEquals(0, myrec.getNumValueUnique() % 2);
                i++;
            }
        }
        assertEquals(50, i);
        assertDiscardedNone(context);
    }
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) FDBQueriedRecord(com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord) Message(com.google.protobuf.Message) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) RecordQuery(com.apple.foundationdb.record.query.RecordQuery)

Aggregations

FDBRecordContext (com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext)542 Test (org.junit.jupiter.api.Test)365 RecordQueryPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan)226 RecordQuery (com.apple.foundationdb.record.query.RecordQuery)215 Message (com.google.protobuf.Message)187 FDBQueriedRecord (com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord)170 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)165 Tuple (com.apple.foundationdb.tuple.Tuple)147 Tag (org.junit.jupiter.api.Tag)136 Tags (com.apple.test.Tags)129 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)123 List (java.util.List)121 Index (com.apple.foundationdb.record.metadata.Index)119 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)114 ArrayList (java.util.ArrayList)112 Collections (java.util.Collections)100 Query (com.apple.foundationdb.record.query.expressions.Query)97 RecordQueryPlanner (com.apple.foundationdb.record.query.plan.RecordQueryPlanner)96 Arrays (java.util.Arrays)94 ExecuteProperties (com.apple.foundationdb.record.ExecuteProperties)93