Search in sources :

Example 1 with NodeValueIterator

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);
    }
}
Also used : NodeValueIterator(org.neo4j.kernel.impl.index.schema.NodeValueIterator) IndexNotApplicableKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException)

Example 2 with NodeValueIterator

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);
        }
    }
}
Also used : NodeValueIterator(org.neo4j.kernel.impl.index.schema.NodeValueIterator) NodeIdsIndexReaderQueryAnswer(org.neo4j.kernel.impl.index.schema.NodeIdsIndexReaderQueryAnswer) PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) LongSet(org.eclipse.collections.api.set.primitive.LongSet) Test(org.junit.jupiter.api.Test)

Example 3 with NodeValueIterator

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));
    }
}
Also used : NodeValueIterator(org.neo4j.kernel.impl.index.schema.NodeValueIterator) IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) Test(org.junit.jupiter.api.Test)

Example 4 with NodeValueIterator

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));
        }
    }
}
Also used : NodeValueIterator(org.neo4j.kernel.impl.index.schema.NodeValueIterator) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.IndexSamplingConfig) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) Value(org.neo4j.values.storable.Value) Values.stringValue(org.neo4j.values.storable.Values.stringValue) Test(org.junit.Test)

Example 5 with NodeValueIterator

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());
                }
            }
        }
    }
}
Also used : NodeValueIterator(org.neo4j.kernel.impl.index.schema.NodeValueIterator)

Aggregations

NodeValueIterator (org.neo4j.kernel.impl.index.schema.NodeValueIterator)11 Test (org.junit.jupiter.api.Test)4 Test (org.junit.Test)3 IndexEntryUpdate (org.neo4j.storageengine.api.IndexEntryUpdate)2 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 StringJoiner (java.util.StringJoiner)1 LongSet (org.eclipse.collections.api.set.primitive.LongSet)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 ValueSource (org.junit.jupiter.params.provider.ValueSource)1 PropertyIndexQuery (org.neo4j.internal.kernel.api.PropertyIndexQuery)1 IndexNotApplicableKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException)1 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)1 LuceneIndexAccessor (org.neo4j.kernel.api.impl.schema.LuceneIndexAccessor)1 SchemaIndex (org.neo4j.kernel.api.impl.schema.SchemaIndex)1 IndexProgressor (org.neo4j.kernel.api.index.IndexProgressor)1 IndexSample (org.neo4j.kernel.api.index.IndexSample)1 IndexSampler (org.neo4j.kernel.api.index.IndexSampler)1 ValueIndexReader (org.neo4j.kernel.api.index.ValueIndexReader)1 IndexSamplingConfig (org.neo4j.kernel.impl.api.index.IndexSamplingConfig)1