Search in sources :

Example 26 with TokenPredicate

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

the class NodeTransactionStateTestBase method shouldNotFindNodeWithRemovedLabelInLabelScan.

@Test
void shouldNotFindNodeWithRemovedLabelInLabelScan() throws Exception {
    // Given
    Node node = createNode("label");
    try (KernelTransaction tx = beginTransaction();
        NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor(tx.cursorContext())) {
        // when
        tx.dataWrite().nodeRemoveLabel(node.node, node.labels[0]);
        tx.dataRead().nodeLabelScan(getTokenReadSession(tx, EntityType.NODE), cursor, IndexQueryConstraints.unconstrained(), new TokenPredicate(node.labels[0]));
        // then
        assertFalse(cursor.next());
    }
}
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 27 with TokenPredicate

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

the class NodeTransactionStateTestBase method shouldFindSwappedNodeInLabelScan.

@Test
void shouldFindSwappedNodeInLabelScan() throws Exception {
    // Given
    Node node1 = createNode("label");
    Node node2 = createNode();
    try (KernelTransaction tx = beginTransaction();
        NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor(tx.cursorContext())) {
        // when
        tx.dataWrite().nodeRemoveLabel(node1.node, node1.labels[0]);
        tx.dataWrite().nodeAddLabel(node2.node, node1.labels[0]);
        tx.dataRead().nodeLabelScan(getTokenReadSession(tx, EntityType.NODE), cursor, IndexQueryConstraints.unconstrained(), new TokenPredicate(node1.labels[0]));
        // then
        assertTrue(cursor.next());
        assertEquals(node2.node, cursor.nodeReference());
    }
}
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 28 with TokenPredicate

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

the class Operations method enforceNodePropertyExistenceConstraint.

private void enforceNodePropertyExistenceConstraint(LabelSchemaDescriptor 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.validateNodePropertyExistenceConstraint(cursor, nodeCursor, propertyCursor, schema.asLabelSchemaDescriptor(), token);
        }
    } else {
        try (var cursor = cursors.allocateFullAccessNodeCursor(ktx.cursorContext())) {
            allStoreHolder.allNodesScan(cursor);
            constraintSemantics.validateNodePropertyExistenceConstraint(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 29 with TokenPredicate

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

the class DefaultTokenIndexReaderTest method shouldFindMultipleEntitiesInEachRange.

@Test
void shouldFindMultipleEntitiesInEachRange() {
    // WHEN
    var reader = new DefaultTokenIndexReader(index);
    SimpleEntityTokenClient tokenClient = new SimpleEntityTokenClient();
    reader.query(tokenClient, unconstrained(), 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 30 with TokenPredicate

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

the class DefaultTokenIndexReaderTest method shouldFindMultipleWithProgressorDescending.

@Test
void shouldFindMultipleWithProgressorDescending() {
    // WHEN
    var reader = new DefaultTokenIndexReader(index);
    SimpleEntityTokenClient tokenClient = new SimpleEntityTokenClient();
    reader.query(tokenClient, IndexQueryConstraints.constrained(IndexOrder.DESCENDING, false), new TokenPredicate(LABEL_ID), NULL);
    // THEN
    ArrayUtils.reverse(expected);
    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)

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