Search in sources :

Example 6 with ValueType

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

the class AbstractIndexProvidedOrderTest method shouldProvideResultInOrderIfCapable.

@Test
void shouldProvideResultInOrderIfCapable() throws KernelException {
    int prop = token.propertyKey(PROPERTY_KEY);
    RandomValues randomValues = randomRule.randomValues();
    IndexReadSession index = read.indexReadSession(tx.schemaRead().indexGetForName(INDEX_NAME));
    for (int i = 0; i < N_ITERATIONS; i++) {
        ValueType type = randomValues.among(targetedTypes);
        IndexOrderCapability order = index.reference().getCapability().orderCapability(type.valueGroup.category());
        if (order.supportsAsc()) {
            expectResultInOrder(randomValues, type, prop, index, IndexOrder.ASCENDING);
        }
        if (order.supportsDesc()) {
            expectResultInOrder(randomValues, type, prop, index, IndexOrder.DESCENDING);
        }
    }
}
Also used : ValueType(org.neo4j.values.storable.ValueType) RandomValues(org.neo4j.values.storable.RandomValues) IndexOrderCapability(org.neo4j.internal.schema.IndexOrderCapability) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Example 7 with ValueType

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

the class AbstractIndexProvidedOrderTest method ensureHighEnoughCardinality.

/**
 * If targetedTypes only contain types that has very low cardinality, then add one random high cardinality value type to the array.
 * This is to prevent createTestGraph from looping forever when trying to generate unique values.
 */
private ValueType[] ensureHighEnoughCardinality(ValueType[] targetedTypes) {
    ValueType[] lowCardinalityArray = new ValueType[] { ValueType.BOOLEAN, ValueType.BYTE, ValueType.BOOLEAN_ARRAY };
    List<ValueType> typesOfLowCardinality = new ArrayList<>(Arrays.asList(lowCardinalityArray));
    for (ValueType targetedType : targetedTypes) {
        if (!typesOfLowCardinality.contains(targetedType)) {
            return targetedTypes;
        }
    }
    List<ValueType> result = new ArrayList<>(Arrays.asList(targetedTypes));
    ValueType highCardinalityType = randomRule.randomValues().among(RandomValues.excluding(lowCardinalityArray));
    result.add(highCardinalityType);
    return result.toArray(new ValueType[0]);
}
Also used : ValueType(org.neo4j.values.storable.ValueType) ArrayList(java.util.ArrayList)

Example 8 with ValueType

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

the class SimpleRandomizedIndexAccessorCompatibility method testExactMatchOnRandomValues.

@Test
public void testExactMatchOnRandomValues() throws Exception {
    // given
    ValueType[] types = randomSetOfSupportedTypes();
    List<Value> values = generateValuesFromType(types, new HashSet<>(), 30_000);
    List<ValueIndexEntryUpdate<?>> updates = generateUpdatesFromValues(values, new MutableLong());
    updateAndCommit(updates);
    // when
    for (ValueIndexEntryUpdate<?> update : updates) {
        // then
        List<Long> hits = query(PropertyIndexQuery.exact(0, update.values()[0]));
        assertEquals(hits.toString(), 1, hits.size());
        assertThat(single(hits)).isEqualTo(update.getEntityId());
    }
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) ValueType(org.neo4j.values.storable.ValueType) Value(org.neo4j.values.storable.Value) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) MutableLong(org.apache.commons.lang3.mutable.MutableLong) Test(org.junit.Test)

Example 9 with ValueType

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

the class SimpleRandomizedIndexAccessorCompatibility method testRangeMatchInOrderOnRandomValues.

