Search in sources :

Example 41 with MutableLongSet

use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.

the class EntityValueIndexCursorTestBase method shouldPerformStringContainmentSearch.

@Test
void shouldPerformStringContainmentSearch() throws Exception {
    // given
    boolean needsValues = indexParams.indexProvidesStringValues();
    int prop = token.propertyKey(PROP_NAME);
    IndexReadSession index = read.indexReadSession(schemaRead.indexGetForName(PROP_INDEX_NAME));
    IndexValueCapability stringCapability = index.reference().getCapability().valueCapability(ValueCategory.TEXT);
    try (var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
        MutableLongSet uniqueIds = new LongHashSet();
        // when
        entityParams.entityIndexSeek(tx, index, cursor, unordered(needsValues), PropertyIndexQuery.stringContains(prop, stringValue("o")));
        // then
        assertThat(cursor.numberOfProperties()).isEqualTo(1);
        assertFoundEntitiesAndValue(cursor, uniqueIds, stringCapability, needsValues, strOne, strTwo1, strTwo2);
    }
}
Also used : LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) IndexValueCapability(org.neo4j.internal.schema.IndexValueCapability) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Example 42 with MutableLongSet

use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.

the class EntityValueIndexCursorTestBase method shouldNotFindDeletedEntityInIndexScan.

@Test
void shouldNotFindDeletedEntityInIndexScan() throws Exception {
    // Given
    boolean needsValues = indexParams.indexProvidesAllValues();
    IndexReadSession index = read.indexReadSession(schemaRead.indexGetForName(PROP_INDEX_NAME));
    IndexValueCapability wildcardCapability = index.reference().getCapability().valueCapability(ValueCategory.UNKNOWN);
    try (KernelTransaction tx = beginTransaction();
        var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
        MutableLongSet uniqueIds = new LongHashSet();
        // when
        entityParams.entityIndexScan(tx, index, cursor, unordered(needsValues));
        assertThat(cursor.numberOfProperties()).isEqualTo(1);
        assertFoundEntitiesAndValue(cursor, TOTAL_ENTITY_COUNT, uniqueIds, wildcardCapability, needsValues);
        // then
        entityParams.entityDelete(tx, strOne);
        entityParams.entityIndexScan(tx, index, cursor, unordered(needsValues));
        assertFoundEntitiesAndValue(cursor, TOTAL_ENTITY_COUNT - 1, uniqueIds, wildcardCapability, needsValues);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) IndexValueCapability(org.neo4j.internal.schema.IndexValueCapability) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Example 43 with MutableLongSet

use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.

the class EntityValueIndexCursorTestBase method shouldPerformIndexScan.

@Test
void shouldPerformIndexScan() throws Exception {
    // given
    IndexReadSession index = read.indexReadSession(schemaRead.indexGetForName(PROP_INDEX_NAME));
    IndexValueCapability wildcardCapability = index.reference().getCapability().valueCapability(ValueCategory.UNKNOWN);
    try (var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
        MutableLongSet uniqueIds = new LongHashSet();
        // when
        entityParams.entityIndexScan(tx, index, cursor, unordered(indexParams.indexProvidesAllValues()));
        // then
        assertThat(cursor.numberOfProperties()).isEqualTo(1);
        assertFoundEntitiesAndValue(cursor, TOTAL_ENTITY_COUNT, uniqueIds, wildcardCapability, indexParams.indexProvidesAllValues());
    }
}
Also used : LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) IndexValueCapability(org.neo4j.internal.schema.IndexValueCapability) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Example 44 with MutableLongSet

use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.

the class TxStateIndexChanges method indexUpdatesWithValuesScanAndFilter.

private static AddedWithValuesAndRemoved indexUpdatesWithValuesScanAndFilter(ReadableTransactionState txState, IndexDescriptor descriptor, PropertyIndexQuery filter, IndexOrder indexOrder) {
    Map<ValueTuple, ? extends LongDiffSets> updates = getUpdates(txState, descriptor, indexOrder);
    if (updates == null) {
        return EMPTY_ADDED_AND_REMOVED_WITH_VALUES;
    }
    MutableList<EntityWithPropertyValues> added = Lists.mutable.empty();
    MutableLongSet removed = LongSets.mutable.empty();
    for (Map.Entry<ValueTuple, ? extends LongDiffSets> entry : updates.entrySet()) {
        ValueTuple key = entry.getKey();
        if (filter == null || filter.acceptsValue(key.valueAt(0))) {
            Value[] values = key.getValues();
            LongDiffSets diffSet = entry.getValue();
            diffSet.getAdded().each(nodeId -> added.add(new EntityWithPropertyValues(nodeId, values)));
            removed.addAll(diffSet.getRemoved());
        }
    }
    return new AddedWithValuesAndRemoved(indexOrder == IndexOrder.DESCENDING ? added.asReversed() : added, removed);
}
Also used : MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) ValueTuple(org.neo4j.values.storable.ValueTuple) Value(org.neo4j.values.storable.Value) TextValue(org.neo4j.values.storable.TextValue) NavigableMap(java.util.NavigableMap) Map(java.util.Map) UnmodifiableMap(org.eclipse.collections.impl.UnmodifiableMap) LongDiffSets(org.neo4j.storageengine.api.txstate.LongDiffSets)

