use of org.neo4j.kernel.impl.index.schema.NodeValueIterator in project neo4j by neo4j.
the class SchemaComplianceChecker method queryIndexOrEmpty.
private static LongIterator queryIndexOrEmpty(ValueIndexReader reader, PropertyIndexQuery[] query) {
try {
NodeValueIterator indexedNodeIds = new NodeValueIterator();
reader.query(NULL_CONTEXT, indexedNodeIds, unconstrained(), query);
return indexedNodeIds;
} catch (IndexNotApplicableKernelException e) {
throw new RuntimeException(format("Consistency checking error: index provider does not support exact query %s", Arrays.toString(query)), e);
}
}
use of org.neo4j.kernel.impl.index.schema.NodeValueIterator in project neo4j by neo4j.
the class FusionIndexReaderTest method mustCombineResultFromExistsPredicate.
@Test
void mustCombineResultFromExistsPredicate() throws Exception {
// given
PropertyIndexQuery.ExistsPredicate exists = PropertyIndexQuery.exists(PROP_KEY);
long lastId = 0;
for (var aliveReader : aliveReaders) {
doAnswer(new NodeIdsIndexReaderQueryAnswer(DESCRIPTOR, lastId++, lastId++)).when(aliveReader).query(any(), any(), any(), any());
}
// when
LongSet resultSet;
try (NodeValueIterator result = new NodeValueIterator()) {
fusionIndexReader.query(NULL_CONTEXT, result, unconstrained(), exists);
// then
resultSet = PrimitiveLongCollections.asSet(result);
for (long i = 0L; i < lastId; i++) {
assertTrue(resultSet.contains(i), "Expected to contain " + i + ", but was " + resultSet);
}
}
}
use of org.neo4j.kernel.impl.index.schema.NodeValueIterator in project neo4j by neo4j.
the class UniqueDatabaseIndexPopulatorTest method addUpdates.
@Test
void addUpdates() throws Exception {
populator = newPopulator();
List<IndexEntryUpdate<?>> updates = Arrays.asList(add(1, schemaDescriptor, "aaa"), add(2, schemaDescriptor, "bbb"), add(3, schemaDescriptor, "ccc"));
populator.add(updates, NULL);
index.maybeRefreshBlocking();
try (var reader = index.getIndexReader();
NodeValueIterator allEntities = new NodeValueIterator()) {
reader.query(NULL_CONTEXT, allEntities, unconstrained(), PropertyIndexQuery.exists(1));
assertArrayEquals(new long[] { 1, 2, 3 }, PrimitiveLongCollections.asArray(allEntities));
}
}
use of org.neo4j.kernel.impl.index.schema.NodeValueIterator in project neo4j by neo4j.
the class SimpleIndexPopulatorCompatibility method shouldApplyUpdatesIdempotently.
@Test
public void shouldApplyUpdatesIdempotently() throws Exception {
// GIVEN
IndexSamplingConfig indexSamplingConfig = new IndexSamplingConfig(Config.defaults());
final Value propertyValue = Values.of("value1");
withPopulator(indexProvider.getPopulator(descriptor, indexSamplingConfig, heapBufferFactory(1024), INSTANCE, tokenNameLookup), p -> {
long nodeId = 1;
// update using populator...
IndexEntryUpdate<SchemaDescriptor> update = add(nodeId, descriptor.schema(), propertyValue);
p.add(singletonList(update), NULL);
// ...is the same as update using updater
try (IndexUpdater updater = p.newPopulatingUpdater((node, propertyId, cursorContext) -> propertyValue, NULL)) {
updater.process(update);
}
});
// THEN
try (IndexAccessor accessor = indexProvider.getOnlineAccessor(descriptor, indexSamplingConfig, tokenNameLookup)) {
try (ValueIndexReader reader = accessor.newValueReader();
NodeValueIterator nodes = new NodeValueIterator()) {
int propertyKeyId = descriptor.schema().getPropertyId();
reader.query(NULL_CONTEXT, nodes, unconstrained(), PropertyIndexQuery.exact(propertyKeyId, propertyValue));
assertEquals(asSet(1L), PrimitiveLongCollections.toSet(nodes));
}
}
}
use of org.neo4j.kernel.impl.index.schema.NodeValueIterator in project neo4j by neo4j.
the class SimpleIndexPopulatorCompatibility method assertHasAllValues.
private void assertHasAllValues(List<NodeAndValue> values) throws IOException, IndexNotApplicableKernelException {
try (IndexAccessor accessor = indexProvider.getOnlineAccessor(descriptor, indexSamplingConfig, tokenNameLookup)) {
try (ValueIndexReader reader = accessor.newValueReader()) {
int propertyKeyId = descriptor.schema().getPropertyId();
for (NodeAndValue entry : values) {
try (NodeValueIterator nodes = new NodeValueIterator()) {
reader.query(NULL_CONTEXT, nodes, unconstrained(), PropertyIndexQuery.exact(propertyKeyId, entry.value));
assertEquals(entry.nodeId, nodes.next());
assertFalse(nodes.hasNext());
}
}
}
}
}
Aggregations