Search in sources :

Example 1 with Value

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

the class LuceneFulltextIndexTest method completeConfigurationMustInjectMissingConfigurations.

@Test
void completeConfigurationMustInjectMissingConfigurations() throws Exception {
    int label;
    int propertyKey;
    try (Transaction tx = db.beginTx()) {
        createNodeIndexableByPropertyValue(tx, LABEL, "bla");
        tx.commit();
    }
    try (KernelTransactionImplementation tx = getKernelTransaction()) {
        label = tx.tokenRead().nodeLabel(LABEL.name());
        propertyKey = tx.tokenRead().propertyKey(PROP);
        tx.success();
    }
    IndexConfig indexConfig = IndexConfig.with(EVENTUALLY_CONSISTENT, Values.booleanValue(true));
    FulltextSchemaDescriptor schema = SchemaDescriptor.fulltext(NODE, new int[] { label }, new int[] { propertyKey });
    IndexProviderDescriptor providerDescriptor = indexProvider.getProviderDescriptor();
    IndexDescriptor descriptor = indexProvider.completeConfiguration(IndexPrototype.forSchema(schema, providerDescriptor).withName("index_1").withIndexConfig(indexConfig).materialise(1));
    assertThat((Value) descriptor.getIndexConfig().get(ANALYZER)).isEqualTo(Values.stringValue("standard-no-stop-words"));
    assertThat((Value) descriptor.getIndexConfig().get(EVENTUALLY_CONSISTENT)).isEqualTo(Values.booleanValue(true));
    assertThat(asList(descriptor.getCapability().behaviours())).containsExactlyInAnyOrder(IndexBehaviour.EVENTUALLY_CONSISTENT, IndexBehaviour.SKIP_AND_LIMIT);
}
Also used : IndexConfig(org.neo4j.internal.schema.IndexConfig) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) KernelTransactionImplementation(org.neo4j.kernel.impl.api.KernelTransactionImplementation) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) Value(org.neo4j.values.storable.Value) FulltextSchemaDescriptor(org.neo4j.internal.schema.FulltextSchemaDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 2 with Value

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

the class EntityValueIndexCursorTestBase method assertFoundEntitiesAndValue.

private void assertFoundEntitiesAndValue(ENTITY_VALUE_INDEX_CURSOR cursor, int expectedCount, MutableLongSet uniqueIds, IndexValueCapability expectValue, boolean indexProvidesValues) {
    uniqueIds.clear();
    for (int i = 0; i < expectedCount; i++) {
        assertTrue(cursor.next(), "at least " + expectedCount + " entities, was " + uniqueIds.size());
        long reference = entityParams.entityReference(cursor);
        assertTrue(uniqueIds.add(reference), "all entities are unique");
        // Assert has value capability
        if (IndexValueCapability.YES.equals(expectValue)) {
            assertTrue(cursor.hasValue(), "Value capability said index would have value for " + expectValue + ", but didn't");
        }
        // Assert has correct value
        if (indexProvidesValues) {
            assertTrue(cursor.hasValue(), "Index did not provide values");
            Value storedValue = entityParams.getPropertyValueFromStore(tx, cursors, reference);
            assertThat(cursor.propertyValue(0)).as("has correct value").isEqualTo(storedValue);
        }
    }
    assertFalse(cursor.next(), "no more than " + expectedCount + " entities");
}
Also used : Value(org.neo4j.values.storable.Value) Values.stringValue(org.neo4j.values.storable.Values.stringValue) PointValue(org.neo4j.values.storable.PointValue) DateValue(org.neo4j.values.storable.DateValue) Values.intValue(org.neo4j.values.storable.Values.intValue)

Example 3 with Value

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

the class Operations method nodeSetProperty.

@Override
public Value nodeSetProperty(long node, int propertyKey, Value value) throws EntityNotFoundException, ConstraintValidationException {
    assert value != NO_VALUE;
    acquireExclusiveNodeLock(node);
    ktx.assertOpen();
    singleNode(node);
    long[] labels = acquireSharedNodeLabelLocks();
    Value existingValue = readNodeProperty(propertyKey);
    int[] existingPropertyKeyIds = null;
    boolean hasRelatedSchema = storageReader.hasRelatedSchema(labels, propertyKey, NODE);
    if (hasRelatedSchema) {
        existingPropertyKeyIds = loadSortedNodePropertyKeyList();
    }
    if (existingValue == NO_VALUE) {
        ktx.securityAuthorizationHandler().assertAllowsSetProperty(ktx.securityContext(), this::resolvePropertyKey, Labels.from(labels), propertyKey);
        checkUniquenessConstraints(node, propertyKey, value, labels, existingPropertyKeyIds);
        // no existing value, we just add it
        ktx.txState().nodeDoAddProperty(node, propertyKey, value);
        if (hasRelatedSchema) {
            updater.onPropertyAdd(nodeCursor, propertyCursor, labels, propertyKey, existingPropertyKeyIds, value);
        }
    } else if (propertyHasChanged(value, existingValue)) {
        ktx.securityAuthorizationHandler().assertAllowsSetProperty(ktx.securityContext(), this::resolvePropertyKey, Labels.from(labels), propertyKey);
        checkUniquenessConstraints(node, propertyKey, value, labels, existingPropertyKeyIds);
        // the value has changed to a new value
        ktx.txState().nodeDoChangeProperty(node, propertyKey, value);
        if (hasRelatedSchema) {
            updater.onPropertyChange(nodeCursor, propertyCursor, labels, propertyKey, existingPropertyKeyIds, existingValue, value);
        }
    }
    return existingValue;
}
Also used : Value(org.neo4j.values.storable.Value)

Example 4 with Value

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

the class Operations method readNodeProperty.

private Value readNodeProperty(int propertyKey) {
    nodeCursor.properties(propertyCursor);
    // Find out if the property had a value
    Value existingValue = NO_VALUE;
    while (propertyCursor.next()) {
        if (propertyCursor.propertyKey() == propertyKey) {
            existingValue = propertyCursor.propertyValue();
            break;
        }
    }
    return existingValue;
}
Also used : Value(org.neo4j.values.storable.Value)

Example 5 with Value

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

Aggregations

Value (org.neo4j.values.storable.Value)260 Test (org.junit.jupiter.api.Test)91 TextValue (org.neo4j.values.storable.TextValue)63 PointValue (org.neo4j.values.storable.PointValue)50 Values.stringValue (org.neo4j.values.storable.Values.stringValue)46 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)41 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)39 DateValue (org.neo4j.values.storable.DateValue)31 ArrayList (java.util.ArrayList)30 DateTimeValue (org.neo4j.values.storable.DateTimeValue)29 LocalDateTimeValue (org.neo4j.values.storable.LocalDateTimeValue)29 LocalTimeValue (org.neo4j.values.storable.LocalTimeValue)29 TimeValue (org.neo4j.values.storable.TimeValue)29 Values.intValue (org.neo4j.values.storable.Values.intValue)26 MethodSource (org.junit.jupiter.params.provider.MethodSource)23 ArrayValue (org.neo4j.values.storable.ArrayValue)23 DurationValue (org.neo4j.values.storable.DurationValue)23 HashMap (java.util.HashMap)19 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)19 IntValue (org.neo4j.values.storable.IntValue)19