Search in sources :

Example 1 with IndexOrder

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

Example 2 with IndexOrder

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

the class NativeIndexAccessorTests method expectIndexOrder.

private static void expectIndexOrder(Value[] allValues, ValueGroup valueGroup, ValueIndexReader reader, IndexOrder supportedOrder, PropertyIndexQuery.RangePredicate<?> supportedQuery) throws IndexNotApplicableKernelException {
    Value[] expectedValues = Arrays.stream(allValues).filter(v -> v.valueGroup() == valueGroup).toArray(Value[]::new);
    if (supportedOrder == IndexOrder.ASCENDING) {
        Arrays.sort(expectedValues, Values.COMPARATOR);
    } else if (supportedOrder == IndexOrder.DESCENDING) {
        Arrays.sort(expectedValues, Values.COMPARATOR.reversed());
    }
    SimpleEntityValueClient client = new SimpleEntityValueClient();
    reader.query(NULL_CONTEXT, client, constrained(supportedOrder, true), supportedQuery);
    int i = 0;
    while (client.next()) {
        assertEquals(expectedValues[i++], client.values[0], "values in order");
    }
    assertEquals(i, expectedValues.length, "found all values");
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) IndexOrder(org.neo4j.internal.schema.IndexOrder) Arrays(java.util.Arrays) ValueIndexReader(org.neo4j.kernel.api.index.ValueIndexReader) SimpleEntityValueClient(org.neo4j.storageengine.api.schema.SimpleEntityValueClient) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Iterators.filter(org.neo4j.internal.helpers.collection.Iterators.filter) NULL_CONTEXT(org.neo4j.internal.kernel.api.QueryContext.NULL_CONTEXT) Value(org.neo4j.values.storable.Value) RandomValues(org.neo4j.values.storable.RandomValues) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) NULL(org.neo4j.io.pagecache.context.CursorContext.NULL) IndexEntryUpdate.remove(org.neo4j.storageengine.api.IndexEntryUpdate.remove) Predicates.alwaysTrue(org.neo4j.function.Predicates.alwaysTrue) EMPTY_LONG_ARRAY(org.neo4j.collection.PrimitiveLongCollections.EMPTY_LONG_ARRAY) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) TestDirectory(org.neo4j.test.rule.TestDirectory) Collectors(java.util.stream.Collectors) PointValue(org.neo4j.values.storable.PointValue) String.format(java.lang.String.format) ValueIndexEntryUpdate(org.neo4j.storageengine.api.ValueIndexEntryUpdate) Test(org.junit.jupiter.api.Test) IndexValueCapability(org.neo4j.internal.schema.IndexValueCapability) IndexQueryConstraints.unconstrained(org.neo4j.internal.kernel.api.IndexQueryConstraints.unconstrained) List(java.util.List) Stream(java.util.stream.Stream) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) IndexNotApplicableKernelException(org.neo4j.internal.kernel.api.exceptions.schema.IndexNotApplicableKernelException) PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) ValueCreatorUtil.countUniqueValues(org.neo4j.kernel.impl.index.schema.ValueCreatorUtil.countUniqueValues) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) IndexCapability(org.neo4j.internal.schema.IndexCapability) IndexDirectoryStructure.directoriesByProvider(org.neo4j.kernel.api.index.IndexDirectoryStructure.directoriesByProvider) Iterables.asUniqueSet(org.neo4j.internal.helpers.collection.Iterables.asUniqueSet) IndexQueryConstraints.unorderedValues(org.neo4j.internal.kernel.api.IndexQueryConstraints.unorderedValues) IndexEntryUpdate.change(org.neo4j.storageengine.api.IndexEntryUpdate.change) Predicates.in(org.neo4j.function.Predicates.in) ArrayList(java.util.ArrayList) Values(org.neo4j.values.storable.Values) HashSet(java.util.HashSet) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IndexSample(org.neo4j.kernel.api.index.IndexSample) Iterator(java.util.Iterator) ValueType(org.neo4j.values.storable.ValueType) IndexOrderCapability(org.neo4j.internal.schema.IndexOrderCapability) IndexQueryConstraints(org.neo4j.internal.kernel.api.IndexQueryConstraints) IndexDirectoryStructure(org.neo4j.kernel.api.index.IndexDirectoryStructure) IndexQueryConstraints.constrained(org.neo4j.internal.kernel.api.IndexQueryConstraints.constrained) PrimitiveLongCollections(org.neo4j.collection.PrimitiveLongCollections) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) LongIterator(org.eclipse.collections.api.iterator.LongIterator) IndexProgressor(org.neo4j.kernel.api.index.IndexProgressor) Values.of(org.neo4j.values.storable.Values.of) CoordinateReferenceSystem(org.neo4j.values.storable.CoordinateReferenceSystem) IndexSampler(org.neo4j.kernel.api.index.IndexSampler) ValueGroup(org.neo4j.values.storable.ValueGroup) Collections(java.util.Collections) ONLINE(org.neo4j.kernel.impl.api.index.IndexUpdateMode.ONLINE) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Value(org.neo4j.values.storable.Value) PointValue(org.neo4j.values.storable.PointValue) SimpleEntityValueClient(org.neo4j.storageengine.api.schema.SimpleEntityValueClient)

