Search in sources :

Example 66 with IndexReadSession

use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.

the class IndexOrderTestBase method shouldDoOrderedCompositeIndexScanWithPointsInBothValuesWithTwoGapsBetween.

@ParameterizedTest
@EnumSource(value = IndexOrder.class, names = { "ASCENDING", "DESCENDING" })
void shouldDoOrderedCompositeIndexScanWithPointsInBothValuesWithTwoGapsBetween(IndexOrder indexOrder) throws Exception {
    List<Pair<Long, Value[]>> expected = new ArrayList<>();
    try (KernelTransaction tx = beginTransaction()) {
        expected.add(entityWithTwoProps(tx, new String[] { "a" }, new String[] { "b" }));
        expected.add(entityWithTwoProps(tx, pointValue(Cartesian, -500000, -500000), "a"));
        expected.add(entityWithTwoProps(tx, pointValue(Cartesian, 500000, -500000), "a"));
        expected.add(entityWithTwoProps(tx, pointValue(Cartesian, -500000, 500000), "a"));
        expected.add(entityWithTwoProps(tx, pointValue(Cartesian, 500000, 500000), "a"));
        expected.add(entityWithTwoProps(tx, "b", new String[] { "b" }));
        expected.add(entityWithTwoProps(tx, "b", new String[] { "c" }));
        expected.add(entityWithTwoProps(tx, "b", pointValue(Cartesian, -500000, -500000)));
        expected.add(entityWithTwoProps(tx, "b", pointValue(Cartesian, 500000, -500000)));
        expected.add(entityWithTwoProps(tx, "b", pointValue(Cartesian, -500000, 500000)));
        expected.add(entityWithTwoProps(tx, "b", pointValue(Cartesian, 500000, 500000)));
        expected.add(entityWithTwoProps(tx, "c", new String[] { "b" }));
        tx.commit();
    }
    createCompositeIndex();
    // when
    try (KernelTransaction tx = beginTransaction()) {
        IndexReadSession index = tx.dataRead().indexReadSession(tx.schemaRead().indexGetForName(INDEX_NAME));
        try (var cursor = getEntityValueIndexCursor(tx)) {
            entityIndexScan(tx, index, cursor, constrained(indexOrder, true));
            assertCompositeResultsInOrder(expected, cursor, indexOrder);
        }
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Value(org.neo4j.values.storable.Value) Values.pointValue(org.neo4j.values.storable.Values.pointValue) TextValue(org.neo4j.values.storable.TextValue) Values.stringValue(org.neo4j.values.storable.Values.stringValue) PointValue(org.neo4j.values.storable.PointValue) ArrayList(java.util.ArrayList) Pair(org.neo4j.internal.helpers.collection.Pair) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 67 with IndexReadSession

use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.

the class KernelReadTracerTest method shouldTraceNodeIndexSeek.

@Test
void shouldTraceNodeIndexSeek() throws KernelException {
    // given
    TestKernelReadTracer tracer = new TestKernelReadTracer();
    try (NodeValueIndexCursor cursor = cursors.allocateNodeValueIndexCursor(NULL, EmptyMemoryTracker.INSTANCE)) {
        int p1 = token.propertyKey("p1");
        IndexReadSession session = read.indexReadSession(index);
        assertIndexSeekTracing(tracer, cursor, session, IndexOrder.NONE, p1);
        assertIndexSeekTracing(tracer, cursor, session, IndexOrder.ASCENDING, p1);
    }
}
Also used : NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Example 68 with IndexReadSession

use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.

the class KernelReadTracerTest method shouldTraceRelationshipIndexSeek.

@Test
void shouldTraceRelationshipIndexSeek() throws KernelException {
    // given
    TestKernelReadTracer tracer = new TestKernelReadTracer();
    try (RelationshipValueIndexCursor cursor = cursors.allocateRelationshipValueIndexCursor(NULL, INSTANCE)) {
        int p1 = token.propertyKey("p1");
        IndexReadSession session = read.indexReadSession(relIndex);
        assertRelationshipIndexSeekTracing(tracer, cursor, session, IndexOrder.NONE, p1);
        assertRelationshipIndexSeekTracing(tracer, cursor, session, IndexOrder.ASCENDING, p1);
    }
}
Also used : RelationshipValueIndexCursor(org.neo4j.internal.kernel.api.RelationshipValueIndexCursor) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Example 69 with IndexReadSession

use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.

the class KernelReadTracerTxStateTest method shouldTraceIndexSeek.

@Test
void shouldTraceIndexSeek() throws KernelException {
    // given
    TestKernelReadTracer tracer = new TestKernelReadTracer();
    String indexName = createIndex("User", "name");
    try (KernelTransaction tx = beginTransaction();
        NodeValueIndexCursor cursor = tx.cursors().allocateNodeValueIndexCursor(NULL, tx.memoryTracker())) {
        int name = tx.token().propertyKey("name");
        int user = tx.token().nodeLabel("User");
        long n = tx.dataWrite().nodeCreate();
        tx.dataWrite().nodeAddLabel(n, user);
        tx.dataWrite().nodeSetProperty(n, name, Values.stringValue("Bosse"));
        IndexDescriptor index = tx.schemaRead().indexGetForName(indexName);
        IndexReadSession session = tx.dataRead().indexReadSession(index);
        // when
        assertIndexSeekTracing(tracer, tx, cursor, session, IndexOrder.NONE, false, user);
        assertIndexSeekTracing(tracer, tx, cursor, session, IndexOrder.NONE, true, user);
        assertIndexSeekTracing(tracer, tx, cursor, session, IndexOrder.ASCENDING, false, user);
        assertIndexSeekTracing(tracer, tx, cursor, session, IndexOrder.ASCENDING, true, user);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Example 70 with IndexReadSession

use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.

the class FulltextIndexProviderTest method verifyNodeData.

private void verifyNodeData(long thirdNodeId) throws Exception {
    try (Transaction tx = db.beginTx()) {
        KernelTransaction ktx = LuceneFulltextTestSupport.kernelTransaction(tx);
        IndexReadSession index = ktx.dataRead().indexReadSession(ktx.schemaRead().indexGetForName("fulltext"));
        try (NodeValueIndexCursor cursor = ktx.cursors().allocateNodeValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
            ktx.dataRead().nodeIndexSeek(index, cursor, unconstrained(), fulltextSearch("value"));
            assertTrue(cursor.next());
            assertEquals(0L, cursor.nodeReference());
            assertFalse(cursor.next());
            ktx.dataRead().nodeIndexSeek(index, cursor, unconstrained(), fulltextSearch("villa"));
            assertTrue(cursor.next());
            assertEquals(thirdNodeId, cursor.nodeReference());
            assertFalse(cursor.next());
            ktx.dataRead().nodeIndexSeek(index, cursor, unconstrained(), fulltextSearch("value3"));
            MutableLongSet ids = LongSets.mutable.empty();
            ids.add(0L);
            ids.add(thirdNodeId);
            assertTrue(cursor.next());
            assertTrue(ids.remove(cursor.nodeReference()));
            assertTrue(cursor.next());
            assertTrue(ids.remove(cursor.nodeReference()));
            assertFalse(cursor.next());
        }
        tx.commit();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession)

Aggregations

IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)93 Test (org.junit.jupiter.api.Test)62 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)47 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)22 NodeValueIndexCursor (org.neo4j.internal.kernel.api.NodeValueIndexCursor)20 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)17 LongHashSet (org.eclipse.collections.impl.set.mutable.primitive.LongHashSet)15 ArrayList (java.util.ArrayList)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 EnumSource (org.junit.jupiter.params.provider.EnumSource)12 RelationshipValueIndexCursor (org.neo4j.internal.kernel.api.RelationshipValueIndexCursor)12 IndexValueCapability (org.neo4j.internal.schema.IndexValueCapability)12 Pair (org.neo4j.internal.helpers.collection.Pair)11 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)10 Transaction (org.neo4j.graphdb.Transaction)9 IndexQueryConstraints (org.neo4j.internal.kernel.api.IndexQueryConstraints)9 IndexOrderCapability (org.neo4j.internal.schema.IndexOrderCapability)7 Read (org.neo4j.internal.kernel.api.Read)6 TokenRead (org.neo4j.internal.kernel.api.TokenRead)6 PropertyIndexQuery (org.neo4j.internal.kernel.api.PropertyIndexQuery)5