Search in sources :

Example 6 with SimpleEntityValueClient

use of org.neo4j.storageengine.api.schema.SimpleEntityValueClient in project neo4j by neo4j.

the class GenericAccessorPointsTest method exactMatchOnAllValues.

private void exactMatchOnAllValues(List<Value> values) throws IndexNotApplicableKernelException {
    try (var indexReader = accessor.newValueReader()) {
        SimpleEntityValueClient client = new SimpleEntityValueClient();
        for (Value value : values) {
            PropertyIndexQuery.ExactPredicate exact = PropertyIndexQuery.exact(descriptor.schema().getPropertyId(), value);
            indexReader.query(QueryContext.NULL_CONTEXT, client, unorderedValues(), exact);
            // then
            assertTrue(client.next());
            assertEquals(value, client.values[0]);
            assertFalse(client.next());
        }
    }
}
Also used : PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) Value(org.neo4j.values.storable.Value) PointValue(org.neo4j.values.storable.PointValue) SimpleEntityValueClient(org.neo4j.storageengine.api.schema.SimpleEntityValueClient)

Example 7 with SimpleEntityValueClient

use of org.neo4j.storageengine.api.schema.SimpleEntityValueClient in project neo4j by neo4j.

the class GenericAccessorPointsTest method shouldNotGetFalsePositivesForRangesSpanningMultipleTiles.

/**
 * Given how the spatial index works, if a point is on a tile that intersect with the search area,
 * but the point itself is outside the search area, it is a candidate for a false positive.
 * The reason is that such a point is returned from the index itself,
 * because a space index compares (and generally works with) only values of a space-filling curve
 * and not the points themselves.
 * Therefore {@link IndexReader} implementation must post-process raw index results and filter out such false positives.
 */
@Test
void shouldNotGetFalsePositivesForRangesSpanningMultipleTiles() throws IndexNotApplicableKernelException, IndexEntryConflictException {
    PointValue origin = Values.pointValue(WGS84, 0.0, 0.0);
    long derivedValueForCenterPoint = curve.derivedValueFor(origin.coordinate());
    double[] searchStart = curve.centerPointFor(derivedValueForCenterPoint);
    double xTileWidth = curve.getTileWidth(0, curve.getMaxLevel());
    // to make it easier to imagine this, the search start is a center point of one tile and the limit is a center point of the next tile on the x-axis
    PointValue limitPoint = Values.pointValue(WGS84, searchStart[0] + xTileWidth, searchStart[1]);
    int nbrOfValues = 10_000;
    List<PointValue> pointsInside = new ArrayList<>();
    List<IndexEntryUpdate<?>> updates = new ArrayList<>();
    for (int i = 0; i < nbrOfValues; i++) {
        double distanceMultiplier = random.nextDouble() * 2;
        PointValue point = Values.pointValue(WGS84, searchStart[0] + distanceMultiplier * xTileWidth, searchStart[1]);
        updates.add(IndexEntryUpdate.add(0, descriptor, point));
        if (distanceMultiplier <= 1) {
            pointsInside.add(point);
        }
    }
    processAll(updates);
    try (var indexReader = accessor.newValueReader()) {
        SimpleEntityValueClient client = new SimpleEntityValueClient();
        var range = PropertyIndexQuery.range(descriptor.schema().getPropertyId(), Values.pointValue(WGS84, searchStart), true, limitPoint, true);
        indexReader.query(QueryContext.NULL_CONTEXT, client, unorderedValues(), range);
        List<Value> queryResult = new ArrayList<>();
        while (client.next()) {
            queryResult.add(client.values[0]);
        }
        assertThat(queryResult).containsExactlyInAnyOrderElementsOf(pointsInside);
    }
}
Also used : IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) PointValue(org.neo4j.values.storable.PointValue) ArrayList(java.util.ArrayList) Value(org.neo4j.values.storable.Value) PointValue(org.neo4j.values.storable.PointValue) SimpleEntityValueClient(org.neo4j.storageengine.api.schema.SimpleEntityValueClient) Test(org.junit.jupiter.api.Test)

Example 8 with SimpleEntityValueClient

use of org.neo4j.storageengine.api.schema.SimpleEntityValueClient in project neo4j by neo4j.

the class GenericBlockBasedIndexPopulatorTest method assertHasEntry.

private static void assertHasEntry(BlockBasedIndexPopulator<GenericKey, NativeIndexValue> populator, Value entry, int expectedId) {
    try (NativeIndexReader<GenericKey, NativeIndexValue> reader = populator.newReader()) {
        SimpleEntityValueClient valueClient = new SimpleEntityValueClient();
        PropertyIndexQuery.ExactPredicate exact = PropertyIndexQuery.exact(INDEX_DESCRIPTOR.schema().getPropertyId(), entry);
        reader.query(NULL_CONTEXT, valueClient, unconstrained(), exact);
        assertTrue(valueClient.next());
        long id = valueClient.reference;
        assertEquals(expectedId, id);
    }
}
Also used : PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) SimpleEntityValueClient(org.neo4j.storageengine.api.schema.SimpleEntityValueClient)

