Search in sources :

Example 11 with IndexReadSession

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

the class EntityValueIndexCursorTestBase method shouldNotFindEntityWithRemovedTokenInIndexSeek.

@Test
void shouldNotFindEntityWithRemovedTokenInIndexSeek() throws Exception {
    assumeTrue(entityParams.tokenlessEntitySupported());
    // Given
    boolean needsValues = false;
    int label = entityParams.entityTokenId(tx, DEFAULT_ENTITY_TOKEN);
    int prop = token.propertyKey(PROP_NAME);
    IndexReadSession index = read.indexReadSession(schemaRead.indexGetForName(PROP_INDEX_NAME));
    try (KernelTransaction tx = beginTransaction();
        var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
        // when
        entityParams.entityRemoveToken(tx, strOne, label);
        entityParams.entityIndexSeek(tx, index, cursor, unordered(needsValues), PropertyIndexQuery.exact(prop, "one"));
        // 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 12 with IndexReadSession

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

the class EntityValueIndexCursorTestBase method shouldHandleOrderedExactSeekWithNeedsValuesTrueWithTxChanges.

@Test
void shouldHandleOrderedExactSeekWithNeedsValuesTrueWithTxChanges() throws Exception {
    // given
    int prop = token.propertyKey("prop");
    IndexReadSession index = tx.dataRead().indexReadSession(tx.schemaRead().indexGetForName(PROP_INDEX_NAME));
    int label = entityParams.entityTokenId(tx, DEFAULT_ENTITY_TOKEN);
    try (KernelTransaction tx = beginTransaction();
        var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
        // when
        long newEntity = entityParams.entityCreateNew(tx, label);
        entityParams.entitySetProperty(tx, newEntity, prop, intValue(5));
        entityParams.entityIndexSeek(tx, index, cursor, constrained(IndexOrder.ASCENDING, true), PropertyIndexQuery.exact(prop, 5));
        // then
        assertTrue(cursor.next());
        assertTrue(cursor.hasValue());
        assertEquals(cursor.propertyValue(0), intValue(5));
        assertTrue(cursor.next());
        assertTrue(cursor.hasValue());
        assertEquals(cursor.propertyValue(0), intValue(5));
        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 13 with IndexReadSession

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

the class EntityValueIndexCursorTestBase method shouldFindSwappedEntityInIndexSeek.

@Test
void shouldFindSwappedEntityInIndexSeek() throws Exception {
    assumeTrue(entityParams.tokenlessEntitySupported());
    // Given
    boolean needsValues = false;
    int label = entityParams.entityTokenId(tx, DEFAULT_ENTITY_TOKEN);
    int prop = token.propertyKey(PROP_NAME);
    IndexReadSession index = read.indexReadSession(schemaRead.indexGetForName(PROP_INDEX_NAME));
    try (KernelTransaction tx = beginTransaction();
        var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
        // when
        entityParams.entityRemoveToken(tx, strOne, label);
        entityParams.entityAddToken(tx, strOneNoLabel, label);
        entityParams.entityIndexSeek(tx, index, cursor, unordered(needsValues), PropertyIndexQuery.exact(prop, "one"));
        // then
        assertTrue(cursor.next());
        assertEquals(strOneNoLabel, entityParams.entityReference(cursor));
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Example 14 with IndexReadSession

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

the class EntityValueIndexCursorTestBase method shouldPerformSpatialRangeSearch.

@Test
void shouldPerformSpatialRangeSearch() throws KernelException {
    // given
    boolean needsValues = indexParams.indexProvidesSpatialValues();
    IndexQueryConstraints constraints = unordered(needsValues);
    int prop = token.propertyKey(PROP_NAME);
    IndexReadSession index = read.indexReadSession(schemaRead.indexGetForName(PROP_INDEX_NAME));
    IndexValueCapability spatialCapability = index.reference().getCapability().valueCapability(ValueCategory.GEOMETRY);
    try (var cursor = entityParams.allocateEntityValueIndexCursor(tx, cursors)) {
        MutableLongSet uniqueIds = new LongHashSet();
        // when
        entityParams.entityIndexSeek(tx, index, cursor, constraints, PropertyIndexQuery.range(prop, Cartesian));
        // then
        assertFoundEntitiesAndValue(cursor, 5, uniqueIds, spatialCapability, needsValues);
        // when
        entityParams.entityIndexSeek(tx, index, cursor, constraints, PropertyIndexQuery.range(prop, Cartesian_3D));
        // then
        assertFoundEntitiesAndValue(cursor, 1, uniqueIds, spatialCapability, needsValues);
        // when
        entityParams.entityIndexSeek(tx, index, cursor, constraints, PropertyIndexQuery.range(prop, WGS84));
        // then
        assertFoundEntitiesAndValue(cursor, 1, uniqueIds, spatialCapability, needsValues);
        // when
        entityParams.entityIndexSeek(tx, index, cursor, constraints, PropertyIndexQuery.range(prop, WGS84_3D));
        // then
        assertFoundEntitiesAndValue(cursor, 1, uniqueIds, spatialCapability, 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 15 with IndexReadSession

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

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