Search in sources :

Example 76 with IndexReadSession

use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.

the class EntityValueIndexCursorTestBase method shouldPerformTextArraySearch.

@Test
void shouldPerformTextArraySearch() throws KernelException {
    // given
    boolean needsValues = indexParams.indexProvidesArrayValues();
    IndexQueryConstraints constraints = unordered(needsValues);
    int prop = token.propertyKey(PROP_NAME);
    IndexReadSession index = read.indexReadSession(schemaRead.indexGetForName(PROP_INDEX_NAME));
    IndexValueCapability capability = index.reference().getCapability().valueCapability(ValueGroup.TEXT_ARRAY.category());
    try (var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
        MutableLongSet uniqueIds = new LongHashSet();
        // when
        entityParams.entityIndexSeek(tx, index, cursor, constraints, PropertyIndexQuery.exact(prop, new String[] { "first", "second", "third" }));
        // then
        assertFoundEntitiesAndValue(cursor, 1, uniqueIds, capability, needsValues);
        // when
        entityParams.entityIndexSeek(tx, index, cursor, constraints, PropertyIndexQuery.exact(prop, new String[] { "fourth", "fifth", "sixth", "seventh" }));
        // then
        assertFoundEntitiesAndValue(cursor, 1, uniqueIds, capability, needsValues);
    }
}
Also used : LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) IndexQueryConstraints(org.neo4j.internal.kernel.api.IndexQueryConstraints) IndexValueCapability(org.neo4j.internal.schema.IndexValueCapability) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Example 77 with IndexReadSession

use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.

the class EntityValueIndexCursorTestBase method shouldNotFindDeletedEntityInCompositeIndex.

@Test
void shouldNotFindDeletedEntityInCompositeIndex() throws Exception {
    // Given
    boolean needsValues = false;
    int firstName = token.propertyKey(FIRSTNAME_PROP_NAME);
    int surname = token.propertyKey(SURNAME_PROP_NAME);
    IndexReadSession index = read.indexReadSession(schemaRead.indexGetForName(COMPOSITE_INDEX_NAME));
    try (KernelTransaction tx = beginTransaction();
        var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
        // when
        entityParams.entityDelete(tx, jackDalton);
        entityParams.entityIndexSeek(tx, index, cursor, unordered(needsValues), PropertyIndexQuery.exact(firstName, "Jack"), PropertyIndexQuery.exact(surname, "Dalton"));
        // then
        assertFalse(cursor.next());
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Example 78 with IndexReadSession

use of org.neo4j.internal.kernel.api.IndexReadSession 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)

Example 79 with IndexReadSession

use of org.neo4j.internal.kernel.api.IndexReadSession 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 80 with IndexReadSession

use of org.neo4j.internal.kernel.api.IndexReadSession in project neo4j by neo4j.

the class EntityValueIndexCursorTestBase method shouldProvideValuesForAllTypes.

@Test
void shouldProvideValuesForAllTypes() throws Exception {
    // given
    assumeTrue(indexParams.indexProvidesAllValues());
    int prop = token.propertyKey(EVER_PROP_NAME);
    IndexReadSession index = read.indexReadSession(schemaRead.indexGetForName(WHAT_EVER_INDEX_NAME));
    IndexValueCapability valueCapability = index.reference().getCapability().valueCapability(ValueCategory.UNKNOWN);
    assertEquals(IndexValueCapability.YES, valueCapability);
    try (var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
        MutableLongSet uniqueIds = new LongHashSet();
        // when
        entityParams.entityIndexSeek(tx, index, cursor, unorderedValues(), PropertyIndexQuery.exists(prop));
        // then
        assertFoundEntitiesAndValue(cursor, uniqueIds, valueCapability, true, entitiesOfAllPropertyTypes);
    }
}
Also used : LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) IndexValueCapability(org.neo4j.internal.schema.IndexValueCapability) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Aggregations

IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)93 Test (org.junit.jupiter.api.Test)62 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)47 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)22 NodeValueIndexCursor (org.neo4j.internal.kernel.api.NodeValueIndexCursor)20 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)17 LongHashSet (org.eclipse.collections.impl.set.mutable.primitive.LongHashSet)15 ArrayList (java.util.ArrayList)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 EnumSource (org.junit.jupiter.params.provider.EnumSource)12 RelationshipValueIndexCursor (org.neo4j.internal.kernel.api.RelationshipValueIndexCursor)12 IndexValueCapability (org.neo4j.internal.schema.IndexValueCapability)12 Pair (org.neo4j.internal.helpers.collection.Pair)11 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)10 Transaction (org.neo4j.graphdb.Transaction)9 IndexQueryConstraints (org.neo4j.internal.kernel.api.IndexQueryConstraints)9 IndexOrderCapability (org.neo4j.internal.schema.IndexOrderCapability)7 Read (org.neo4j.internal.kernel.api.Read)6 TokenRead (org.neo4j.internal.kernel.api.TokenRead)6 PropertyIndexQuery (org.neo4j.internal.kernel.api.PropertyIndexQuery)5