Example 3 with IndexOrder

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

the class DefaultTokenIndexReader method query.

@Override
public void query(IndexProgressor.EntityTokenClient client, IndexQueryConstraints constraints, TokenPredicate query, EntityRange range, CursorContext cursorContext) {
    try {
        final int tokenId = query.tokenId();
        final IndexOrder order = constraints.order();
        Seeker<TokenScanKey, TokenScanValue> seeker = seekerForToken(range, tokenId, order, cursorContext);
        IndexProgressor progressor = new TokenScanValueIndexProgressor(seeker, client, order, range);
        client.initialize(progressor, tokenId, order);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : IndexProgressor(org.neo4j.kernel.api.index.IndexProgressor) UncheckedIOException(java.io.UncheckedIOException) IndexOrder(org.neo4j.internal.schema.IndexOrder) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 4 with IndexOrder

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

the class NativeIndexAccessorTests method throwForUnsupportedIndexOrder.

@Test
void throwForUnsupportedIndexOrder() {
    // Unsupported index order for query
    try (var reader = accessor.newValueReader()) {
        IndexOrder unsupportedOrder = IndexOrder.DESCENDING;
        // <- Any spatial value would do
        PropertyIndexQuery.ExactPredicate unsupportedQuery = PropertyIndexQuery.exact(0, PointValue.MAX_VALUE);
        var e = assertThrows(UnsupportedOperationException.class, () -> reader.query(NULL_CONTEXT, new SimpleEntityValueClient(), constrained(unsupportedOrder, false), unsupportedQuery));
        assertThat(e.getMessage()).contains("unsupported order").contains(unsupportedOrder.toString()).contains(unsupportedQuery.toString());
    }
}
Also used : PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) IndexOrder(org.neo4j.internal.schema.IndexOrder) SimpleEntityValueClient(org.neo4j.storageengine.api.schema.SimpleEntityValueClient) Test(org.junit.jupiter.api.Test)

Aggregations

IndexOrder (org.neo4j.internal.schema.IndexOrder)4 PropertyIndexQuery (org.neo4j.internal.kernel.api.PropertyIndexQuery)3 SimpleEntityValueClient (org.neo4j.storageengine.api.schema.SimpleEntityValueClient)3 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 IndexOrderCapability (org.neo4j.internal.schema.IndexOrderCapability)2 IndexProgressor (org.neo4j.kernel.api.index.IndexProgressor)2 ValueIndexEntryUpdate (org.neo4j.storageengine.api.ValueIndexEntryUpdate)2 CoordinateReferenceSystem (org.neo4j.values.storable.CoordinateReferenceSystem)2 PointValue (org.neo4j.values.storable.PointValue)2 Value (org.neo4j.values.storable.Value)2 ValueType (org.neo4j.values.storable.ValueType)2 Values (org.neo4j.values.storable.Values)2 IOException (java.io.IOException)1