@Test
public void testRangeMatchInOrderOnRandomValues() throws Exception {
    Assume.assumeTrue("Assume support for granular composite queries", testSuite.supportsGranularCompositeQueries());
    // given
    ValueType[] types = randomSetOfSupportedAndSortableTypes();
    Set<Value> uniqueValues = new HashSet<>();
    TreeSet<ValueAndId> sortedValues = new TreeSet<>((v1, v2) -> Values.COMPARATOR.compare(v1.value, v2.value));
    MutableLong nextId = new MutableLong();
    // A couple of rounds of updates followed by lots of range verifications
    for (int i = 0; i < 5; i++) {
        List<ValueIndexEntryUpdate<?>> updates = new ArrayList<>();
        if (i == 0) {
            // The initial batch of data can simply be additions
            updates = generateUpdatesFromValues(generateValuesFromType(types, uniqueValues, 20_000), nextId);
            sortedValues.addAll(updates.stream().map(u -> new ValueAndId(u.values()[0], u.getEntityId())).collect(Collectors.toList()));
        } else {
            // Then do all sorts of updates
            for (int j = 0; j < 1_000; j++) {
                int type = random.intBetween(0, 2);
                if (type == 0) {
                    // add
                    Value value = generateUniqueRandomValue(types, uniqueValues);
                    long id = nextId.getAndIncrement();
                    sortedValues.add(new ValueAndId(value, id));
                    updates.add(add(id, descriptor.schema(), value));
                } else if (type == 1) {
                    // update
                    ValueAndId existing = random.among(sortedValues.toArray(new ValueAndId[0]));
                    sortedValues.remove(existing);
                    Value newValue = generateUniqueRandomValue(types, uniqueValues);
                    uniqueValues.remove(existing.value);
                    sortedValues.add(new ValueAndId(newValue, existing.id));
                    updates.add(change(existing.id, descriptor.schema(), existing.value, newValue));
                } else {
                    // remove
                    ValueAndId existing = random.among(sortedValues.toArray(new ValueAndId[0]));
                    sortedValues.remove(existing);
                    uniqueValues.remove(existing.value);
                    updates.add(remove(existing.id, descriptor.schema(), existing.value));
                }
            }
        }
        updateAndCommit(updates);
        verifyRandomRanges(types, sortedValues);
    }
}
Also used : ValueType(org.neo4j.values.storable.ValueType) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) ArrayList(java.util.ArrayList) MutableLong(org.apache.commons.lang3.mutable.MutableLong) TreeSet(java.util.TreeSet) Value(org.neo4j.values.storable.Value) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with ValueType

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

the class SimpleRandomizedIndexAccessorCompatibility method verifyRandomRanges.

private void verifyRandomRanges(ValueType[] types, TreeSet<ValueAndId> sortedValues) throws Exception {
    for (int i = 0; i < 100; i++) {
        // Construct a random range query of random value type
        ValueType type = random.among(types);
        Value from = random.randomValues().nextValueOfType(type);
        Value to = random.randomValues().nextValueOfType(type);
        if (Values.COMPARATOR.compare(from, to) > 0) {
            Value tmp = from;
            from = to;
            to = tmp;
        }
        boolean fromInclusive = random.nextBoolean();
        boolean toInclusive = random.nextBoolean();
        // Expected result based on query
        PropertyIndexQuery.RangePredicate<?> predicate = PropertyIndexQuery.range(0, from, fromInclusive, to, toInclusive);
        List<Long> expectedIds = expectedIds(sortedValues, from, to, fromInclusive, toInclusive);
        // Depending on order capabilities we verify ids or order and ids.
        IndexOrderCapability indexOrders = descriptor.getCapability().orderCapability(predicate.valueGroup().category());
        if (indexOrders.supportsAsc()) {
            List<Long> actualIds = assertInOrder(IndexOrder.ASCENDING, predicate);
            actualIds.sort(Long::compare);
            // then
            assertThat(actualIds).isEqualTo(expectedIds);
        }
        if (indexOrders.supportsDesc()) {
            List<Long> actualIds = assertInOrder(IndexOrder.DESCENDING, predicate);
            actualIds.sort(Long::compare);
            // then
            assertThat(actualIds).isEqualTo(expectedIds);
        }
    }
}
Also used : PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) ValueType(org.neo4j.values.storable.ValueType) Value(org.neo4j.values.storable.Value) MutableLong(org.apache.commons.lang3.mutable.MutableLong) IndexOrderCapability(org.neo4j.internal.schema.IndexOrderCapability)

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