Search in sources :

Example 31 with IndexReadSession

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

the class AbstractIndexQueryingTest method relationshipIndexSeekMustThrowOnWrongIndexEntityType.

@Test
void relationshipIndexSeekMustThrowOnWrongIndexEntityType() throws IndexNotFoundKernelException {
    IndexDescriptor index = schemaRead.indexGetForName("ftsNodes");
    IndexReadSession indexReadSession = read.indexReadSession(index);
    try (RelationshipValueIndexCursor cursor = cursors.allocateRelationshipValueIndexCursor(NULL, EmptyMemoryTracker.INSTANCE)) {
        assertThrows(IndexNotApplicableKernelException.class, () -> read.relationshipIndexSeek(indexReadSession, cursor, unconstrained(), PropertyIndexQuery.fulltextSearch("search")));
    }
}
Also used : RelationshipValueIndexCursor(org.neo4j.internal.kernel.api.RelationshipValueIndexCursor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Example 32 with IndexReadSession

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

the class NodeIndexTransactionStateTest method assertEntityAndValueForSeek.

@Override
void assertEntityAndValueForSeek(Set<Pair<Long, Value>> expected, KernelTransaction tx, IndexDescriptor index, boolean needsValues, Object anotherValueFoundByQuery, PropertyIndexQuery... queries) throws Exception {
    try (NodeValueIndexCursor nodes = tx.cursors().allocateNodeValueIndexCursor(tx.cursorContext(), tx.memoryTracker())) {
        IndexReadSession indexSession = tx.dataRead().indexReadSession(index);
        tx.dataRead().nodeIndexSeek(indexSession, nodes, unordered(needsValues), queries);
        assertEntityAndValue(expected, tx, needsValues, anotherValueFoundByQuery, new NodeCursorAdapter(nodes));
    }
}
Also used : NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession)

Example 33 with IndexReadSession

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

the class IndexOrderTestBase method shouldNodeIndexScanInOrderWithPointsAndSingleNodeAfterwards.

