Search in sources :

Example 6 with InputRelationship

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

the class CalculateDenseNodesStepTest method shouldCollectBadRelationships.

@Test
public void shouldCollectBadRelationships() throws Exception {
    // GIVEN
    NodeRelationshipCache cache = mock(NodeRelationshipCache.class);
    Collector collector = mock(Collector.class);
    try (CalculateDenseNodesStep step = new CalculateDenseNodesStep(mock(StageControl.class), DEFAULT, cache, collector)) {
        step.processors(4);
        step.start(0);
        // WHEN
        Batch<InputRelationship, RelationshipRecord> batch = batch(relationship(1, 5), relationship(3, 10), // <-- bad relationship with missing start node
        relationship("a", 2, -1, 2), // <-- bad relationship with missing end node
        relationship(2, "b", 2, -1), // <-- bad relationship with missing start and end node
        relationship("c", "d", -1, -1));
        step.receive(0, batch);
        step.endOfUpstream();
        while (!step.isCompleted()) {
        //wait
        }
        // THEN
        verify(collector, times(1)).collectBadRelationship(any(InputRelationship.class), eq("a"));
        verify(collector, times(1)).collectBadRelationship(any(InputRelationship.class), eq("b"));
        verify(collector, times(1)).collectBadRelationship(any(InputRelationship.class), eq("c"));
        verify(collector, times(1)).collectBadRelationship(any(InputRelationship.class), eq("d"));
    }
}
Also used : NodeRelationshipCache(org.neo4j.unsafe.impl.batchimport.cache.NodeRelationshipCache) StageControl(org.neo4j.unsafe.impl.batchimport.staging.StageControl) Collector(org.neo4j.unsafe.impl.batchimport.input.Collector) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) InputRelationship(org.neo4j.unsafe.impl.batchimport.input.InputRelationship) Test(org.junit.Test)

Example 7 with InputRelationship

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

the class CalculateDenseNodesStepTest method shouldNotProcessLoopsTwice.

@Test
public void shouldNotProcessLoopsTwice() throws Exception {
    // GIVEN
    NodeRelationshipCache cache = mock(NodeRelationshipCache.class);
    try (CalculateDenseNodesStep step = new CalculateDenseNodesStep(mock(StageControl.class), DEFAULT, cache, mock(Collector.class))) {
        step.processors(4);
        step.start(0);
        // WHEN
        Batch<InputRelationship, RelationshipRecord> batch = batch(relationship(1, 5), relationship(3, 10), // <-- the loop
        relationship(2, 2), relationship(4, 1));
        step.receive(0, batch);
        step.endOfUpstream();
        while (!step.isCompleted()) {
        // wait
        }
        // THEN
        verify(cache, times(2)).incrementCount(eq(1L));
        verify(cache, times(1)).incrementCount(eq(2L));
        verify(cache, times(1)).incrementCount(eq(3L));
        verify(cache, times(1)).incrementCount(eq(4L));
        verify(cache, times(1)).incrementCount(eq(5L));
        verify(cache, times(1)).incrementCount(eq(10L));
    }
}
Also used : NodeRelationshipCache(org.neo4j.unsafe.impl.batchimport.cache.NodeRelationshipCache) StageControl(org.neo4j.unsafe.impl.batchimport.staging.StageControl) Collector(org.neo4j.unsafe.impl.batchimport.input.Collector) RelationshipRecord(org.neo4j.kernel.impl.store.record.RelationshipRecord) InputRelationship(org.neo4j.unsafe.impl.batchimport.input.InputRelationship) Test(org.junit.Test)

Example 8 with InputRelationship

use of org.neo4j.unsafe.impl.batchimport.input.InputRelationship 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 9 with InputRelationship

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

the class CsvInputTest method shouldDoWithoutRelationshipTypeHeaderIfDefaultSupplied.

@Test
public void shouldDoWithoutRelationshipTypeHeaderIfDefaultSupplied() throws Exception {
    // GIVEN relationship data w/o :TYPE header
    String defaultType = "HERE";
    DataFactory<InputRelationship> data = data(":START_ID,:END_ID,name\n" + "0,1,First\n" + "2,3,Second\n", defaultRelationshipType(defaultType));
    Iterable<DataFactory<InputRelationship>> dataIterable = dataIterable(data);
    Input input = new CsvInput(null, null, dataIterable, defaultFormatRelationshipFileHeader(), IdType.ACTUAL, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
    // WHEN
    try (ResourceIterator<InputRelationship> relationships = input.relationships().iterator()) {
        // THEN
        assertRelationship(relationships.next(), 0L, 1L, defaultType, properties("name", "First"));
        assertRelationship(relationships.next(), 2L, 3L, defaultType, properties("name", "Second"));
        assertFalse(relationships.hasNext());
    }
}
Also used : Input(org.neo4j.unsafe.impl.batchimport.input.Input) InputRelationship(org.neo4j.unsafe.impl.batchimport.input.InputRelationship) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 10 with InputRelationship

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

the class CsvInputTest method shouldIgnoreRelationshipEntriesMarkedIgnoreUsingHeader.

@Test
public void shouldIgnoreRelationshipEntriesMarkedIgnoreUsingHeader() throws Exception {
    // GIVEN
    Iterable<DataFactory<InputRelationship>> data = DataFactories.relationshipData(CsvInputTest.<InputRelationship>data(":START_ID,:TYPE,:END_ID,prop:IGNORE,other:int\n" + "1,KNOWS,2,Mattias,10\n" + "2,KNOWS,3,Johan,111\n" + "3,KNOWS,4,Emil,12"));
    Input input = new CsvInput(null, null, data, defaultFormatRelationshipFileHeader(), IdType.INTEGER, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
    // WHEN
    try (InputIterator<InputRelationship> relationships = input.relationships().iterator()) {
        assertRelationship(relationships.next(), 1L, 2L, "KNOWS", new Object[] { "other", 10 });
        assertRelationship(relationships.next(), 2L, 3L, "KNOWS", new Object[] { "other", 111 });
        assertRelationship(relationships.next(), 3L, 4L, "KNOWS", new Object[] { "other", 12 });
        assertFalse(relationships.hasNext());
    }
}
Also used : Input(org.neo4j.unsafe.impl.batchimport.input.Input) InputRelationship(org.neo4j.unsafe.impl.batchimport.input.InputRelationship) Test(org.junit.Test)

Aggregations

InputRelationship (org.neo4j.unsafe.impl.batchimport.input.InputRelationship)29 Test (org.junit.Test)14 RelationshipRecord (org.neo4j.kernel.impl.store.record.RelationshipRecord)9 Input (org.neo4j.unsafe.impl.batchimport.input.Input)9 InputNode (org.neo4j.unsafe.impl.batchimport.input.InputNode)8 StageControl (org.neo4j.unsafe.impl.batchimport.staging.StageControl)4 HashMap (java.util.HashMap)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 Matchers.anyString (org.mockito.Matchers.anyString)3 RelationshipStore (org.neo4j.kernel.impl.store.RelationshipStore)3 File (java.io.File)2 IOException (java.io.IOException)2 Map (java.util.Map)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)2 Transaction (org.neo4j.graphdb.Transaction)2 NeoStores (org.neo4j.kernel.impl.store.NeoStores)2 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)2 BatchImporter (org.neo4j.unsafe.impl.batchimport.BatchImporter)2 ParallelBatchImporter (org.neo4j.unsafe.impl.batchimport.ParallelBatchImporter)2