Search in sources :

Example 1 with TokenPredicate

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

the class Operations method enforceNodeKeyConstraint.

private void enforceNodeKeyConstraint(SchemaDescriptor schema) throws KernelException {
    IndexDescriptor index = allStoreHolder.findUsableTokenIndex(NODE);
    if (index != IndexDescriptor.NO_INDEX) {
        try (var cursor = cursors.allocateFullAccessNodeLabelIndexCursor(ktx.cursorContext())) {
            var session = allStoreHolder.tokenReadSession(index);
            allStoreHolder.nodeLabelScan(session, cursor, unconstrained(), new TokenPredicate(schema.getLabelId()));
            constraintSemantics.validateNodeKeyConstraint(cursor, nodeCursor, propertyCursor, schema.asLabelSchemaDescriptor(), token);
        }
    } else {
        try (var cursor = cursors.allocateFullAccessNodeCursor(ktx.cursorContext())) {
            allStoreHolder.allNodesScan(cursor);
            constraintSemantics.validateNodeKeyConstraint(new FilteringNodeCursorWrapper(cursor, CursorPredicates.hasLabel(schema.getLabelId())), propertyCursor, schema.asLabelSchemaDescriptor(), token);
        }
    }
}
Also used : TokenPredicate(org.neo4j.internal.kernel.api.TokenPredicate) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor)

Example 2 with TokenPredicate

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

the class Operations method enforceRelationshipPropertyExistenceConstraint.

private void enforceRelationshipPropertyExistenceConstraint(RelationTypeSchemaDescriptor schema) throws KernelException {
    var index = allStoreHolder.findUsableTokenIndex(RELATIONSHIP);
    if (index != IndexDescriptor.NO_INDEX) {
        try (var fullAccessIndexCursor = cursors.allocateFullAccessRelationshipTypeIndexCursor();
            var fullAccessCursor = cursors.allocateFullAccessRelationshipScanCursor(ktx.cursorContext())) {
            var session = allStoreHolder.tokenReadSession(index);
            allStoreHolder.relationshipTypeScan(session, fullAccessIndexCursor, unconstrained(), new TokenPredicate(schema.getRelTypeId()));
            constraintSemantics.validateRelationshipPropertyExistenceConstraint(fullAccessIndexCursor, fullAccessCursor, propertyCursor, schema, token);
        }
    } else {
        // fallback to all relationship scan
        try (var fullAccessCursor = cursors.allocateFullAccessRelationshipScanCursor(ktx.cursorContext())) {
            allStoreHolder.allRelationshipsScan(fullAccessCursor);
            constraintSemantics.validateRelationshipPropertyExistenceConstraint(new FilteringRelationshipScanCursorWrapper(fullAccessCursor, CursorPredicates.hasType(schema.getRelTypeId())), propertyCursor, schema, token);
        }
    }
}
Also used : TokenPredicate(org.neo4j.internal.kernel.api.TokenPredicate)

Example 3 with TokenPredicate

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

the class DefaultTokenIndexReaderTest method shouldFindMultipleWithProgressorAscending.

@Test
void shouldFindMultipleWithProgressorAscending() {
    // WHEN
    var reader = new DefaultTokenIndexReader(index);
    SimpleEntityTokenClient tokenClient = new SimpleEntityTokenClient();
    reader.query(tokenClient, IndexQueryConstraints.constrained(IndexOrder.ASCENDING, false), new TokenPredicate(LABEL_ID), NULL);
    // THEN
    assertArrayEquals(expected, asArray(tokenClient));
}
Also used : TokenPredicate(org.neo4j.internal.kernel.api.TokenPredicate) SimpleEntityTokenClient(org.neo4j.storageengine.api.schema.SimpleEntityTokenClient) Test(org.junit.jupiter.api.Test)

Example 4 with TokenPredicate

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

the class RelationshipTypeIndexIT method assertContainIds.

private void assertContainIds(List<Long> expectedIds) throws IndexNotFoundKernelException {
    int relationshipTypeId = getRelationshipTypeId();
    IndexProxy indexProxy = getIndexProxy();
    List<Long> actualIds = new ArrayList<>();
    try (TokenIndexReader reader = indexProxy.newTokenReader()) {
        SimpleEntityTokenClient tokenClient = new SimpleEntityTokenClient();
        reader.query(tokenClient, unconstrained(), new TokenPredicate(relationshipTypeId), CursorContext.NULL);
        while (tokenClient.next()) {
            actualIds.add(tokenClient.reference);
        }
    }
    expectedIds.sort(Long::compareTo);
    actualIds.sort(Long::compareTo);
    assertThat(actualIds).as("contains expected relationships").isEqualTo(expectedIds);
}
Also used : TokenPredicate(org.neo4j.internal.kernel.api.TokenPredicate) ArrayList(java.util.ArrayList) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) SimpleEntityTokenClient(org.neo4j.storageengine.api.schema.SimpleEntityTokenClient) TokenIndexReader(org.neo4j.kernel.api.index.TokenIndexReader)

Example 5 with TokenPredicate

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

the class KernelAPIParallelLabelScanStressIT method labelScan.

private Runnable labelScan(Read read, NodeLabelIndexCursor cursor, IndexDescriptor index, int label) {
    return throwing(() -> {
        var tokenReadSession = read.tokenReadSession(index);
        read.nodeLabelScan(tokenReadSession, cursor, unconstrained(), new TokenPredicate(label));
        int n = 0;
        while (cursor.next()) {
            n++;
        }
        assertEquals(N_NODES, n, "correct number of nodes");
    });
}
Also used : TokenPredicate(org.neo4j.internal.kernel.api.TokenPredicate)

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