Search in sources :

Example 61 with IndexReadSession

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

the class IndexOrderTestBase method shouldRangeScanInOrderWithTxState.

@ParameterizedTest
@EnumSource(value = IndexOrder.class, names = { "ASCENDING", "DESCENDING" })
void shouldRangeScanInOrderWithTxState(IndexOrder indexOrder) throws Exception {
    List<Pair<Long, Value>> expected = new ArrayList<>();
    try (KernelTransaction tx = beginTransaction()) {
        expected.add(entityWithProp(tx, "hello"));
        entityWithProp(tx, "bellow");
        expected.add(entityWithProp(tx, "schmello"));
        expected.add(entityWithProp(tx, "low"));
        expected.add(entityWithProp(tx, "trello"));
        entityWithProp(tx, "yellow");
        expected.add(entityWithProp(tx, "loww"));
        entityWithProp(tx, "below");
        tx.commit();
    }
    createIndex();
    // when
    try (KernelTransaction tx = beginTransaction()) {
        int prop = tx.tokenRead().propertyKey(DEFAULT_PROPERTY_NAME);
        IndexReadSession index = tx.dataRead().indexReadSession(tx.schemaRead().indexGetForName(INDEX_NAME));
        try (var cursor = getEntityValueIndexCursor(tx)) {
            entityWithProp(tx, "allow");
            expected.add(entityWithProp(tx, "now"));
            expected.add(entityWithProp(tx, "jello"));
            entityWithProp(tx, "willow");
            PropertyIndexQuery query = PropertyIndexQuery.range(prop, "hello", true, "trello", true);
            entityIndexSeek(tx, index, cursor, constrained(indexOrder, true), query);
            assertResultsInOrder(expected, cursor, indexOrder);
        }
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) 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 62 with IndexReadSession

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

the class IndexOrderTestBase method shouldDoOrderedCompositeIndexScanWithPointsInBothValues.

@ParameterizedTest
@EnumSource(value = IndexOrder.class, names = { "ASCENDING", "DESCENDING" })
void shouldDoOrderedCompositeIndexScanWithPointsInBothValues(IndexOrder indexOrder) throws Exception {
    List<Pair<Long, Value[]>> expected = new ArrayList<>();
    try (KernelTransaction tx = beginTransaction()) {
        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, pointValue(Cartesian, -500000, -500000), "b"));
        expected.add(entityWithTwoProps(tx, pointValue(Cartesian, 500000, -500000), "b"));
        expected.add(entityWithTwoProps(tx, pointValue(Cartesian, -500000, 500000), "b"));
        expected.add(entityWithTwoProps(tx, pointValue(Cartesian, 500000, 500000), "b"));
        expected.add(entityWithTwoProps(tx, "a", pointValue(Cartesian, -500000, -500000)));
        expected.add(entityWithTwoProps(tx, "a", pointValue(Cartesian, 500000, -500000)));
        expected.add(entityWithTwoProps(tx, "a", pointValue(Cartesian, -500000, 500000)));
        expected.add(entityWithTwoProps(tx, "a", pointValue(Cartesian, 500000, 500000)));
        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)

Example 63 with IndexReadSession

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

the class IndexOrderTestBase method shouldNodeIndexScanInOrderWithPointsAndNodesBefore.

@ParameterizedTest
@EnumSource(value = IndexOrder.class, names = { "ASCENDING", "DESCENDING" })
void shouldNodeIndexScanInOrderWithPointsAndNodesBefore(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" }));
        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" }));
            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 64 with IndexReadSession

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

the class NodeIndexTransactionStateTest method assertEntityAndValueForScan.

@Override
void assertEntityAndValueForScan(Set<Pair<Long, Value>> expected, KernelTransaction tx, IndexDescriptor index, boolean needsValues, Object anotherValueFoundByQuery) throws Exception {
    IndexReadSession indexSession = tx.dataRead().indexReadSession(index);
    try (NodeValueIndexCursor nodes = tx.cursors().allocateNodeValueIndexCursor(tx.cursorContext(), tx.memoryTracker())) {
        tx.dataRead().nodeIndexScan(indexSession, nodes, unordered(needsValues));
        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 65 with IndexReadSession

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

the class IndexOrderTestBase method shouldPrefixScanInOrder.

@ParameterizedTest
@EnumSource(value = IndexOrder.class, names = { "ASCENDING", "DESCENDING" })
void shouldPrefixScanInOrder(IndexOrder indexOrder) throws Exception {
    List<Pair<Long, Value>> expected = new ArrayList<>();
    try (KernelTransaction tx = beginTransaction()) {
        expected.add(entityWithProp(tx, "bee hive"));
        entityWithProp(tx, "a");
        expected.add(entityWithProp(tx, "become"));
        expected.add(entityWithProp(tx, "be"));
        expected.add(entityWithProp(tx, "bachelor"));
        entityWithProp(tx, "street smart");
        expected.add(entityWithProp(tx, "builder"));
        entityWithProp(tx, "ceasar");
        tx.commit();
    }
    createIndex();
    // when
    try (KernelTransaction tx = beginTransaction()) {
        int prop = tx.tokenRead().propertyKey(DEFAULT_PROPERTY_NAME);
        IndexReadSession index = tx.dataRead().indexReadSession(tx.schemaRead().indexGetForName(INDEX_NAME));
        try (var cursor = getEntityValueIndexCursor(tx)) {
            entityWithProp(tx, "allow");
            expected.add(entityWithProp(tx, "bastard"));
            expected.add(entityWithProp(tx, "bully"));
            entityWithProp(tx, "willow");
            PropertyIndexQuery query = PropertyIndexQuery.stringPrefix(prop, stringValue("b"));
            entityIndexSeek(tx, index, cursor, constrained(indexOrder, true), query);
            assertResultsInOrder(expected, cursor, indexOrder);
        }
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) PropertyIndexQuery(org.neo4j.internal.kernel.api.PropertyIndexQuery) 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