Search in sources :

Example 1 with Pair

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

the class TxStateTest method addNodesToIndex.

private IndexUpdater addNodesToIndex(final IndexDescriptor descriptor) {
    return new IndexUpdater() {

        @Override
        public void withDefaultStringProperties(long... nodeIds) {
            Collection<Pair<Long, String>> entries = new ArrayList<>(nodeIds.length);
            for (long nodeId : nodeIds) {
                entries.add(of(nodeId, "value" + nodeId));
            }
            withProperties(entries);
        }

        private <T> void withProperties(Collection<Pair<Long, T>> nodesWithValues) {
            SchemaDescriptor schema = descriptor.schema();
            int[] labelIds = schema.getEntityTokenIds();
            int[] propertyKeyIds = schema.getPropertyIds();
            assertEquals(1, labelIds.length);
            assertEquals(1, propertyKeyIds.length);
            for (Pair<Long, T> entry : nodesWithValues) {
                long nodeId = entry.first();
                state.nodeDoCreate(nodeId);
                state.nodeDoAddLabel(labelIds[0], nodeId);
                Value valueAfter = Values.of(entry.other());
                state.nodeDoAddProperty(nodeId, propertyKeyIds[0], valueAfter);
                state.indexDoUpdateEntry(schema, nodeId, null, ValueTuple.of(valueAfter));
            }
        }
    };
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) LabelSchemaDescriptor(org.neo4j.internal.schema.LabelSchemaDescriptor) ArrayList(java.util.ArrayList) Value(org.neo4j.values.storable.Value) Values.stringValue(org.neo4j.values.storable.Values.stringValue) Collection(java.util.Collection) Pair(org.neo4j.internal.helpers.collection.Pair)

Example 2 with Pair

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

the class CsvInputBatchImportIT method allNodeCounts.

private Iterable<Pair<Integer, Long>> allNodeCounts(Function<String, Integer> labelTranslationTable, Map<String, AtomicLong> counts) {
    Collection<Pair<Integer, Long>> result = new ArrayList<>();
    for (Map.Entry<String, AtomicLong> count : counts.entrySet()) {
        result.add(Pair.of(labelTranslationTable.apply(count.getKey()), count.getValue().get()));
    }
    counts.put(null, new AtomicLong(counts.size()));
    return result;
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) AutoCreatingHashMap(org.neo4j.kernel.impl.util.AutoCreatingHashMap) Pair(org.neo4j.internal.helpers.collection.Pair)

Example 3 with Pair

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

the class OrderedByTypeExpander method doExpand.

@Override
ResourceIterator<Relationship> doExpand(final Path path, BranchState state) {
    final Node node = path.endNode();
    return new NestingResourceIterator<>(orderedTypes.iterator()) {

        @Override
        protected ResourceIterator<Relationship> createNestedIterator(Pair<RelationshipType, Direction> entry) {
            RelationshipType type = entry.first();
            Direction dir = entry.other();
            Iterable<Relationship> relationshipsIterable = (dir == Direction.BOTH) ? node.getRelationships(type) : node.getRelationships(dir, type);
            return Iterables.asResourceIterable(relationshipsIterable).iterator();
        }
    };
}
Also used : NestingResourceIterator(org.neo4j.internal.helpers.collection.NestingResourceIterator) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) RelationshipType(org.neo4j.graphdb.RelationshipType) Direction(org.neo4j.graphdb.Direction) Pair(org.neo4j.internal.helpers.collection.Pair)

Example 4 with Pair

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

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

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