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]");
}
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);
}
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;
}
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);
}
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);
}
Aggregations