Search in sources :

Example 6 with InputNode

use of org.neo4j.unsafe.impl.batchimport.input.InputNode in project neo4j by neo4j.

the class CsvInputBatchImportIT method buildUpExpectedData.

private void buildUpExpectedData(List<InputNode> nodeData, List<InputRelationship> relationshipData, Map<String, InputNode> expectedNodes, Map<String, String[]> expectedNodeNames, Map<String, Map<String, Map<String, AtomicInteger>>> expectedRelationships, Map<String, AtomicLong> nodeCounts, Map<String, Map<String, Map<String, AtomicLong>>> relationshipCounts) {
    for (InputNode node : nodeData) {
        expectedNodes.put((String) node.id(), node);
        expectedNodeNames.put(nameOf(node), node.labels());
        countNodeLabels(nodeCounts, node.labels());
    }
    for (InputRelationship relationship : relationshipData) {
        // Expected relationship counts per node, type and direction
        InputNode startNode = expectedNodes.get(relationship.startNode());
        InputNode endNode = expectedNodes.get(relationship.endNode());
        {
            expectedRelationships.get(nameOf(startNode)).get(nameOf(endNode)).get(relationship.type()).incrementAndGet();
        }
        // Expected counts per start/end node label ids
        // Let's do what CountsState#addRelationship does, roughly
        relationshipCounts.get(null).get(null).get(null).incrementAndGet();
        relationshipCounts.get(null).get(relationship.type()).get(null).incrementAndGet();
        for (String startNodeLabelName : asSet(startNode.labels())) {
            Map<String, Map<String, AtomicLong>> startLabelCounts = relationshipCounts.get(startNodeLabelName);
            startLabelCounts.get(null).get(null).incrementAndGet();
            Map<String, AtomicLong> typeCounts = startLabelCounts.get(relationship.type());
            typeCounts.get(null).incrementAndGet();
            if (COMPUTE_DOUBLE_SIDED_RELATIONSHIP_COUNTS) {
                for (String endNodeLabelName : asSet(endNode.labels())) {
                    startLabelCounts.get(null).get(endNodeLabelName).incrementAndGet();
                    typeCounts.get(endNodeLabelName).incrementAndGet();
                }
            }
        }
        for (String endNodeLabelName : asSet(endNode.labels())) {
            relationshipCounts.get(null).get(null).get(endNodeLabelName).incrementAndGet();
            relationshipCounts.get(null).get(relationship.type()).get(endNodeLabelName).incrementAndGet();
        }
    }
}
Also used : InputNode(org.neo4j.unsafe.impl.batchimport.input.InputNode) AtomicLong(java.util.concurrent.atomic.AtomicLong) InputRelationship(org.neo4j.unsafe.impl.batchimport.input.InputRelationship) Map(java.util.Map) HashMap(java.util.HashMap) AutoCreatingHashMap(org.neo4j.kernel.impl.util.AutoCreatingHashMap)

Example 7 with InputNode

use of org.neo4j.unsafe.impl.batchimport.input.InputNode in project neo4j by neo4j.

the class CsvInputBatchImportIT method randomNodeData.

// ======================================================
// Below is code for generating import data
// ======================================================
private List<InputNode> randomNodeData() {
    List<InputNode> nodes = new ArrayList<>();
    for (int i = 0; i < 300; i++) {
        Object[] properties = new Object[] { "name", "Node " + i };
        String id = UUID.randomUUID().toString();
        nodes.add(new InputNode("source", i, i, id, properties, null, randomLabels(random), null));
    }
    return nodes;
}
Also used : InputNode(org.neo4j.unsafe.impl.batchimport.input.InputNode) ArrayList(java.util.ArrayList)

Example 8 with InputNode

use of org.neo4j.unsafe.impl.batchimport.input.InputNode in project neo4j by neo4j.

the class CsvInputTest method shouldProvideAdditiveLabels.

