Search in sources :

Example 1 with OrderedPropertyValues

use of org.neo4j.kernel.api.schema_new.OrderedPropertyValues in project neo4j by neo4j.

the class TxState method getIndexUpdatesForRangeSeekByString.

private ReadableDiffSets<Long> getIndexUpdatesForRangeSeekByString(NewIndexDescriptor descriptor, String lower, boolean includeLower, String upper, boolean includeUpper) {
    TreeMap<OrderedPropertyValues, DiffSets<Long>> sortedUpdates = getSortedIndexUpdates(descriptor.schema());
    if (sortedUpdates == null) {
        return null;
    }
    OrderedPropertyValues selectedLower;
    boolean selectedIncludeLower;
    OrderedPropertyValues selectedUpper;
    boolean selectedIncludeUpper;
    //TODO: Get working with composite indexes
    if (lower == null) {
        selectedLower = OrderedPropertyValues.ofUndefined(STRING.lowLimit.castValue(String.class));
        selectedIncludeLower = STRING.lowLimit.isInclusive;
    } else {
        selectedLower = OrderedPropertyValues.ofUndefined(lower);
        selectedIncludeLower = includeLower;
    }
    if (upper == null) {
        selectedUpper = OrderedPropertyValues.ofUndefined(STRING.highLimit.castValue(Boolean.class).booleanValue());
        selectedIncludeUpper = STRING.highLimit.isInclusive;
    } else {
        selectedUpper = OrderedPropertyValues.ofUndefined(upper);
        selectedIncludeUpper = includeUpper;
    }
    DiffSets<Long> diffs = new DiffSets<>();
    Collection<DiffSets<Long>> inRange = sortedUpdates.subMap(selectedLower, selectedIncludeLower, selectedUpper, selectedIncludeUpper).values();
    for (DiffSets<Long> diffForSpecificValue : inRange) {
        diffs.addAll(diffForSpecificValue.getAdded().iterator());
        diffs.removeAll(diffForSpecificValue.getRemoved().iterator());
    }
    return diffs;
}
Also used : DiffSets(org.neo4j.kernel.impl.util.diffsets.DiffSets) RelationshipDiffSets(org.neo4j.kernel.impl.util.diffsets.RelationshipDiffSets) ReadableDiffSets(org.neo4j.storageengine.api.txstate.ReadableDiffSets) ReadableRelationshipDiffSets(org.neo4j.storageengine.api.txstate.ReadableRelationshipDiffSets) OrderedPropertyValues(org.neo4j.kernel.api.schema_new.OrderedPropertyValues)

Example 2 with OrderedPropertyValues

use of org.neo4j.kernel.api.schema_new.OrderedPropertyValues in project neo4j by neo4j.

the class TxState method getIndexUpdatesForRangeSeekByPrefix.

private ReadableDiffSets<Long> getIndexUpdatesForRangeSeekByPrefix(NewIndexDescriptor descriptor, String prefix) {
    TreeMap<OrderedPropertyValues, DiffSets<Long>> sortedUpdates = getSortedIndexUpdates(descriptor.schema());
    if (sortedUpdates == null) {
        return null;
    }
    //TODO: get working with composite indexes
    OrderedPropertyValues floor = OrderedPropertyValues.ofUndefined(prefix);
    DiffSets<Long> diffs = new DiffSets<>();
    for (Map.Entry<OrderedPropertyValues, DiffSets<Long>> entry : sortedUpdates.tailMap(floor).entrySet()) {
        OrderedPropertyValues key = entry.getKey();
        if (key.getSinglePropertyValue().toString().startsWith(prefix)) {
            DiffSets<Long> diffSets = entry.getValue();
            diffs.addAll(diffSets.getAdded().iterator());
            diffs.removeAll(diffSets.getRemoved().iterator());
        } else {
            break;
        }
    }
    return diffs;
}
Also used : DiffSets(org.neo4j.kernel.impl.util.diffsets.DiffSets) RelationshipDiffSets(org.neo4j.kernel.impl.util.diffsets.RelationshipDiffSets) ReadableDiffSets(org.neo4j.storageengine.api.txstate.ReadableDiffSets) ReadableRelationshipDiffSets(org.neo4j.storageengine.api.txstate.ReadableRelationshipDiffSets) OrderedPropertyValues(org.neo4j.kernel.api.schema_new.OrderedPropertyValues) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Example 3 with OrderedPropertyValues

use of org.neo4j.kernel.api.schema_new.OrderedPropertyValues in project neo4j by neo4j.

the class TxState method getIndexUpdatesForRangeSeekByNumber.

