Search in sources :

Example 1 with ValueTuple

use of org.neo4j.values.storable.ValueTuple 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 2 with ValueTuple

use of org.neo4j.values.storable.ValueTuple 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)

Example 3 with ValueTuple

use of org.neo4j.values.storable.ValueTuple in project neo4j by neo4j.

the class TxStateIndexChanges method indexUpdatesForRangeSeekByPrefix.

// PREFIX
static AddedAndRemoved indexUpdatesForRangeSeekByPrefix(ReadableTransactionState txState, IndexDescriptor descriptor, Value[] equalityPrefix, TextValue prefix, IndexOrder indexOrder) {
    NavigableMap<ValueTuple, ? extends LongDiffSets> sortedUpdates = txState.getSortedIndexUpdates(descriptor.schema());
    if (sortedUpdates == null) {
        return EMPTY_ADDED_AND_REMOVED;
    }
    int size = descriptor.schema().getPropertyIds().length;
    ValueTuple floor = getCompositeValueTuple(size, equalityPrefix, prefix, true);
    ValueTuple maxString = getCompositeValueTuple(size, equalityPrefix, Values.MAX_STRING, false);
    MutableLongList added = LongLists.mutable.empty();
    MutableLongSet removed = LongSets.mutable.empty();
    for (Map.Entry<ValueTuple, ? extends LongDiffSets> entry : sortedUpdates.subMap(floor, maxString).entrySet()) {
        Value key = entry.getKey().valueAt(equalityPrefix.length);
        // Needs to check type since the subMap might include non-TextValue for composite index
        if (key.valueGroup() == ValueGroup.TEXT && ((TextValue) key).startsWith(prefix)) {
            LongDiffSets diffSets = entry.getValue();
            added.addAll(diffSets.getAdded());
            removed.addAll(diffSets.getRemoved());
        } else {
            break;
        }
    }
    return new AddedAndRemoved(indexOrder == IndexOrder.DESCENDING ? added.asReversed() : added, removed);
}
Also used : MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) 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 4 with ValueTuple

use of org.neo4j.values.storable.ValueTuple in project neo4j by neo4j.

the class TxStateTest method shouldComputeSortedIndexUpdatesOnTxStateWithAddedNodes.

@Test
void shouldComputeSortedIndexUpdatesOnTxStateWithAddedNodes() {
    // GIVEN
    addNodesToIndex(indexOn_1_1).withDefaultStringProperties(42L);
    addNodesToIndex(indexOn_1_1).withDefaultStringProperties(43L);
    addNodesToIndex(indexOn_1_1).withDefaultStringProperties(41L);
    // WHEN
    NavigableMap<ValueTuple, ? extends LongDiffSets> diffSets = state.getSortedIndexUpdates(indexOn_1_1.schema());
    TreeMap<ValueTuple, LongDiffSets> expected = sortedAddedNodesDiffSets(42, 41, 43);
    // THEN
    assertNotNull(diffSets);
    assertEquals(expected.keySet(), diffSets.keySet());
    for (final ValueTuple key : expected.keySet()) {
        assertEqualDiffSets(expected.get(key), diffSets.get(key));
    }
}
Also used : ValueTuple(org.neo4j.values.storable.ValueTuple) MutableLongDiffSets(org.neo4j.kernel.impl.util.diffsets.MutableLongDiffSets) LongDiffSets(org.neo4j.storageengine.api.txstate.LongDiffSets) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 5 with ValueTuple

use of org.neo4j.values.storable.ValueTuple in project neo4j by neo4j.

the class IndexTxStateUpdater method onDeleteUncreated.

// PROPERTY CHANGES
/**
 * Creating an entity with its data in a transaction adds also adds that state to index transaction state (for matching indexes).
 * When deleting an entity this method will delete this state from the index transaction state.
 *
 * @param entity entity that was deleted.
 * @param propertyCursor property cursor for accessing the properties of the entity.
 * @param tokens the entity tokens this entity has.
 */
private void onDeleteUncreated(EntityCursor entity, PropertyCursor propertyCursor, long[] tokens) {
    assert noSchemaChangedInTx();
    entity.properties(propertyCursor);
    MutableIntList propertyKeyList = IntLists.mutable.empty();
    while (propertyCursor.next()) {
        propertyKeyList.add(propertyCursor.propertyKey());
    }
    // Make sure to sort the propertyKeyIds since SchemaMatcher.onMatchingSchema requires it.
    int[] propertyKeyIds = propertyKeyList.toSortedArray();
    Collection<IndexDescriptor> indexes = storageReader.valueIndexesGetRelated(tokens, propertyKeyIds, entity.entityType());
    if (!indexes.isEmpty()) {
        MutableIntObjectMap<Value> materializedProperties = IntObjectMaps.mutable.empty();
        SchemaMatcher.onMatchingSchema(indexes.iterator(), ANY_PROPERTY_KEY, propertyKeyIds, index -> {
            MemoryTracker memoryTracker = read.txState().memoryTracker();
            SchemaDescriptor schema = index.schema();
            Value[] values = getValueTuple(entity, propertyCursor, ANY_PROPERTY_KEY, NO_VALUE, schema.getPropertyIds(), materializedProperties, memoryTracker);
            ValueTuple valueTuple = ValueTuple.of(values);
            memoryTracker.allocateHeap(valueTuple.getShallowSize());
            read.txState().indexDoUpdateEntry(schema, entity.reference(), valueTuple, null);
        });
    }
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) MutableIntList(org.eclipse.collections.api.list.primitive.MutableIntList) ValueTuple(org.neo4j.values.storable.ValueTuple) Value(org.neo4j.values.storable.Value) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) MemoryTracker(org.neo4j.memory.MemoryTracker)

Aggregations

ValueTuple (org.neo4j.values.storable.ValueTuple)16 Value (org.neo4j.values.storable.Value)11 LongDiffSets (org.neo4j.storageengine.api.txstate.LongDiffSets)8 Map (java.util.Map)7 NavigableMap (java.util.NavigableMap)7 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)7 UnmodifiableMap (org.eclipse.collections.impl.UnmodifiableMap)7 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)6 TextValue (org.neo4j.values.storable.TextValue)6 SchemaDescriptor (org.neo4j.internal.schema.SchemaDescriptor)5 MemoryTracker (org.neo4j.memory.MemoryTracker)5 MutableLongList (org.eclipse.collections.api.list.primitive.MutableLongList)4 Test (org.junit.jupiter.api.Test)2 MutableLongDiffSets (org.neo4j.kernel.impl.util.diffsets.MutableLongDiffSets)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 LongIterable (org.eclipse.collections.api.LongIterable)1 LongProcedure (org.eclipse.collections.api.block.procedure.primitive.LongProcedure)1 MutableList (org.eclipse.collections.api.list.MutableList)1