use of org.neo4j.internal.kernel.api.TokenPredicate in project neo4j by neo4j.
the class DefaultPooledCursorsTestBase method shouldReuseNodeLabelIndexCursor.
@Test
void shouldReuseNodeLabelIndexCursor() throws Exception {
try (KernelTransaction tx = beginTransaction()) {
NodeLabelIndexCursor c1 = tx.cursors().allocateNodeLabelIndexCursor(NULL);
tx.dataRead().nodeLabelScan(getTokenReadSession(tx, EntityType.NODE), c1, IndexQueryConstraints.unconstrained(), new TokenPredicate(1));
c1.close();
NodeLabelIndexCursor c2 = tx.cursors().allocateNodeLabelIndexCursor(NULL);
assertThat(c1).isSameAs(c2);
c2.close();
}
}
use of org.neo4j.internal.kernel.api.TokenPredicate in project neo4j by neo4j.
the class TransactionImpl method getNodesByLabelAndPropertyWithoutPropertyIndex.
private ResourceIterator<Node> getNodesByLabelAndPropertyWithoutPropertyIndex(KernelTransaction ktx, int labelId, PropertyIndexQuery... queries) {
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));
var nodeCursor = ktx.cursors().allocateNodeCursor(ktx.cursorContext());
var propertyCursor = ktx.cursors().allocatePropertyCursor(ktx.cursorContext(), ktx.memoryTracker());
return new NodeLabelPropertyIterator(ktx.dataRead(), cursor, nodeCursor, propertyCursor, c -> newNodeEntity(c.nodeReference()), coreApiResourceTracker, queries);
} catch (KernelException e) {
// ignore, fallback to all node scan
}
}
return getNodesByLabelAndPropertyViaAllNodesScan(ktx, labelId, queries);
}
use of org.neo4j.internal.kernel.api.TokenPredicate in project neo4j by neo4j.
the class RelationshipIndexedRelationshipStoreScanTest method mockIdsReturnedFromTokenQueries.
private void mockIdsReturnedFromTokenQueries() {
// Make token index reader return different ids for the different tokens
doAnswer(invocation -> {
IndexProgressor.EntityTokenClient client = invocation.getArgument(0);
TokenPredicate token = invocation.getArgument(2);
client.initialize(new IndexProgressor() {
private final PrimitiveIterator.OfLong relationshipsWithType1 = Arrays.stream(new long[] { 1, 2, 4, 8 }).iterator();
private final PrimitiveIterator.OfLong relationshipsWithType2 = Arrays.stream(new long[] { 2, 5, 6 }).iterator();
@Override
public boolean next() {
PrimitiveIterator.OfLong relationshipsWithType = relationshipsWithType1;
if (token.tokenId() == 2) {
relationshipsWithType = relationshipsWithType2;
}
if (relationshipsWithType.hasNext()) {
client.acceptEntity(relationshipsWithType.nextLong(), null);
return true;
}
return false;
}
@Override
public void close() {
}
}, token.tokenId(), IndexOrder.NONE);
return null;
}).when(relationshipTypeScanReader).query(any(), any(), any(), any(), any());
}
use of org.neo4j.internal.kernel.api.TokenPredicate in project neo4j by neo4j.
the class NodeLabelTokenIndexCursorTest method shouldFindNodesByLabel.
@Test
void shouldFindNodesByLabel() throws Exception {
long toDelete;
try (KernelTransaction tx = beginTransaction()) {
createNode(tx.dataWrite(), labelOne, labelFirst);
createNode(tx.dataWrite(), labelTwo, labelFirst);
createNode(tx.dataWrite(), labelThree, labelFirst);
toDelete = createNode(tx.dataWrite(), labelOne);
createNode(tx.dataWrite(), labelTwo);
createNode(tx.dataWrite(), labelThree);
createNode(tx.dataWrite(), labelThree);
tx.commit();
}
try (KernelTransaction tx = beginTransaction()) {
tx.dataWrite().nodeDelete(toDelete);
tx.commit();
}
try (KernelTransaction tx = beginTransaction()) {
org.neo4j.internal.kernel.api.Read read = tx.dataRead();
var session = getTokenReadSession(tx);
try (NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor(tx.cursorContext())) {
MutableLongSet uniqueIds = new LongHashSet();
// WHEN
read.nodeLabelScan(session, cursor, IndexQueryConstraints.unconstrained(), new TokenPredicate(labelOne));
// THEN
assertNodeCount(cursor, 1, uniqueIds);
// WHEN
read.nodeLabelScan(session, cursor, IndexQueryConstraints.unconstrained(), new TokenPredicate(labelTwo));
// THEN
assertNodeCount(cursor, 2, uniqueIds);
// WHEN
read.nodeLabelScan(session, cursor, IndexQueryConstraints.unconstrained(), new TokenPredicate(labelThree));
// THEN
assertNodeCount(cursor, 3, uniqueIds);
// WHEN
uniqueIds.clear();
read.nodeLabelScan(session, cursor, IndexQueryConstraints.unconstrained(), new TokenPredicate(labelFirst));
// THEN
assertNodeCount(cursor, 3, uniqueIds);
}
}
}
use of org.neo4j.internal.kernel.api.TokenPredicate in project neo4j by neo4j.
the class KernelReadTracerTest method shouldTraceRelationshipTypeScan.
@Test
void shouldTraceRelationshipTypeScan() throws KernelException {
// given
TestKernelReadTracer tracer = new TestKernelReadTracer();
int hasId = token.relationshipTypeGetOrCreateForName("HAS");
List<TraceEvent> expectedEvents = new ArrayList<>();
expectedEvents.add(OnRelationshipTypeScan(hasId));
try (RelationshipTypeIndexCursor cursor = cursors.allocateRelationshipTypeIndexCursor(NULL)) {
// when
cursor.setTracer(tracer);
read.relationshipTypeScan(getTokenReadSession(tx, EntityType.RELATIONSHIP), cursor, IndexQueryConstraints.unconstrained(), new TokenPredicate(hasId));
while (cursor.next()) {
expectedEvents.add(OnRelationship(cursor.relationshipReference()));
}
}
// then
tracer.assertEvents(expectedEvents);
}
Aggregations