Example 9 with SimpleEntityValueClient

use of org.neo4j.storageengine.api.schema.SimpleEntityValueClient in project neo4j by neo4j.

the class GenericBlockBasedIndexPopulatorTest method assertMatch.

private static void assertMatch(BlockBasedIndexPopulator<GenericKey, NativeIndexValue> populator, Value value, long id) {
    try (NativeIndexReader<GenericKey, NativeIndexValue> reader = populator.newReader()) {
        SimpleEntityValueClient cursor = new SimpleEntityValueClient();
        reader.query(NULL_CONTEXT, cursor, unorderedValues(), PropertyIndexQuery.exact(INDEX_DESCRIPTOR.schema().getPropertyId(), value));
        assertTrue(cursor.next());
        assertEquals(id, cursor.reference);
        assertEquals(value, cursor.values[0]);
        assertFalse(cursor.next());
    }
}
Also used : SimpleEntityValueClient(org.neo4j.storageengine.api.schema.SimpleEntityValueClient)

Example 10 with SimpleEntityValueClient

use of org.neo4j.storageengine.api.schema.SimpleEntityValueClient in project neo4j by neo4j.

the class IndexPopulationStressTest method stressIt.

@Test
void stressIt() throws Throwable {
    Race race = new Race();
    AtomicReferenceArray<List<ValueIndexEntryUpdate<?>>> lastBatches = new AtomicReferenceArray<>(THREADS);
    Generator[] generators = new Generator[THREADS];
    populator.create();
    CountDownLatch insertersDone = new CountDownLatch(THREADS);
    ReadWriteLock updateLock = new ReentrantReadWriteLock(true);
    for (int i = 0; i < THREADS; i++) {
        race.addContestant(inserter(lastBatches, generators, insertersDone, updateLock, i), 1);
    }
    Collection<ValueIndexEntryUpdate<?>> updates = new ArrayList<>();
    race.addContestant(updater(lastBatches, insertersDone, updateLock, updates));
    race.go();
    populator.close(true, NULL);
    // to let the after-method know that we've closed it ourselves
    populator = null;
    // then assert that a tree built by a single thread ends up exactly the same
    buildReferencePopulatorSingleThreaded(generators, updates);
    try (IndexAccessor accessor = indexProvider.getOnlineAccessor(descriptor, samplingConfig, tokenNameLookup);
        IndexAccessor referenceAccessor = indexProvider.getOnlineAccessor(descriptor2, samplingConfig, tokenNameLookup);
        var reader = accessor.newValueReader();
        var referenceReader = referenceAccessor.newValueReader()) {
        SimpleEntityValueClient entries = new SimpleEntityValueClient();
        SimpleEntityValueClient referenceEntries = new SimpleEntityValueClient();
        reader.query(NULL_CONTEXT, entries, unordered(hasValues), PropertyIndexQuery.exists(0));
        referenceReader.query(NULL_CONTEXT, referenceEntries, unordered(hasValues), PropertyIndexQuery.exists(0));
        while (referenceEntries.next()) {
            assertTrue(entries.next());
            assertEquals(referenceEntries.reference, entries.reference);
            if (hasValues) {
                assertEquals(ValueTuple.of(referenceEntries.values), ValueTuple.of(entries.values));
            }
        }
        assertFalse(entries.next());
    }
}
Also used : IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Race(org.neo4j.test.Race) AtomicReferenceArray(java.util.concurrent.atomic.AtomicReferenceArray) List(java.util.List) ArrayList(java.util.ArrayList) SimpleEntityValueClient(org.neo4j.storageengine.api.schema.SimpleEntityValueClient) Test(org.junit.jupiter.api.Test)

Aggregations

SimpleEntityValueClient (org.neo4j.storageengine.api.schema.SimpleEntityValueClient)12 PropertyIndexQuery (org.neo4j.internal.kernel.api.PropertyIndexQuery)8 PointValue (org.neo4j.values.storable.PointValue)6 Value (org.neo4j.values.storable.Value)6 ArrayList (java.util.ArrayList)5 List (java.util.List)4 Test (org.junit.jupiter.api.Test)4 IndexOrder (org.neo4j.internal.schema.IndexOrder)4 IndexOrderCapability (org.neo4j.internal.schema.IndexOrderCapability)4 ValueIndexEntryUpdate (org.neo4j.storageengine.api.ValueIndexEntryUpdate)4 Arrays (java.util.Arrays)3 Collections (java.util.Collections)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 String.format (java.lang.String.format)2 Collection (java.util.Collection)2 Iterator (java.util.Iterator)2 Predicate (java.util.function.Predicate)2