Search in sources :

Example 6 with Group

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));
    }
}
Also used : Group(org.neo4j.internal.batchimport.input.Group) InputIterator(org.neo4j.internal.batchimport.InputIterator) Input(org.neo4j.internal.batchimport.input.Input) Groups(org.neo4j.internal.batchimport.input.Groups) IdType(org.neo4j.internal.batchimport.input.IdType) Test(org.junit.Test)

Example 7 with Group

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);
}
Also used : Group(org.neo4j.internal.batchimport.input.Group)

Example 8 with Group

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);
}
Also used : Group(org.neo4j.internal.batchimport.input.Group)

Aggregations

Group (org.neo4j.internal.batchimport.input.Group)8 Test (org.junit.Test)6 PropertyValueLookup (org.neo4j.internal.batchimport.PropertyValueLookup)4 IdMapper (org.neo4j.internal.batchimport.cache.idmapping.IdMapper)4 Collector (org.neo4j.internal.batchimport.input.Collector)4 Groups (org.neo4j.internal.batchimport.input.Groups)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 InputIterator (org.neo4j.internal.batchimport.InputIterator)2 IdType (org.neo4j.internal.batchimport.input.IdType)2 Math.toIntExact (java.lang.Math.toIntExact)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Random (java.util.Random)1 Set (java.util.Set)1 UUID (java.util.UUID)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 LongFunction (java.util.function.LongFunction)1