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