Search in sources :

Example 11 with TokenPredicate

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

the class NodeLabelIndexOrderTest method tokenScan.

@Override
protected void tokenScan(IndexOrder indexOrder, KernelTransaction tx, int label, NodeLabelIndexCursor cursor) throws KernelException {
    IndexDescriptor index = tx.schemaRead().index(SchemaDescriptor.forAnyEntityTokens(EntityType.NODE)).next();
    TokenReadSession tokenReadSession = tx.dataRead().tokenReadSession(index);
    tx.dataRead().nodeLabelScan(tokenReadSession, cursor, IndexQueryConstraints.ordered(indexOrder), new TokenPredicate(label));
}
Also used : TokenReadSession(org.neo4j.internal.kernel.api.TokenReadSession) TokenPredicate(org.neo4j.internal.kernel.api.TokenPredicate) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 12 with TokenPredicate

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

the class KernelReadTracerTxStateTest method shouldTraceRelationshipTypeScan.

@Test
void shouldTraceRelationshipTypeScan() throws KernelException {
    // given
    TestKernelReadTracer tracer = new TestKernelReadTracer();
    try (KernelTransaction tx = beginTransaction();
        RelationshipTypeIndexCursor cursor = tx.cursors().allocateRelationshipTypeIndexCursor(NULL)) {
        int rType = tx.token().relationshipTypeGetOrCreateForName("R");
        long n1 = tx.dataWrite().nodeCreate();
        long n2 = tx.dataWrite().nodeCreate();
        tx.dataWrite().relationshipCreate(n1, rType, n2);
        // when
        cursor.setTracer(tracer);
        tx.dataRead().relationshipTypeScan(getTokenReadSession(tx, EntityType.RELATIONSHIP), cursor, IndexQueryConstraints.unconstrained(), new TokenPredicate(rType));
        tracer.assertEvents(OnRelationshipTypeScan(rType));
        assertTrue(cursor.next());
        tracer.assertEvents(OnRelationship(cursor.relationshipReference()));
        assertFalse(cursor.next());
        tracer.assertEvents();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TokenPredicate(org.neo4j.internal.kernel.api.TokenPredicate) RelationshipTypeIndexCursor(org.neo4j.internal.kernel.api.RelationshipTypeIndexCursor) Test(org.junit.jupiter.api.Test)

Example 13 with TokenPredicate

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

the class KernelReadTracerTxStateTest method shouldTraceLabelScan.

@Test
void shouldTraceLabelScan() throws KernelException {
    // given
    TestKernelReadTracer tracer = new TestKernelReadTracer();
    try (KernelTransaction tx = beginTransaction();
        NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor(NULL)) {
        int barId = tx.tokenWrite().labelGetOrCreateForName("Bar");
        long n = tx.dataWrite().nodeCreate();
        tx.dataWrite().nodeAddLabel(n, barId);
        // when
        cursor.setTracer(tracer);
        tx.dataRead().nodeLabelScan(getTokenReadSession(tx, EntityType.NODE), cursor, IndexQueryConstraints.unconstrained(), new TokenPredicate(barId));
        tracer.assertEvents(OnLabelScan(barId));
        assertTrue(cursor.next());
        tracer.assertEvents(OnNode(cursor.nodeReference()));
        assertFalse(cursor.next());
        tracer.assertEvents();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TokenPredicate(org.neo4j.internal.kernel.api.TokenPredicate) NodeLabelIndexCursor(org.neo4j.internal.kernel.api.NodeLabelIndexCursor) Test(org.junit.jupiter.api.Test)

Example 14 with TokenPredicate

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

the class BatchInsertTokenIndexesTest method assertTokenIndexContains.

private void assertTokenIndexContains(TokenIndexReader reader, int tokenId, Long... intityIds) {
    SimpleEntityTokenClient tokenClient = new SimpleEntityTokenClient();
    reader.query(tokenClient, unconstrained(), new TokenPredicate(tokenId), CursorContext.NULL);
    var found = new ArrayList<Long>();
    while (tokenClient.next()) {
        found.add(tokenClient.reference);
    }
    assertThat(found).containsExactlyInAnyOrder(intityIds);
}
Also used : TokenPredicate(org.neo4j.internal.kernel.api.TokenPredicate) ArrayList(java.util.ArrayList) SimpleEntityTokenClient(org.neo4j.storageengine.api.schema.SimpleEntityTokenClient)

Example 15 with TokenPredicate

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

the class DefaultPooledCursorsTestBase method shouldReuseFullAccessNodeLabelIndexCursor.

@Test
void shouldReuseFullAccessNodeLabelIndexCursor() throws Exception {
    try (KernelTransaction tx = beginTransaction()) {
        NodeLabelIndexCursor c1 = tx.cursors().allocateFullAccessNodeLabelIndexCursor(NULL);
        tx.dataRead().nodeLabelScan(getTokenReadSession(tx, EntityType.NODE), c1, IndexQueryConstraints.unconstrained(), new TokenPredicate(1));
        c1.close();
        NodeLabelIndexCursor c2 = tx.cursors().allocateFullAccessNodeLabelIndexCursor(NULL);
        assertThat(c1).isSameAs(c2);
        c2.close();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TokenPredicate(org.neo4j.internal.kernel.api.TokenPredicate) NodeLabelIndexCursor(org.neo4j.internal.kernel.api.NodeLabelIndexCursor) Test(org.junit.jupiter.api.Test)

Aggregations

TokenPredicate (org.neo4j.internal.kernel.api.TokenPredicate)32 Test (org.junit.jupiter.api.Test)16 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)13 NodeLabelIndexCursor (org.neo4j.internal.kernel.api.NodeLabelIndexCursor)11 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)6 KernelException (org.neo4j.exceptions.KernelException)5 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)5 SimpleEntityTokenClient (org.neo4j.storageengine.api.schema.SimpleEntityTokenClient)5 ArrayList (java.util.ArrayList)4 TokenReadSession (org.neo4j.internal.kernel.api.TokenReadSession)4 InvalidTransactionTypeKernelException (org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException)4 SchemaKernelException (org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException)4 QueryExecutionKernelException (org.neo4j.kernel.impl.query.QueryExecutionKernelException)4 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)2 LongHashSet (org.eclipse.collections.impl.set.mutable.primitive.LongHashSet)2 Read (org.neo4j.internal.kernel.api.Read)2 RelationshipTypeIndexCursor (org.neo4j.internal.kernel.api.RelationshipTypeIndexCursor)2 CursorIterator (org.neo4j.kernel.impl.coreapi.internal.CursorIterator)2 TraceEvent (org.neo4j.kernel.impl.newapi.TestKernelReadTracer.TraceEvent)2 PrimitiveIterator (java.util.PrimitiveIterator)1