Search in sources :

Example 31 with TokenPredicate

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

the class TransactionImpl method allNodesWithLabel.

private ResourceIterator<Node> allNodesWithLabel(final Label myLabel) {
    KernelTransaction ktx = kernelTransaction();
    int labelId = ktx.tokenRead().nodeLabel(myLabel.name());
    if (labelId == TokenRead.NO_TOKEN) {
        return emptyResourceIterator();
    }
    var index = findUsableMatchingIndex(ktx, SchemaDescriptor.forAnyEntityTokens(EntityType.NODE));
    if (index != IndexDescriptor.NO_INDEX) {
        try {
            var session = ktx.dataRead().tokenReadSession(index);
            var cursor = ktx.cursors().allocateNodeLabelIndexCursor(ktx.cursorContext());
            ktx.dataRead().nodeLabelScan(session, cursor, unconstrained(), new TokenPredicate(labelId));
            return new CursorIterator<>(cursor, NodeIndexCursor::nodeReference, c -> newNodeEntity(c.nodeReference()), coreApiResourceTracker);
        } catch (KernelException e) {
        // ignore, fallback to all node scan
        }
    }
    return allNodesByLabelWithoutIndex(ktx, labelId);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeIndexCursor(org.neo4j.internal.kernel.api.NodeIndexCursor) TokenPredicate(org.neo4j.internal.kernel.api.TokenPredicate) CursorIterator(org.neo4j.kernel.impl.coreapi.internal.CursorIterator) InvalidTransactionTypeKernelException(org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException) IndexNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException) QueryExecutionKernelException(org.neo4j.kernel.impl.query.QueryExecutionKernelException) SchemaKernelException(org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException) KernelException(org.neo4j.exceptions.KernelException)

Example 32 with TokenPredicate

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

the class TokenIndexAccessorTest method assertReaderFindsExpected.

private static void assertReaderFindsExpected(TokenIndexReader reader, IndexOrder indexOrder, long tokenId, LongList expectedIds, ThrowingConsumer<TokenIndexReader, Exception> innerCalling) throws Exception {
    if (indexOrder.equals(IndexOrder.DESCENDING)) {
        expectedIds = expectedIds.toReversed();
    }
    try (CollectingEntityTokenClient collectingEntityTokenClient = new CollectingEntityTokenClient(tokenId)) {
        IndexQueryConstraints constraint = IndexQueryConstraints.constrained(indexOrder, false);
        TokenPredicate query = new TokenPredicate((int) tokenId);
        reader.query(collectingEntityTokenClient, constraint, query, NULL);
        // Then
        int count = 0;
        while (collectingEntityTokenClient.next()) {
            innerCalling.accept(reader);
            count++;
        }
        assertThat(count).isEqualTo(expectedIds.size());
        assertThat(collectingEntityTokenClient.actualIds).isEqualTo(expectedIds);
    }
}
Also used : TokenPredicate(org.neo4j.internal.kernel.api.TokenPredicate) IndexQueryConstraints(org.neo4j.internal.kernel.api.IndexQueryConstraints)

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