Search in sources :

Example 31 with InputNode

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

the class CsvInputTest method shouldAllowSomeNodesToBeAnonymous.

@Test
public void shouldAllowSomeNodesToBeAnonymous() throws Exception {
    // GIVEN
    DataFactory<InputNode> data = data(":ID,name:string,level:int\n" + "abc,Mattias,1\n" + // this node is anonymous
    ",Johan,2\n");
    Iterable<DataFactory<InputNode>> dataIterable = dataIterable(data);
    Input input = new CsvInput(dataIterable, defaultFormatNodeFileHeader(), null, null, IdType.STRING, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
    // WHEN
    try (ResourceIterator<InputNode> nodes = input.nodes().iterator()) {
        // THEN
        assertNode(nodes.next(), "abc", new Object[] { "name", "Mattias", "level", 1 }, labels());
        assertNode(nodes.next(), null, new Object[] { "name", "Johan", "level", 2 }, 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 32 with InputNode

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

the class CsvInputTest method shouldHaveNodesBelongToGroupSpecifiedInHeader.

@Test
public void shouldHaveNodesBelongToGroupSpecifiedInHeader() throws Exception {
    // GIVEN
    IdType idType = IdType.ACTUAL;
    Iterable<DataFactory<InputNode>> 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(), idType.extractor(extractors)), entry("name", Type.PROPERTY, extractors.string())), null, null, idType, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
    // WHEN/THEN
    try (InputIterator<InputNode> nodes = input.nodes().iterator()) {
        assertNode(nodes.next(), group, 123L, properties("name", "one"), labels());
        assertNode(nodes.next(), group, 456L, properties("name", "two"), labels());
        assertFalse(nodes.hasNext());
    }
}
Also used : Group(org.neo4j.unsafe.impl.batchimport.input.Group) InputNode(org.neo4j.unsafe.impl.batchimport.input.InputNode) Input(org.neo4j.unsafe.impl.batchimport.input.Input) Groups(org.neo4j.unsafe.impl.batchimport.input.Groups) Test(org.junit.Test)

Example 33 with InputNode

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

the class CsvInputTest method shouldProvideNodesFromCsvInput.

@Test
public void shouldProvideNodesFromCsvInput() throws Exception {
    // GIVEN
    IdType idType = IdType.ACTUAL;
    Iterable<DataFactory<InputNode>> data = dataIterable(data("123,Mattias Persson,HACKER"));
    Input input = new CsvInput(data, header(entry(null, Type.ID, idType.extractor(extractors)), entry("name", Type.PROPERTY, extractors.string()), entry("labels", Type.LABEL, extractors.string())), null, null, idType, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
    // WHEN/THEN
    try (InputIterator<InputNode> nodes = input.nodes().iterator()) {
        assertNode(nodes.next(), 123L, properties("name", "Mattias Persson"), labels("HACKER"));
        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 34 with InputNode

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

the class CsvInputTest method shouldIgnoreEmptyExtraColumns.

@Test
public void shouldIgnoreEmptyExtraColumns() throws Exception {
    // GIVEN
    Iterable<DataFactory<InputNode>> data = DataFactories.nodeData(CsvInputTest.<InputNode>data(":ID,one\n" + "1,test,\n" + "2,test,,additional"));
    // WHEN
    Collector collector = mock(Collector.class);
    Input input = new CsvInput(data, defaultFormatNodeFileHeader(), null, null, IdType.INTEGER, config(COMMAS), collector, getRuntime().availableProcessors());
    // THEN
    try (InputIterator<InputNode> nodes = input.nodes().iterator()) {
        // THEN
        assertNode(nodes.next(), 1L, properties("one", "test"), labels());
        assertNode(nodes.next(), 2L, properties("one", "test"), labels());
        assertFalse(nodes.hasNext());
    }
    verify(collector, times(1)).collectExtraColumns(anyString(), eq(1L), eq((String) null));
    verify(collector, times(1)).collectExtraColumns(anyString(), eq(2L), eq((String) null));
    verify(collector, times(1)).collectExtraColumns(anyString(), eq(2L), eq("additional"));
}
Also used : InputNode(org.neo4j.unsafe.impl.batchimport.input.InputNode) Input(org.neo4j.unsafe.impl.batchimport.input.Input) Collector(org.neo4j.unsafe.impl.batchimport.input.Collector) Collectors.silentBadCollector(org.neo4j.unsafe.impl.batchimport.input.Collectors.silentBadCollector) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 35 with InputNode

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

the class CsvInputTest method shouldCloseDataIteratorsInTheEnd.

@Test
public void shouldCloseDataIteratorsInTheEnd() throws Exception {
    // GIVEN
    CharReadable nodeData = charReader("1");
    CharReadable relationshipData = charReader("1,1");
    IdType idType = IdType.STRING;
    Iterable<DataFactory<InputNode>> nodeDataIterable = dataIterable(given(nodeData));
    Iterable<DataFactory<InputRelationship>> relationshipDataIterable = dataIterable(data(relationshipData, defaultRelationshipType("TYPE")));
    Input input = new CsvInput(nodeDataIterable, header(entry(null, Type.ID, idType.extractor(extractors))), relationshipDataIterable, header(entry(null, Type.START_ID, idType.extractor(extractors)), entry(null, Type.END_ID, idType.extractor(extractors))), idType, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
    // WHEN
    try (ResourceIterator<InputNode> iterator = input.nodes().iterator()) {
        iterator.next();
    }
    try (ResourceIterator<InputRelationship> iterator = input.relationships().iterator()) {
        iterator.next();
    }
    // THEN
    assertClosed(nodeData);
    assertClosed(relationshipData);
}
Also used : InputNode(org.neo4j.unsafe.impl.batchimport.input.InputNode) Input(org.neo4j.unsafe.impl.batchimport.input.Input) CharReadable(org.neo4j.csv.reader.CharReadable) InputRelationship(org.neo4j.unsafe.impl.batchimport.input.InputRelationship) 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