use of org.neo4j.internal.schema.IndexOrderCapability 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.internal.schema.IndexOrderCapability in project neo4j by neo4j.
the class SchemaCacheTest method shouldCompleteConfigurationOfIndexesAddedToCache.
@Test
void shouldCompleteConfigurationOfIndexesAddedToCache() {
IndexCapability capability = new IndexCapability() {
@Override
public IndexOrderCapability orderCapability(ValueCategory... valueCategories) {
return IndexOrderCapability.NONE;
}
@Override
public IndexValueCapability valueCapability(ValueCategory... valueCategories) {
return IndexValueCapability.NO;
}
};
List<IndexDescriptor> completed = new ArrayList<>();
IndexConfigCompleter completer = index -> {
completed.add(index);
return index.withIndexCapability(capability);
};
SchemaCache cache = new SchemaCache(new ConstraintSemantics(), completer);
IndexDescriptor index1 = newIndexRule(1, 2, 3);
ConstraintDescriptor constraint1 = uniquenessConstraint(2, 2, 3, 1);
IndexDescriptor index2 = newIndexRule(3, 4, 5);
ConstraintDescriptor constraint2 = uniquenessConstraint(4, 4, 5, 3);
IndexDescriptor index3 = newIndexRule(5, 5, 5);
cache.load(asList(index1, constraint1));
cache.addSchemaRule(index2);
cache.addSchemaRule(constraint2);
cache.addSchemaRule(index3);
assertEquals(List.of(index1, index2, index3), completed);
assertEquals(capability, cache.getIndex(index1.getId()).getCapability());
assertEquals(capability, cache.getIndex(index2.getId()).getCapability());
assertEquals(capability, cache.getIndex(index3.getId()).getCapability());
}
use of org.neo4j.internal.schema.IndexOrderCapability 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);
}
}
}
use of org.neo4j.internal.schema.IndexOrderCapability in project neo4j by neo4j.
the class CompositeIndexAccessorCompatibility method shouldSeekInOrderExactWithRange.
private void shouldSeekInOrderExactWithRange(IndexOrder order, Object o0, Object o1, Object o2, Object o3, Object o4, Object o5) throws Exception {
// Todo use random value instead
Object baseValue = 1;
PropertyIndexQuery exact = exact(100, baseValue);
PropertyIndexQuery range = range(200, Values.of(o0), true, Values.of(o5), true);
IndexOrderCapability indexOrders = orderCapability(exact, range);
if (order == IndexOrder.ASCENDING) {
Assume.assumeTrue("Assume support for order " + order, indexOrders.supportsAsc());
} else if (order == IndexOrder.DESCENDING) {
Assume.assumeTrue("Assume support for order " + order, indexOrders.supportsDesc());
}
updateAndCommit(asList(add(1, descriptor.schema(), baseValue, o0), add(1, descriptor.schema(), baseValue, o5), add(1, descriptor.schema(), baseValue, o1), add(1, descriptor.schema(), baseValue, o4), add(1, descriptor.schema(), baseValue, o2), add(1, descriptor.schema(), baseValue, o3)));
SimpleEntityValueClient client = new SimpleEntityValueClient();
try (AutoCloseable ignored = query(client, order, exact, range)) {
List<Long> seenIds = assertClientReturnValuesInOrder(client, order);
assertThat(seenIds.size()).isEqualTo(6);
}
}
use of org.neo4j.internal.schema.IndexOrderCapability in project neo4j by neo4j.
the class EntityValueIndexCursorTestBase method shouldRespectOrderCapabilitiesForSpatial.
@Test
void shouldRespectOrderCapabilitiesForSpatial() throws KernelException {
// given
boolean needsValues = indexParams.indexProvidesSpatialValues();
int prop = token.propertyKey(PROP_NAME);
IndexReadSession index = read.indexReadSession(schemaRead.indexGetForName(PROP_INDEX_NAME));
IndexOrderCapability orderCapabilities = index.reference().getCapability().orderCapability(ValueCategory.GEOMETRY);
try (var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
if (orderCapabilities.supportsAsc()) {
// when
entityParams.entityIndexSeek(tx, index, cursor, constrained(IndexOrder.ASCENDING, needsValues), PropertyIndexQuery.range(prop, CoordinateReferenceSystem.Cartesian));
// then
assertFoundEntitiesInOrder(cursor, IndexOrder.ASCENDING);
}
if (orderCapabilities.supportsDesc()) {
// when
entityParams.entityIndexSeek(tx, index, cursor, constrained(IndexOrder.DESCENDING, needsValues), PropertyIndexQuery.range(prop, CoordinateReferenceSystem.Cartesian));
// then
assertFoundEntitiesInOrder(cursor, IndexOrder.DESCENDING);
}
}
}
Aggregations