Search in sources :

Example 36 with NodeValueIndexCursor

use of org.neo4j.internal.kernel.api.NodeValueIndexCursor 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 37 with NodeValueIndexCursor

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

the class ManagedTestCursors method allocateNodeValueIndexCursor.

@Override
public NodeValueIndexCursor allocateNodeValueIndexCursor(CursorContext cursorContext, MemoryTracker memoryTracker) {
    NodeValueIndexCursor n = cursors.allocateNodeValueIndexCursor(cursorContext, memoryTracker);
    allCursors.add(n);
    return n;
}
Also used : NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor)

Example 38 with NodeValueIndexCursor

use of org.neo4j.internal.kernel.api.NodeValueIndexCursor 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 39 with NodeValueIndexCursor

use of org.neo4j.internal.kernel.api.NodeValueIndexCursor 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)

Example 40 with NodeValueIndexCursor

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

the class FulltextIndexProviderTest method assertQueryResult.

private void assertQueryResult(KernelTransaction ktx, PropertyIndexQuery query, Long... expectedResultArray) throws KernelException {
    List<Long> expectedResult = Arrays.asList(expectedResultArray);
    IndexReadSession index = ktx.dataRead().indexReadSession(ktx.schemaRead().indexGetForName(NAME));
    try (NodeValueIndexCursor cursor = ktx.cursors().allocateNodeValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
        List<Long> actualResult = new ArrayList<>();
        ktx.dataRead().nodeIndexSeek(index, cursor, unconstrained(), query);
        while (cursor.next()) {
            actualResult.add(cursor.nodeReference());
        }
        actualResult.sort(Long::compareTo);
        expectedResult.sort(Long::compareTo);
        assertThat(actualResult).isEqualTo(expectedResult);
    }
}
Also used : NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) ArrayList(java.util.ArrayList) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession)

Aggregations

NodeValueIndexCursor (org.neo4j.internal.kernel.api.NodeValueIndexCursor)42 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)25 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)20 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)20 Test (org.junit.jupiter.api.Test)18 Transaction (org.neo4j.graphdb.Transaction)16 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)16 ArrayList (java.util.ArrayList)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 MethodSource (org.junit.jupiter.params.provider.MethodSource)9 TokenRead (org.neo4j.internal.kernel.api.TokenRead)7 Read (org.neo4j.internal.kernel.api.Read)6 Value (org.neo4j.values.storable.Value)6 KernelException (org.neo4j.exceptions.KernelException)3 Node (org.neo4j.graphdb.Node)3 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)2 Label (org.neo4j.graphdb.Label)2 IndexQueryConstraints (org.neo4j.internal.kernel.api.IndexQueryConstraints)2 NodeIndexCursor (org.neo4j.internal.kernel.api.NodeIndexCursor)2 PropertyIndexQuery (org.neo4j.internal.kernel.api.PropertyIndexQuery)2