Search in sources :

Example 6 with IndexOrderCapability

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);
        }
    }
}
Also used : ValueType(org.neo4j.values.storable.ValueType) RandomValues(org.neo4j.values.storable.RandomValues) IndexOrderCapability(org.neo4j.internal.schema.IndexOrderCapability) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Example 7 with IndexOrderCapability

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());
}
Also used : IndexConfigCompleter(org.neo4j.internal.schema.IndexConfigCompleter) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) IndexCapability(org.neo4j.internal.schema.IndexCapability) MutableInt(org.apache.commons.lang3.mutable.MutableInt) SchemaRule(org.neo4j.internal.schema.SchemaRule) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) ConstraintDescriptorFactory.uniqueForLabel(org.neo4j.internal.schema.constraints.ConstraintDescriptorFactory.uniqueForLabel) ConstraintDescriptorFactory(org.neo4j.internal.schema.constraints.ConstraintDescriptorFactory) ArrayList(java.util.ArrayList) StandardConstraintRuleAccessor(org.neo4j.storageengine.api.StandardConstraintRuleAccessor) IndexConfigCompleter(org.neo4j.internal.schema.IndexConfigCompleter) Collections.singleton(java.util.Collections.singleton) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) SchemaDescriptor.forLabel(org.neo4j.internal.schema.SchemaDescriptor.forLabel) Iterables(org.neo4j.internal.helpers.collection.Iterables) Arrays.asList(java.util.Arrays.asList) SchemaDescriptor.forRelType(org.neo4j.internal.schema.SchemaDescriptor.forRelType) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SchemaDescriptor.fulltext(org.neo4j.internal.schema.SchemaDescriptor.fulltext) Iterator(java.util.Iterator) Iterators(org.neo4j.internal.helpers.collection.Iterators) ConstraintType(org.neo4j.internal.schema.ConstraintType) IndexOrderCapability(org.neo4j.internal.schema.IndexOrderCapability) Set(java.util.Set) ValueCategory(org.neo4j.values.storable.ValueCategory) Iterators.single(org.neo4j.internal.helpers.collection.Iterators.single) RELATIONSHIP(org.neo4j.common.EntityType.RELATIONSHIP) Test(org.junit.jupiter.api.Test) IndexValueCapability(org.neo4j.internal.schema.IndexValueCapability) List(java.util.List) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) Iterators.asSet(org.neo4j.internal.helpers.collection.Iterators.asSet) FulltextSchemaDescriptor(org.neo4j.internal.schema.FulltextSchemaDescriptor) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Collections(java.util.Collections) NODE(org.neo4j.common.EntityType.NODE) Race(org.neo4j.test.Race) ValueCategory(org.neo4j.values.storable.ValueCategory) ConstraintDescriptor(org.neo4j.internal.schema.ConstraintDescriptor) IndexCapability(org.neo4j.internal.schema.IndexCapability) ArrayList(java.util.ArrayList) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 8 with IndexOrderCapability

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);
        }
    }
}
Also used : PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) ValueType(org.neo4j.values.storable.ValueType) Value(org.neo4j.values.storable.Value) MutableLong(org.apache.commons.lang3.mutable.MutableLong) IndexOrderCapability(org.neo4j.internal.schema.IndexOrderCapability)

Example 9 with IndexOrderCapability

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);
    }
}
Also used : PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) IndexOrderCapability(org.neo4j.internal.schema.IndexOrderCapability) SimpleEntityValueClient(org.neo4j.storageengine.api.schema.SimpleEntityValueClient)

Example 10 with IndexOrderCapability

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);
        }
    }
}
Also used : IndexOrderCapability(org.neo4j.internal.schema.IndexOrderCapability) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) 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