Search in sources :

Example 11 with ValueTuple

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

the class IndexEntryConflictExceptionTest method shouldMakeCompositeEntryConflicts.

@Test
void shouldMakeCompositeEntryConflicts() {
    LabelSchemaDescriptor schema = SchemaDescriptor.forLabel(labelId, 2, 3, 4);
    ValueTuple values = ValueTuple.of(true, "hi", new long[] { 6L, 4L });
    IndexEntryConflictException e = new IndexEntryConflictException(0L, 1L, values);
    assertThat(e.evidenceMessage(tokens, schema)).isEqualTo("Both Node(0) and Node(1) have the label `label1` and properties `p2` = true, `p3` = 'hi', `p4` = [6, 4]");
}
Also used : ValueTuple(org.neo4j.values.storable.ValueTuple) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) Test(org.junit.jupiter.api.Test)

Example 12 with ValueTuple

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

the class TxStateIndexChanges method indexUpdatesForScanAndFilter.

// HELPERS
private static AddedAndRemoved indexUpdatesForScanAndFilter(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;
    }
    MutableLongList added = LongLists.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))) {
            LongDiffSets diffSet = entry.getValue();
            added.addAll(diffSet.getAdded());
            removed.addAll(diffSet.getRemoved());
        }
    }
    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) NavigableMap(java.util.NavigableMap) Map(java.util.Map) UnmodifiableMap(org.eclipse.collections.impl.UnmodifiableMap) LongDiffSets(org.neo4j.storageengine.api.txstate.LongDiffSets)

Example 13 with ValueTuple

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

the class TxStateIndexChanges method indexUpdatesWithValuesForSeek.

static AddedWithValuesAndRemoved indexUpdatesWithValuesForSeek(ReadableTransactionState txState, IndexDescriptor descriptor, ValueTuple values) {
    UnmodifiableMap<ValueTuple, ? extends LongDiffSets> updates = txState.getIndexUpdates(descriptor.schema());
    if (updates != null) {
        LongDiffSets indexUpdatesForSeek = updates.get(values);
        if (indexUpdatesForSeek == null) {
            return EMPTY_ADDED_AND_REMOVED_WITH_VALUES;
        }
        Value[] valueArray = values.getValues();
        MutableList<EntityWithPropertyValues> added = Lists.mutable.empty();
        indexUpdatesForSeek.getAdded().forEach((LongProcedure) l -> added.add(new EntityWithPropertyValues(l, valueArray)));
        return new AddedWithValuesAndRemoved(added, indexUpdatesForSeek.getRemoved());
    }
    return EMPTY_ADDED_AND_REMOVED_WITH_VALUES;
}
Also used : IndexOrder(org.neo4j.internal.schema.IndexOrder) NO_VALUE(org.neo4j.values.storable.Values.NO_VALUE) LongDiffSets(org.neo4j.storageengine.api.txstate.LongDiffSets) ReadableTransactionState(org.neo4j.storageengine.api.txstate.ReadableTransactionState) ValueTuple(org.neo4j.values.storable.ValueTuple) LongLists(org.eclipse.collections.impl.factory.primitive.LongLists) Value(org.neo4j.values.storable.Value) TextValue(org.neo4j.values.storable.TextValue) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) NavigableMap(java.util.NavigableMap) MutableList(org.eclipse.collections.api.list.MutableList) Values(org.neo4j.values.storable.Values) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) LongProcedure(org.eclipse.collections.api.block.procedure.primitive.LongProcedure) Lists(org.eclipse.collections.impl.factory.Lists) Map(java.util.Map) LongIterable(org.eclipse.collections.api.LongIterable) LongSets(org.eclipse.collections.impl.factory.primitive.LongSets) PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) ValueGroup(org.neo4j.values.storable.ValueGroup) LongSet(org.eclipse.collections.api.set.primitive.LongSet) Collections(java.util.Collections) UnmodifiableMap(org.eclipse.collections.impl.UnmodifiableMap) ValueTuple(org.neo4j.values.storable.ValueTuple) Value(org.neo4j.values.storable.Value) TextValue(org.neo4j.values.storable.TextValue) LongDiffSets(org.neo4j.storageengine.api.txstate.LongDiffSets)

Example 14 with ValueTuple

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

the class TxStateIndexChanges method indexUpdatesForRangeSeek.

// RANGE SEEK
static AddedAndRemoved indexUpdatesForRangeSeek(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;
    }
    int size = descriptor.schema().getPropertyIds().length;
    RangeFilterValues rangeFilter = predicate == null ? RangeFilterValues.fromExists(size, equalityPrefix) : RangeFilterValues.fromRange(size, equalityPrefix, predicate);
    MutableLongList added = LongLists.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);
        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))) {
            added.addAll(diffForSpecificValue.getAdded());
            removed.addAll(diffForSpecificValue.getRemoved());
        }
    }
    return new AddedAndRemoved(indexOrder == IndexOrder.DESCENDING ? added.asReversed() : added, removed);
}
Also used : MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) 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 15 with ValueTuple

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

the class TxStateIndexChanges method indexUpdatesWithValuesForRangeSeekByPrefix.

static AddedWithValuesAndRemoved indexUpdatesWithValuesForRangeSeekByPrefix(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_WITH_VALUES;
    }
    int keySize = descriptor.schema().getPropertyIds().length;
    ValueTuple floor = getCompositeValueTuple(keySize, equalityPrefix, prefix, true);
    ValueTuple maxString = getCompositeValueTuple(keySize, equalityPrefix, Values.MAX_STRING, false);
    MutableList<EntityWithPropertyValues> added = Lists.mutable.empty();
    MutableLongSet removed = LongSets.mutable.empty();
    for (Map.Entry<ValueTuple, ? extends LongDiffSets> entry : sortedUpdates.subMap(floor, maxString).entrySet()) {
        ValueTuple key = entry.getKey();
        Value prefixKey = key.valueAt(equalityPrefix.length);
        // Needs to check type since the subMap might include non-TextValue for composite index
        if (prefixKey.valueGroup() == ValueGroup.TEXT && ((TextValue) prefixKey).startsWith(prefix)) {
            LongDiffSets diffSets = entry.getValue();
            Value[] values = key.getValues();
            diffSets.getAdded().each(nodeId -> added.add(new EntityWithPropertyValues(nodeId, values)));
            removed.addAll(diffSets.getRemoved());
        } else {
            break;
        }
    }
    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

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