Search in sources :

Example 26 with Pair

use of org.neo4j.internal.helpers.collection.Pair in project neo4j by neo4j.

the class AllNodesInStoreExistInLabelIndexTest method someData.

private List<Pair<Long, Label[]>> someData(int numberOfModifications) {
    List<Pair<Long, Label[]>> existingNodes;
    existingNodes = new ArrayList<>();
    try (Transaction tx = db.beginTx()) {
        randomModifications(tx, existingNodes, numberOfModifications);
        tx.commit();
    }
    return existingNodes;
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Label(org.neo4j.graphdb.Label) Pair(org.neo4j.internal.helpers.collection.Pair)

Example 27 with Pair

use of org.neo4j.internal.helpers.collection.Pair in project neo4j by neo4j.

the class IndexOrderTestBase method shouldNodeIndexScanInOrderPointsOnly.

@ParameterizedTest
@EnumSource(value = IndexOrder.class, names = { "ASCENDING", "DESCENDING" })
void shouldNodeIndexScanInOrderPointsOnly(IndexOrder indexOrder) throws Exception {
    List<Pair<Long, Value>> expected = new ArrayList<>();
    try (KernelTransaction tx = beginTransaction()) {
        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)));
            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 28 with Pair

use of org.neo4j.internal.helpers.collection.Pair in project neo4j by neo4j.

the class IndexOrderTestBase method assertResultsInOrder.

protected void assertResultsInOrder(List<Pair<Long, Value>> expected, ENTITY_VALUE_INDEX_CURSOR cursor, IndexOrder indexOrder) {
    Comparator<Pair<Long, Value>> comparator = indexOrder == IndexOrder.ASCENDING ? (a, b) -> Values.COMPARATOR.compare(a.other(), b.other()) : (a, b) -> Values.COMPARATOR.compare(b.other(), a.other());
    expected.sort(comparator);
    Iterator<Pair<Long, Value>> expectedRows = expected.iterator();
    while (cursor.next() && expectedRows.hasNext()) {
        Pair<Long, Value> expectedRow = expectedRows.next();
        assertThat(entityReference(cursor)).as(expectedRow.other() + " == " + cursor.propertyValue(0)).isEqualTo(expectedRow.first());
        for (int i = 0; i < cursor.numberOfProperties(); i++) {
            Value value = cursor.propertyValue(i);
            assertThat(value).isEqualTo(expectedRow.other());
        }
    }
    assertFalse(expectedRows.hasNext());
    assertFalse(cursor.next());
}
Also used : 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) Pair(org.neo4j.internal.helpers.collection.Pair)

Example 29 with Pair

use of org.neo4j.internal.helpers.collection.Pair in project neo4j by neo4j.

the class IndexOrderTestBase method shouldNodeCompositeIndexScanInOrderWithPointsAndSingleNodeAfterwards.

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

Example 30 with Pair

use of org.neo4j.internal.helpers.collection.Pair 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)

Aggregations

Pair (org.neo4j.internal.helpers.collection.Pair)39 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)22 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)22 ArrayList (java.util.ArrayList)15 HashSet (java.util.HashSet)12 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)12 EnumSource (org.junit.jupiter.params.provider.EnumSource)11 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)11 ValueSource (org.junit.jupiter.params.provider.ValueSource)9 TextValue (org.neo4j.values.storable.TextValue)9 PointValue (org.neo4j.values.storable.PointValue)8 Value (org.neo4j.values.storable.Value)8 Values.stringValue (org.neo4j.values.storable.Values.stringValue)8 Values.pointValue (org.neo4j.values.storable.Values.pointValue)7 Test (org.junit.jupiter.api.Test)6 HashMap (java.util.HashMap)5 Label (org.neo4j.graphdb.Label)5 Path (java.nio.file.Path)4 Transaction (org.neo4j.graphdb.Transaction)4 Map (java.util.Map)3