Search in sources :

Example 11 with IndexOrderCapability

use of org.neo4j.internal.schema.IndexOrderCapability in project neo4j by neo4j.

the class EntityValueIndexCursorTestBase method shouldRespectOrderCapabilitiesForTemporal.

@Test
void shouldRespectOrderCapabilitiesForTemporal() throws KernelException {
    // given
    boolean needsValues = indexParams.indexProvidesTemporalValues();
    int prop = token.propertyKey(PROP_NAME);
    IndexReadSession index = read.indexReadSession(schemaRead.indexGetForName(PROP_INDEX_NAME));
    IndexOrderCapability orderCapabilities = index.reference().getCapability().orderCapability(ValueCategory.TEMPORAL);
    try (var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
        if (orderCapabilities.supportsAsc()) {
            // when
            entityParams.entityIndexSeek(tx, index, cursor, constrained(IndexOrder.ASCENDING, needsValues), PropertyIndexQuery.range(prop, DateValue.date(1986, 11, 18), true, DateValue.date(1989, 3, 24), true));
            // then
            assertFoundEntitiesInOrder(cursor, IndexOrder.ASCENDING);
        }
        if (orderCapabilities.supportsDesc()) {
            // when
            entityParams.entityIndexSeek(tx, index, cursor, constrained(IndexOrder.DESCENDING, needsValues), PropertyIndexQuery.range(prop, DateValue.date(1986, 11, 18), true, DateValue.date(1989, 3, 24), true));
            // then
            assertFoundEntitiesInOrder(cursor, IndexOrder.DESCENDING);
        }
    }
}
Also used : IndexOrderCapability(org.neo4j.internal.schema.IndexOrderCapability) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Example 12 with IndexOrderCapability

use of org.neo4j.internal.schema.IndexOrderCapability in project neo4j by neo4j.

the class QueryValidator method validateOrder.

static void validateOrder(IndexCapability capability, IndexOrder indexOrder, PropertyIndexQuery[] predicates) {
    if (indexOrder != IndexOrder.NONE) {
        ValueCategory valueCategory = predicates[0].valueGroup().category();
        IndexOrderCapability orderCapability = capability.orderCapability(valueCategory);
        if (indexOrder == IndexOrder.ASCENDING && !orderCapability.supportsAsc() || indexOrder == IndexOrder.DESCENDING && !orderCapability.supportsDesc()) {
            throw new UnsupportedOperationException(format("Tried to query index with unsupported order %s. For query %s supports ascending: %b, supports descending: %b.", indexOrder, Arrays.toString(predicates), orderCapability.supportsAsc(), orderCapability.supportsDesc()));
        }
    }
}
Also used : ValueCategory(org.neo4j.values.storable.ValueCategory) IndexOrderCapability(org.neo4j.internal.schema.IndexOrderCapability)

Example 13 with IndexOrderCapability

use of org.neo4j.internal.schema.IndexOrderCapability 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

IndexOrderCapability (org.neo4j.internal.schema.IndexOrderCapability)13 Test (org.junit.jupiter.api.Test)9 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)7 ValueType (org.neo4j.values.storable.ValueType)4 PropertyIndexQuery (org.neo4j.internal.kernel.api.PropertyIndexQuery)3 ArrayList (java.util.ArrayList)2 Arrays.asList (java.util.Arrays.asList)2 Collections (java.util.Collections)2 List (java.util.List)2 Set (java.util.Set)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 IndexPrototype (org.neo4j.internal.schema.IndexPrototype)2 Value (org.neo4j.values.storable.Value)2 Duration (java.time.Duration)1 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 LocalTime (java.time.LocalTime)1 OffsetTime (java.time.OffsetTime)1 ZoneId (java.time.ZoneId)1 ZoneOffset (java.time.ZoneOffset)1