Example 45 with MutableLongSet

use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.

the class TxStateIndexChanges method indexUpdatesWithValuesForRangeSeek.

static AddedWithValuesAndRemoved indexUpdatesWithValuesForRangeSeek(ReadableTransactionState txState, IndexDescriptor descriptor, Value[] equalityPrefix, PropertyIndexQuery.RangePredicate<?> predicate, IndexOrder indexOrder) {
    NavigableMap<ValueTuple, ? extends LongDiffSets> sortedUpdates = txState.getSortedIndexUpdates(descriptor.schema());
    if (sortedUpdates == null) {
        return EMPTY_ADDED_AND_REMOVED_WITH_VALUES;
    }
    int size = descriptor.schema().getPropertyIds().length;
    RangeFilterValues rangeFilter = predicate == null ? RangeFilterValues.fromExists(size, equalityPrefix) : RangeFilterValues.fromRange(size, equalityPrefix, predicate);
    MutableList<EntityWithPropertyValues> added = Lists.mutable.empty();
    MutableLongSet removed = LongSets.mutable.empty();
    Map<ValueTuple, ? extends LongDiffSets> inRange = sortedUpdates.subMap(rangeFilter.lower, true, rangeFilter.upper, true);
    for (Map.Entry<ValueTuple, ? extends LongDiffSets> entry : inRange.entrySet()) {
        ValueTuple values = entry.getKey();
        Value rangeKey = values.valueAt(equalityPrefix.length);
        Value[] valuesArray = values.getValues();
        LongDiffSets diffForSpecificValue = entry.getValue();
        // Needs to manually filter for if lower or upper should be included
        // since we only wants to compare the first value of the key and not all of them for composite indexes
        boolean allowed = rangeFilter.allowedEntry(rangeKey, equalityPrefix.length);
        // The TreeMap cannot perfectly order multi-dimensional types (spatial) and need additional filtering out false positives
        if (allowed && (predicate == null || predicate.isRegularOrder() || predicate.acceptsValue(rangeKey))) {
            diffForSpecificValue.getAdded().each(nodeId -> added.add(new EntityWithPropertyValues(nodeId, valuesArray)));
            removed.addAll(diffForSpecificValue.getRemoved());
        }
    }
    return new AddedWithValuesAndRemoved(indexOrder == IndexOrder.DESCENDING ? added.asReversed() : added, removed);
}
Also used : MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) ValueTuple(org.neo4j.values.storable.ValueTuple) Value(org.neo4j.values.storable.Value) TextValue(org.neo4j.values.storable.TextValue) NavigableMap(java.util.NavigableMap) Map(java.util.Map) UnmodifiableMap(org.eclipse.collections.impl.UnmodifiableMap) LongDiffSets(org.neo4j.storageengine.api.txstate.LongDiffSets)

Aggregations

MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)153 LongHashSet (org.eclipse.collections.impl.set.mutable.primitive.LongHashSet)57 Test (org.junit.jupiter.api.Test)54 Test (org.junit.Test)49 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)17 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)17 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)14 ArrayList (java.util.ArrayList)13 IndexValueCapability (org.neo4j.internal.schema.IndexValueCapability)12 LongIterator (org.eclipse.collections.api.iterator.LongIterator)10 LongSet (org.eclipse.collections.api.set.primitive.LongSet)9 Value (org.neo4j.values.storable.Value)8 Map (java.util.Map)7 MutableLongList (org.eclipse.collections.api.list.primitive.MutableLongList)7 Transaction (org.neo4j.graphdb.Transaction)7 Write (org.neo4j.internal.kernel.api.Write)7 NavigableMap (java.util.NavigableMap)6 UnmodifiableMap (org.eclipse.collections.impl.UnmodifiableMap)6 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)6 IndexQueryConstraints (org.neo4j.internal.kernel.api.IndexQueryConstraints)6