@Test
public void shouldProvideAdditiveLabels() throws Exception {
    // GIVEN
    String[] addedLabels = { "Two", "AddTwo" };
    DataFactory<InputNode> data = data(":ID,name,:LABEL\n" + "0,First,\n" + "1,Second,One\n" + "2,Third,One;Two", additiveLabels(addedLabels));
    Iterable<DataFactory<InputNode>> dataIterable = dataIterable(data);
    Input input = new CsvInput(dataIterable, defaultFormatNodeFileHeader(), null, null, IdType.ACTUAL, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
    // WHEN/THEN
    try (ResourceIterator<InputNode> nodes = input.nodes().iterator()) {
        assertNode(nodes.next(), 0L, properties("name", "First"), labels(addedLabels));
        assertNode(nodes.next(), 1L, properties("name", "Second"), labels(union(new String[] { "One" }, addedLabels)));
        assertNode(nodes.next(), 2L, properties("name", "Third"), labels(union(new String[] { "One" }, addedLabels)));
        assertFalse(nodes.hasNext());
    }
}
Also used : InputNode(org.neo4j.unsafe.impl.batchimport.input.InputNode) Input(org.neo4j.unsafe.impl.batchimport.input.Input) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 9 with InputNode

use of org.neo4j.unsafe.impl.batchimport.input.InputNode in project neo4j by neo4j.

the class CsvInputTest method shouldIgnoreEmptyPropertyValues.

@Test
public void shouldIgnoreEmptyPropertyValues() throws Exception {
    // GIVEN
    DataFactory<InputNode> data = data(":ID,name,extra\n" + // here we leave out "extra" property
    "0,Mattias,\n" + "1,Johan,Additional\n");
    Iterable<DataFactory<InputNode>> dataIterable = dataIterable(data);
    Input input = new CsvInput(dataIterable, defaultFormatNodeFileHeader(), null, null, IdType.ACTUAL, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
    // WHEN
    try (ResourceIterator<InputNode> nodes = input.nodes().iterator()) {
        // THEN
        assertNode(nodes.next(), 0L, new Object[] { "name", "Mattias" }, labels());
        assertNode(nodes.next(), 1L, new Object[] { "name", "Johan", "extra", "Additional" }, labels());
        assertFalse(nodes.hasNext());
    }
}
Also used : InputNode(org.neo4j.unsafe.impl.batchimport.input.InputNode) Input(org.neo4j.unsafe.impl.batchimport.input.Input) Test(org.junit.Test)

Example 10 with InputNode

use of org.neo4j.unsafe.impl.batchimport.input.InputNode in project neo4j by neo4j.

the class CsvInputTest method shouldIncludeDataSourceInformationOnBadFieldValueOrLine.

@Test
public void shouldIncludeDataSourceInformationOnBadFieldValueOrLine() throws Exception {
    // GIVEN
    Iterable<DataFactory<InputNode>> data = DataFactories.nodeData(CsvInputTest.<InputNode>data(":ID,name,other:int\n" + "1,Mattias,10\n" + "2,Johan,abc\n" + "3,Emil,12"));
    Input input = new CsvInput(data, DataFactories.defaultFormatNodeFileHeader(), null, null, IdType.INTEGER, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
    // WHEN
    try (InputIterator<InputNode> nodes = input.nodes().iterator()) {
        try {
            assertNode(nodes.next(), 1L, new Object[] { "name", "Mattias", "other", 10 }, labels());
            nodes.next();
            fail("Should have failed");
        } catch (InputException e) {
            // THEN
            assertThat(e.getMessage(), containsString("other"));
            assertThat(e.getMessage(), containsString("abc"));
        }
    }
}
Also used : InputNode(org.neo4j.unsafe.impl.batchimport.input.InputNode) Input(org.neo4j.unsafe.impl.batchimport.input.Input) InputException(org.neo4j.unsafe.impl.batchimport.input.InputException) Test(org.junit.Test)

Aggregations

InputNode (org.neo4j.unsafe.impl.batchimport.input.InputNode)42 Test (org.junit.Test)32 Input (org.neo4j.unsafe.impl.batchimport.input.Input)21 InputRelationship (org.neo4j.unsafe.impl.batchimport.input.InputRelationship)8 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)6 Collector (org.neo4j.unsafe.impl.batchimport.input.Collector)6 Groups (org.neo4j.unsafe.impl.batchimport.input.Groups)4 File (java.io.File)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 Matchers.anyString (org.mockito.Matchers.anyString)3 StatsProvider (org.neo4j.unsafe.impl.batchimport.stats.StatsProvider)3 StringReader (java.io.StringReader)2 Writer (java.io.Writer)2 CharReadable (org.neo4j.csv.reader.CharReadable)2 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)2 Transaction (org.neo4j.graphdb.Transaction)2 NeoStores (org.neo4j.kernel.impl.store.NeoStores)2