use of org.neo4j.internal.batchimport.input.Group in project neo4j by neo4j.
the class CsvInputTest method shouldHaveNodesBelongToGroupSpecifiedInHeader.
@Test
public void shouldHaveNodesBelongToGroupSpecifiedInHeader() throws Exception {
// GIVEN
IdType idType = IdType.INTEGER;
Iterable<DataFactory> data = dataIterable(data("123,one\n" + "456,two"));
Groups groups = new Groups();
Group group = groups.getOrCreate("MyGroup");
Input input = new CsvInput(data, header(entry(null, Type.ID, group.name(), CsvInput.idExtractor(idType, extractors)), entry("name", Type.PROPERTY, extractors.string())), datas(), defaultFormatRelationshipFileHeader(), idType, config(), NO_MONITOR, INSTANCE);
// WHEN/THEN
try (InputIterator nodes = input.nodes(EMPTY).iterator()) {
assertNextNode(nodes, group, 123L, properties("name", "one"), labels());
assertNextNode(nodes, group, 456L, properties("name", "two"), labels());
assertFalse(readNext(nodes));
}
}
use of org.neo4j.internal.batchimport.input.Group in project neo4j by neo4j.
the class ParallelBatchImporterTest method nodes.
private InputIterable nodes(final long randomSeed, final long count, int batchSize, final InputIdGenerator inputIdGenerator, final IdGroupDistribution groups, LongAdder propertyCount) {
return () -> new GeneratingInputIterator<>(count, batchSize, new RandomsStates(randomSeed), (randoms, visitor, id) -> {
Object nodeId = inputIdGenerator.nextNodeId(randoms, id);
Group group = groups.groupOf(id);
visitor.id(nodeId, group);
propertyCount.add(randomProperties(randoms, uniqueId(group, nodeId), visitor));
visitor.labels(randoms.selection(TOKENS, 0, TOKENS.length, true));
}, 0);
}
use of org.neo4j.internal.batchimport.input.Group in project neo4j by neo4j.
the class ParallelBatchImporterTest method relationships.
private InputIterable relationships(final long randomSeed, final long count, int batchSize, final InputIdGenerator idGenerator, final IdGroupDistribution groups, LongAdder propertyCount, LongAdder relationshipCount) {
return () -> new GeneratingInputIterator<>(count, batchSize, new RandomsStates(randomSeed), (randoms, visitor, id) -> {
int thisPropertyCount = randomProperties(randoms, "Name " + id, visitor);
ExistingId startNodeExistingId = idGenerator.randomExisting(randoms);
Group startNodeGroup = groups.groupOf(startNodeExistingId.nodeIndex);
ExistingId endNodeExistingId = idGenerator.randomExisting(randoms);
Group endNodeGroup = groups.groupOf(endNodeExistingId.nodeIndex);
// miss some
Object startNode = idGenerator.miss(randoms, startNodeExistingId.id, 0.001f);
Object endNode = idGenerator.miss(randoms, endNodeExistingId.id, 0.001f);
if (!inputIdGenerator.isMiss(startNode) && !inputIdGenerator.isMiss(endNode)) {
relationshipCount.increment();
propertyCount.add(thisPropertyCount);
}
visitor.startId(startNode, startNodeGroup);
visitor.endId(endNode, endNodeGroup);
String type = InputIdGenerator.randomType(randoms);
if (randoms.nextFloat() < 0.00005) {
// Let there be a small chance of introducing a one-off relationship
// with a type that no, or at least very few, other relationships have.
type += "_odd";
}
visitor.type(type);
}, 0);
}
Aggregations