private ReadableDiffSets<Long> getIndexUpdatesForRangeSeekByNumber(NewIndexDescriptor descriptor, Number lower, boolean includeLower, Number upper, boolean includeUpper) {
    TreeMap<OrderedPropertyValues, DiffSets<Long>> sortedUpdates = getSortedIndexUpdates(descriptor.schema());
    if (sortedUpdates == null) {
        return null;
    }
    OrderedPropertyValues selectedLower;
    boolean selectedIncludeLower;
    OrderedPropertyValues selectedUpper;
    boolean selectedIncludeUpper;
    //TODO: Get working with composite indexes
    if (lower == null) {
        selectedLower = OrderedPropertyValues.ofUndefined(NUMBER.lowLimit.castValue(Number.class));
        selectedIncludeLower = NUMBER.lowLimit.isInclusive;
    } else {
        selectedLower = OrderedPropertyValues.ofUndefined(lower);
        selectedIncludeLower = includeLower;
    }
    if (upper == null) {
        selectedUpper = OrderedPropertyValues.ofUndefined(NUMBER.highLimit.castValue(Number.class));
        selectedIncludeUpper = NUMBER.highLimit.isInclusive;
    } else {
        selectedUpper = OrderedPropertyValues.ofUndefined(upper);
        selectedIncludeUpper = includeUpper;
    }
    DiffSets<Long> diffs = new DiffSets<>();
    Collection<DiffSets<Long>> inRange = sortedUpdates.subMap(selectedLower, selectedIncludeLower, selectedUpper, selectedIncludeUpper).values();
    for (DiffSets<Long> diffForSpecificValue : inRange) {
        diffs.addAll(diffForSpecificValue.getAdded().iterator());
        diffs.removeAll(diffForSpecificValue.getRemoved().iterator());
    }
    return diffs;
}
Also used : DiffSets(org.neo4j.kernel.impl.util.diffsets.DiffSets) RelationshipDiffSets(org.neo4j.kernel.impl.util.diffsets.RelationshipDiffSets) ReadableDiffSets(org.neo4j.storageengine.api.txstate.ReadableDiffSets) ReadableRelationshipDiffSets(org.neo4j.storageengine.api.txstate.ReadableRelationshipDiffSets) OrderedPropertyValues(org.neo4j.kernel.api.schema_new.OrderedPropertyValues)

Example 4 with OrderedPropertyValues

use of org.neo4j.kernel.api.schema_new.OrderedPropertyValues in project neo4j by neo4j.

the class TxStateCompositeIndexTest method modifyIndex.

private IndexUpdater modifyIndex(final NewIndexDescriptor descriptor) {
    return new IndexUpdater() {

        @Override
        public void addDefaultStringEntries(long... nodeIds) {
            addEntries(getDefaultStringEntries(nodeIds));
        }

        @Override
        public void removeDefaultStringEntries(long... nodeIds) {
            removeEntries(getDefaultStringEntries(nodeIds));
        }

        @Override
        public void addDefaultStringProperties(long... nodeIds) {
            Collection<Pair<Long, OrderedPropertyValues>> entries = new ArrayList<>(nodeIds.length);
            for (long nodeId : nodeIds) {
                int[] propertyIds = descriptor.schema().getPropertyIds();
                Object[] values = new Object[propertyIds.length];
                for (int i = 0; i < propertyIds.length; i++) {
                    values[i] = nodeId * 1000.0 + propertyIds[i];
                }
                entries.add(of(nodeId, OrderedPropertyValues.ofUndefined(values)));
            }
            addEntries(entries);
        }

        void addEntries(Collection<Pair<Long, OrderedPropertyValues>> nodesWithValues) {
            for (Pair<Long, OrderedPropertyValues> entry : nodesWithValues) {
                long nodeId = entry.first();
                state.indexDoUpdateEntry(descriptor.schema(), nodeId, null, entry.other());
            }
        }

        void removeEntries(Collection<Pair<Long, OrderedPropertyValues>> nodesWithValues) {
            for (Pair<Long, OrderedPropertyValues> entry : nodesWithValues) {
                long nodeId = entry.first();
                state.indexDoUpdateEntry(descriptor.schema(), nodeId, entry.other(), null);
            }
        }

        private Collection<Pair<Long, OrderedPropertyValues>> getDefaultStringEntries(long[] nodeIds) {
            Collection<Pair<Long, OrderedPropertyValues>> entries = new ArrayList<>(nodeIds.length);
            for (long nodeId : nodeIds) {
                int[] propertyIds = descriptor.schema().getPropertyIds();
                OrderedPropertyValues values = getDefaultStringPropertyValues(nodeId, propertyIds);
                entries.add(of(nodeId, values));
            }
            return entries;
        }
    };
}
Also used : ArrayList(java.util.ArrayList) Collection(java.util.Collection) OrderedPropertyValues(org.neo4j.kernel.api.schema_new.OrderedPropertyValues) Pair(org.neo4j.helpers.collection.Pair)

Example 5 with OrderedPropertyValues

use of org.neo4j.kernel.api.schema_new.OrderedPropertyValues in project neo4j by neo4j.

the class IndexTxStateUpdater method onPropertyAdd.

// PROPERTY CHANGES
public void onPropertyAdd(KernelStatement state, NodeItem node, DefinedProperty after) throws EntityNotFoundException {
    Iterator<NewIndexDescriptor> indexes = getIndexesInvolvingProperty(state, after.propertyKeyId());
    nodeIndexMatcher.onMatchingSchema(state, indexes, node, after.propertyKeyId(), index -> {
        Validators.INDEX_VALUE_VALIDATOR.validate(after.value());
        OrderedPropertyValues values = getOrderedPropertyValues(state, node, after, index.schema().getPropertyIds());
        state.txState().indexDoUpdateEntry(index.schema(), node.id(), null, values);
    });
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) OrderedPropertyValues(org.neo4j.kernel.api.schema_new.OrderedPropertyValues)

Aggregations

OrderedPropertyValues (org.neo4j.kernel.api.schema_new.OrderedPropertyValues)7 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)3 DiffSets (org.neo4j.kernel.impl.util.diffsets.DiffSets)3 RelationshipDiffSets (org.neo4j.kernel.impl.util.diffsets.RelationshipDiffSets)3 ReadableDiffSets (org.neo4j.storageengine.api.txstate.ReadableDiffSets)3 ReadableRelationshipDiffSets (org.neo4j.storageengine.api.txstate.ReadableRelationshipDiffSets)3 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 PrimitiveIntSet (org.neo4j.collection.primitive.PrimitiveIntSet)1 Pair (org.neo4j.helpers.collection.Pair)1