@ParameterizedTest
@EnumSource(value = IndexOrder.class, names = { "ASCENDING", "DESCENDING" })
void shouldNodeIndexScanInOrderWithPointsAndSingleNodeAfterwards(IndexOrder indexOrder) throws Exception {
    List<Pair<Long, Value>> expected = new ArrayList<>();
    try (KernelTransaction tx = beginTransaction()) {
        // NOTE: strings come after points in natural ascending sort order
        expected.add(entityWithProp(tx, "a"));
        expected.add(entityWithProp(tx, pointValue(Cartesian, -500000, -500000)));
        expected.add(entityWithProp(tx, pointValue(Cartesian, 500000, -500000)));
        expected.add(entityWithProp(tx, pointValue(Cartesian, -500000, 500000)));
        expected.add(entityWithProp(tx, pointValue(Cartesian, 500000, 500000)));
        tx.commit();
    }
    createIndex();
    // when
    try (KernelTransaction tx = beginTransaction()) {
        IndexReadSession index = tx.dataRead().indexReadSession(tx.schemaRead().indexGetForName(INDEX_NAME));
        try (var cursor = getEntityValueIndexCursor(tx)) {
            expected.add(entityWithProp(tx, pointValue(Cartesian, -400000, -400000)));
            expected.add(entityWithProp(tx, pointValue(Cartesian, 400000, -400000)));
            expected.add(entityWithProp(tx, pointValue(Cartesian, -400000, 400000)));
            expected.add(entityWithProp(tx, pointValue(Cartesian, 400000, 400000)));
            expected.add(entityWithProp(tx, "b"));
            entityIndexScan(tx, index, cursor, constrained(indexOrder, true));
            assertResultsInOrder(expected, cursor, indexOrder);
        }
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ArrayList(java.util.ArrayList) Pair(org.neo4j.internal.helpers.collection.Pair) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 34 with IndexReadSession

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

the class IndexOrderTestBase method shouldNodeIndexScanInOrderWithPointsAndNodesOnBothSides.

@ParameterizedTest
@EnumSource(value = IndexOrder.class, names = { "ASCENDING", "DESCENDING" })
void shouldNodeIndexScanInOrderWithPointsAndNodesOnBothSides(IndexOrder indexOrder) throws Exception {
    List<Pair<Long, Value>> expected = new ArrayList<>();
    try (KernelTransaction tx = beginTransaction()) {
        // NOTE: arrays come before points in natural ascending sort order
        expected.add(entityWithProp(tx, new String[] { "a" }));
        expected.add(entityWithProp(tx, new String[] { "b" }));
        expected.add(entityWithProp(tx, new String[] { "c" }));
        // NOTE: strings come after points in natural ascending sort order
        expected.add(entityWithProp(tx, "a"));
        expected.add(entityWithProp(tx, "b"));
        expected.add(entityWithProp(tx, "c"));
        expected.add(entityWithProp(tx, pointValue(Cartesian, -500000, -500000)));
        expected.add(entityWithProp(tx, pointValue(Cartesian, 500000, -500000)));
        expected.add(entityWithProp(tx, pointValue(Cartesian, -500000, 500000)));
        expected.add(entityWithProp(tx, pointValue(Cartesian, 500000, 500000)));
        tx.commit();
    }
    createIndex();
    // when
    try (KernelTransaction tx = beginTransaction()) {
        IndexReadSession index = tx.dataRead().indexReadSession(tx.schemaRead().indexGetForName(INDEX_NAME));
        try (var cursor = getEntityValueIndexCursor(tx)) {
            expected.add(entityWithProp(tx, pointValue(Cartesian, -400000, -400000)));
            expected.add(entityWithProp(tx, pointValue(Cartesian, 400000, -400000)));
            expected.add(entityWithProp(tx, pointValue(Cartesian, -400000, 400000)));
            expected.add(entityWithProp(tx, pointValue(Cartesian, 400000, 400000)));
            expected.add(entityWithProp(tx, new String[] { "d" }));
            expected.add(entityWithProp(tx, "d"));
            entityIndexScan(tx, index, cursor, constrained(indexOrder, true));
            assertResultsInOrder(expected, cursor, indexOrder);
        }
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ArrayList(java.util.ArrayList) Pair(org.neo4j.internal.helpers.collection.Pair) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 35 with IndexReadSession

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

the class IndexOrderTestBase method shouldDoOrderedCompositeIndexScanWithPointsInBothValuesWithOneGapBetween.

@ParameterizedTest
@EnumSource(value = IndexOrder.class, names = { "ASCENDING", "DESCENDING" })
void shouldDoOrderedCompositeIndexScanWithPointsInBothValuesWithOneGapBetween(IndexOrder indexOrder) throws Exception {
    List<Pair<Long, Value[]>> expected = new ArrayList<>();
    try (KernelTransaction tx = beginTransaction()) {
        expected.add(entityWithTwoProps(tx, new String[] { "a" }, new String[] { "b" }));
        expected.add(entityWithTwoProps(tx, pointValue(Cartesian, -500000, -500000), "a"));
        expected.add(entityWithTwoProps(tx, pointValue(Cartesian, 500000, -500000), "a"));
        expected.add(entityWithTwoProps(tx, pointValue(Cartesian, -500000, 500000), "a"));
        expected.add(entityWithTwoProps(tx, pointValue(Cartesian, 500000, 500000), "a"));
        expected.add(entityWithTwoProps(tx, "b", new String[] { "b" }));
        expected.add(entityWithTwoProps(tx, "b", pointValue(Cartesian, -500000, -500000)));
        expected.add(entityWithTwoProps(tx, "b", pointValue(Cartesian, 500000, -500000)));
        expected.add(entityWithTwoProps(tx, "b", pointValue(Cartesian, -500000, 500000)));
        expected.add(entityWithTwoProps(tx, "b", pointValue(Cartesian, 500000, 500000)));
        expected.add(entityWithTwoProps(tx, "c", new String[] { "b" }));
        tx.commit();
    }
    createCompositeIndex();
    // when
    try (KernelTransaction tx = beginTransaction()) {
        IndexReadSession index = tx.dataRead().indexReadSession(tx.schemaRead().indexGetForName(INDEX_NAME));
        try (var cursor = getEntityValueIndexCursor(tx)) {
            entityIndexScan(tx, index, cursor, constrained(indexOrder, true));
            assertCompositeResultsInOrder(expected, cursor, indexOrder);
        }
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Value(org.neo4j.values.storable.Value) Values.pointValue(org.neo4j.values.storable.Values.pointValue) TextValue(org.neo4j.values.storable.TextValue) Values.stringValue(org.neo4j.values.storable.Values.stringValue) PointValue(org.neo4j.values.storable.PointValue) ArrayList(java.util.ArrayList) Pair(org.neo4j.internal.helpers.collection.Pair) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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