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));
}
}
};
}
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;
}
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();
}
};
}
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);
}
}
}
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);
}
}
}
Aggregations