Search in sources :

Example 1 with IndexOrderCapability

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

the class EntityValueIndexCursorTestBase method shouldRespectOrderCapabilitiesForNumbers.

@Test
void shouldRespectOrderCapabilitiesForNumbers() throws Exception {
    // given
    boolean needsValues = indexParams.indexProvidesNumericValues();
    int prop = token.propertyKey(PROP_NAME);
    IndexReadSession index = read.indexReadSession(schemaRead.indexGetForName(PROP_INDEX_NAME));
    IndexOrderCapability orderCapabilities = index.reference().getCapability().orderCapability(ValueCategory.NUMBER);
    try (var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
        if (orderCapabilities.supportsAsc()) {
            // when
            entityParams.entityIndexSeek(tx, index, cursor, constrained(IndexOrder.ASCENDING, needsValues), PropertyIndexQuery.range(prop, 1, true, 42, true));
            // then
            assertFoundEntitiesInOrder(cursor, IndexOrder.ASCENDING);
        }
        if (orderCapabilities.supportsDesc()) {
            // when
            entityParams.entityIndexSeek(tx, index, cursor, constrained(IndexOrder.DESCENDING, needsValues), PropertyIndexQuery.range(prop, 1, true, 42, 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 2 with IndexOrderCapability

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

the class EntityValueIndexCursorTestBase method shouldRespectOrderCapabilitiesForStrings.

@Test
void shouldRespectOrderCapabilitiesForStrings() throws Exception {
    // given
    boolean needsValues = indexParams.indexProvidesStringValues();
    int prop = token.propertyKey(PROP_NAME);
    IndexReadSession index = read.indexReadSession(schemaRead.indexGetForName(PROP_INDEX_NAME));
    IndexOrderCapability orderCapabilities = index.reference().getCapability().orderCapability(ValueCategory.TEXT);
    try (var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
        if (orderCapabilities.supportsAsc()) {
            // when
            entityParams.entityIndexSeek(tx, index, cursor, constrained(IndexOrder.ASCENDING, needsValues), PropertyIndexQuery.range(prop, "one", true, "two", true));
            // then
            assertFoundEntitiesInOrder(cursor, IndexOrder.ASCENDING);
        }
        if (orderCapabilities.supportsDesc()) {
            // when
            entityParams.entityIndexSeek(tx, index, cursor, constrained(IndexOrder.DESCENDING, needsValues), PropertyIndexQuery.range(prop, "one", true, "two", 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 3 with IndexOrderCapability

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

the class EntityValueIndexCursorTestBase method shouldRespectOrderCapabilitiesForWildcard.

@Test
void shouldRespectOrderCapabilitiesForWildcard() throws Exception {
    // given
    boolean needsValues = false;
    int prop = token.propertyKey(PROP_NAME);
    IndexReadSession index = read.indexReadSession(schemaRead.indexGetForName(PROP_INDEX_NAME));
    IndexOrderCapability orderCapabilities = index.reference().getCapability().orderCapability(ValueCategory.UNKNOWN);
    try (var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
        if (orderCapabilities.supportsAsc()) {
            // when
            entityParams.entityIndexSeek(tx, index, cursor, constrained(IndexOrder.ASCENDING, needsValues), PropertyIndexQuery.exists(prop));
            // then
            assertFoundEntitiesInOrder(cursor, IndexOrder.ASCENDING);
        }
        if (orderCapabilities.supportsDesc()) {
            // when
            entityParams.entityIndexSeek(tx, index, cursor, constrained(IndexOrder.DESCENDING, needsValues), PropertyIndexQuery.exists(prop));
            // 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 4 with IndexOrderCapability

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

the class EntityValueIndexCursorTestBase method shouldRespectOrderCapabilitiesForStringArray.

@Test
void shouldRespectOrderCapabilitiesForStringArray() 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.TEXT_ARRAY);
    try (var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
        if (orderCapabilities.supportsAsc()) {
            // when
            entityParams.entityIndexSeek(tx, index, cursor, constrained(IndexOrder.ASCENDING, needsValues), PropertyIndexQuery.range(prop, Values.of(new String[] { "first", "second", "third" }), true, Values.of(new String[] { "fourth", "fifth", "sixth", "seventh" }), true));
            // then
            assertFoundEntitiesInOrder(cursor, IndexOrder.ASCENDING);
        }
        if (orderCapabilities.supportsDesc()) {
            // when
            entityParams.entityIndexSeek(tx, index, cursor, constrained(IndexOrder.DESCENDING, needsValues), PropertyIndexQuery.range(prop, Values.of(new String[] { "first", "second", "third" }), true, Values.of(new String[] { "fourth", "fifth", "sixth", "seventh" }), 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 5 with IndexOrderCapability

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

the class SimpleIndexAccessorCompatibility method shouldRangeSeekInOrderWithExpectedSize.

private void shouldRangeSeekInOrderWithExpectedSize(IndexOrder order, RangeSeekMode rangeSeekMode, int expectedSize, Object... objects) throws Exception {
    PropertyIndexQuery range;
    switch(rangeSeekMode) {
        case CLOSED:
            range = range(100, Values.of(objects[0]), true, Values.of(objects[objects.length - 1]), true);
            break;
        case OPEN_END:
            range = range(100, Values.of(objects[0]), true, null, false);
            break;
        case OPEN_START:
            range = range(100, null, false, Values.of(objects[objects.length - 1]), true);
            break;
        default:
            throw new IllegalStateException();
    }
    IndexOrderCapability indexOrders = orderCapability(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());
    }
    List<ValueIndexEntryUpdate<?>> additions = Arrays.stream(objects).map(o -> add(1, descriptor.schema(), o)).collect(Collectors.toList());
    Collections.shuffle(additions, random.random());
    updateAndCommit(additions);
    SimpleEntityValueClient client = new SimpleEntityValueClient();
    try (AutoCloseable ignored = query(client, order, range)) {
        List<Long> seenIds = assertClientReturnValuesInOrder(client, order);
        assertThat(seenIds.size()).isEqualTo(expectedSize);
    }
}
Also used : IndexOrder(org.neo4j.internal.schema.IndexOrder) Arrays(java.util.Arrays) ArrayValue(org.neo4j.values.storable.ArrayValue) CursorContext(org.neo4j.io.pagecache.context.CursorContext) ZonedDateTime(java.time.ZonedDateTime) SimpleEntityValueClient(org.neo4j.storageengine.api.schema.SimpleEntityValueClient) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Value(org.neo4j.values.storable.Value) DefaultPageCacheTracer(org.neo4j.io.pagecache.tracing.DefaultPageCacheTracer) PropertyIndexQuery.exists(org.neo4j.internal.kernel.api.PropertyIndexQuery.exists) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) Duration(java.time.Duration) LocalTime(java.time.LocalTime) ZoneOffset(java.time.ZoneOffset) PageCursorTracer(org.neo4j.io.pagecache.tracing.cursor.PageCursorTracer) EMPTY_LIST(java.util.Collections.EMPTY_LIST) OffsetTime(java.time.OffsetTime) Collections.emptyList(java.util.Collections.emptyList) Set(java.util.Set) DateTimeValue.datetime(org.neo4j.values.storable.DateTimeValue.datetime) IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) Collectors(java.util.stream.Collectors) PointValue(org.neo4j.values.storable.PointValue) ZoneId(java.time.ZoneId) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) LocalDateTimeValue(org.neo4j.values.storable.LocalDateTimeValue) List(java.util.List) TimeValue(org.neo4j.values.storable.TimeValue) DateTimeValue(org.neo4j.values.storable.DateTimeValue) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) LocalDate(java.time.LocalDate) UTC(java.time.ZoneOffset.UTC) PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) ReporterFactories(org.neo4j.annotations.documented.ReporterFactories) PropertyIndexQuery.exact(org.neo4j.internal.kernel.api.PropertyIndexQuery.exact) LocalDateTime(java.time.LocalDateTime) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Values(org.neo4j.values.storable.Values) HashSet(java.util.HashSet) PropertyIndexQuery.range(org.neo4j.internal.kernel.api.PropertyIndexQuery.range) Assume(org.junit.Assume) LocalTimeValue(org.neo4j.values.storable.LocalTimeValue) LocalDateTimeValue.localDateTime(org.neo4j.values.storable.LocalDateTimeValue.localDateTime) LocalTimeValue.localTime(org.neo4j.values.storable.LocalTimeValue.localTime) ValueType(org.neo4j.values.storable.ValueType) IndexQueryHelper.add(org.neo4j.kernel.api.index.IndexQueryHelper.add) IndexOrderCapability(org.neo4j.internal.schema.IndexOrderCapability) PropertyIndexQuery.stringPrefix(org.neo4j.internal.kernel.api.PropertyIndexQuery.stringPrefix) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) TimeValue.time(org.neo4j.values.storable.TimeValue.time) Values.stringValue(org.neo4j.values.storable.Values.stringValue) PropertyIndexQuery.stringSuffix(org.neo4j.internal.kernel.api.PropertyIndexQuery.stringSuffix) DateValue.epochDate(org.neo4j.values.storable.DateValue.epochDate) DurationValue.duration(org.neo4j.values.storable.DurationValue.duration) ChronoUnit(java.time.temporal.ChronoUnit) Ignore(org.junit.Ignore) CoordinateReferenceSystem(org.neo4j.values.storable.CoordinateReferenceSystem) DateValue(org.neo4j.values.storable.DateValue) PropertyIndexQuery.stringContains(org.neo4j.internal.kernel.api.PropertyIndexQuery.stringContains) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) IndexOrderCapability(org.neo4j.internal.schema.IndexOrderCapability) SimpleEntityValueClient(org.neo4j.storageengine.api.schema.SimpleEntityValueClient)

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