Search in sources :

Example 11 with ValueType

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

the class CompositeIndexAccessorCompatibility method testExactMatchOnRandomCompositeValues.

@Test
public void testExactMatchOnRandomCompositeValues() throws Exception {
    // given
    ValueType[] types = randomSetOfSupportedTypes();
    List<ValueIndexEntryUpdate<?>> updates = new ArrayList<>();
    Set<ValueTuple> duplicateChecker = new HashSet<>();
    for (long id = 0; id < 10_000; id++) {
        ValueIndexEntryUpdate<SchemaDescriptor> update;
        do {
            update = add(id, descriptor.schema(), random.randomValues().nextValueOfTypes(types), random.randomValues().nextValueOfTypes(types));
        } while (!duplicateChecker.add(ValueTuple.of(update.values())));
        updates.add(update);
    }
    updateAndCommit(updates);
    // when
    InMemoryTokens tokenNameLookup = new InMemoryTokens();
    for (ValueIndexEntryUpdate<?> update : updates) {
        // then
        List<Long> hits = query(exact(0, update.values()[0]), exact(1, update.values()[1]));
        assertEquals(update.describe(tokenNameLookup) + " " + hits, 1, hits.size());
        assertThat(single(hits)).isEqualTo(update.getEntityId());
    }
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) InMemoryTokens(org.neo4j.test.InMemoryTokens) ValueType(org.neo4j.values.storable.ValueType) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) ArrayList(java.util.ArrayList) ValueTuple(org.neo4j.values.storable.ValueTuple) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 12 with ValueType

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

the class CompositeIndexAccessorCompatibility method shouldRemoveEntries.

@Test
public void shouldRemoveEntries() throws Exception {
    ValueType[] valueTypes = testSuite.supportedValueTypes();
    long entityId = random.nextLong(1_000_000_000);
    for (ValueType valueType : valueTypes) {
        // given
        Value[] value = new Value[] { random.nextValue(valueType), random.nextValue(valueType) };
        updateAndCommit(singletonList(IndexEntryUpdate.add(entityId, descriptor.schema(), value)));
        assertEquals(singletonList(entityId), query(exactQuery(value)));
        // when
        updateAndCommit(singletonList(IndexEntryUpdate.remove(entityId, descriptor.schema(), value)));
        // then
        assertEquals(emptyList(), query(exactQuery(value)));
    }
}
Also used : ValueType(org.neo4j.values.storable.ValueType) ArrayValue(org.neo4j.values.storable.ArrayValue) Value(org.neo4j.values.storable.Value) TextValue(org.neo4j.values.storable.TextValue) PointValue(org.neo4j.values.storable.PointValue) LocalDateTimeValue(org.neo4j.values.storable.LocalDateTimeValue) TimeValue(org.neo4j.values.storable.TimeValue) DateTimeValue(org.neo4j.values.storable.DateTimeValue) Values.intValue(org.neo4j.values.storable.Values.intValue) Values.pointValue(org.neo4j.values.storable.Values.pointValue) LocalTimeValue(org.neo4j.values.storable.LocalTimeValue) BooleanValue(org.neo4j.values.storable.BooleanValue) Values.stringValue(org.neo4j.values.storable.Values.stringValue) DateValue(org.neo4j.values.storable.DateValue) Test(org.junit.Test)

Example 13 with ValueType

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

the class NativeIndexAccessorTests method respectIndexOrder.

@Test
void respectIndexOrder() throws Exception {
    // given
    int nUpdates = 10000;
    ValueType[] types = supportedTypesExcludingNonOrderable();
    Iterator<ValueIndexEntryUpdate<IndexDescriptor>> randomUpdateGenerator = valueCreatorUtil.randomUpdateGenerator(random, types);
    // noinspection unchecked
    ValueIndexEntryUpdate<IndexDescriptor>[] someUpdates = new ValueIndexEntryUpdate[nUpdates];
    for (int i = 0; i < nUpdates; i++) {
        someUpdates[i] = randomUpdateGenerator.next();
    }
    processAll(someUpdates);
    Value[] allValues = ValueCreatorUtil.extractValuesFromUpdates(someUpdates);
    // when
    try (var reader = accessor.newValueReader()) {
        ValueGroup valueGroup = random.among(allValues).valueGroup();
        PropertyIndexQuery.RangePredicate<?> supportedQuery = PropertyIndexQuery.range(0, valueGroup);
        IndexOrderCapability supportedOrders = indexCapability().orderCapability(valueGroup.category());
        if (supportedOrders.supportsAsc()) {
            expectIndexOrder(allValues, valueGroup, reader, IndexOrder.ASCENDING, supportedQuery);
        }
        if (supportedOrders.supportsDesc()) {
            expectIndexOrder(allValues, valueGroup, reader, IndexOrder.DESCENDING, supportedQuery);
        }
    }
}
Also used : ValueType(org.neo4j.values.storable.ValueType) ValueGroup(org.neo4j.values.storable.ValueGroup) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) Value(org.neo4j.values.storable.Value) PointValue(org.neo4j.values.storable.PointValue) IndexOrderCapability(org.neo4j.internal.schema.IndexOrderCapability) Test(org.junit.jupiter.api.Test)

Aggregations

ValueType (org.neo4j.values.storable.ValueType)13 Value (org.neo4j.values.storable.Value)10 Test (org.junit.Test)7 PointValue (org.neo4j.values.storable.PointValue)5 ValueIndexEntryUpdate (org.neo4j.storageengine.api.ValueIndexEntryUpdate)4 ArrayValue (org.neo4j.values.storable.ArrayValue)4 DateTimeValue (org.neo4j.values.storable.DateTimeValue)4 DateValue (org.neo4j.values.storable.DateValue)4 LocalDateTimeValue (org.neo4j.values.storable.LocalDateTimeValue)4 LocalTimeValue (org.neo4j.values.storable.LocalTimeValue)4 TimeValue (org.neo4j.values.storable.TimeValue)4 Values.stringValue (org.neo4j.values.storable.Values.stringValue)4 ArrayList (java.util.ArrayList)3 MutableLong (org.apache.commons.lang3.mutable.MutableLong)3 IndexOrderCapability (org.neo4j.internal.schema.IndexOrderCapability)3 RandomValues (org.neo4j.values.storable.RandomValues)3 HashSet (java.util.HashSet)2 Test (org.junit.jupiter.api.Test)2 Transaction (org.neo4j.graphdb.Transaction)2 PropertyIndexQuery (org.neo4j.internal.kernel.api.PropertyIndexQuery)2