Search in sources :

Example 11 with InputNode

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

the class CsvInputTest method shouldIgnoreEmptyIntPropertyValues.

@Test
public void shouldIgnoreEmptyIntPropertyValues() throws Exception {
    // GIVEN
    DataFactory<InputNode> data = data(":ID,name,extra:int\n" + // here we leave out "extra" property
    "0,Mattias,\n" + "1,Johan,10\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", 10 }, 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 12 with InputNode

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

the class CsvInputTest method shouldCopeWithLinesThatHasTooFewValuesButStillValidates.

@Test
public void shouldCopeWithLinesThatHasTooFewValuesButStillValidates() throws Exception {
    // GIVEN
    Iterable<DataFactory<InputNode>> data = dataIterable(data("1,ultralisk,ZERG,10\n" + "2,corruptor,ZERG\n" + "3,mutalisk,ZERG,3"));
    Input input = new CsvInput(data, header(entry(null, Type.ID, extractors.long_()), entry("unit", Type.PROPERTY, extractors.string()), entry("type", Type.LABEL, extractors.string()), entry("kills", Type.PROPERTY, extractors.int_())), null, null, IdType.ACTUAL, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
    // WHEN
    try (ResourceIterator<InputNode> nodes = input.nodes().iterator()) {
        // THEN
        assertNode(nodes.next(), 1L, new Object[] { "unit", "ultralisk", "kills", 10 }, labels("ZERG"));
        assertNode(nodes.next(), 2L, new Object[] { "unit", "corruptor" }, labels("ZERG"));
        assertNode(nodes.next(), 3L, new Object[] { "unit", "mutalisk", "kills", 3 }, labels("ZERG"));
        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 13 with InputNode

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

the class CsvInputTest method shouldNotHaveIdSetAsPropertyIfIdHeaderEntryIsNamedForActualIds.

@Test
public void shouldNotHaveIdSetAsPropertyIfIdHeaderEntryIsNamedForActualIds() throws Exception {
    // GIVEN
    DataFactory<InputNode> data = data("myId:ID,name:string,level:int\n" + "0,Mattias,1\n" + // this node is anonymous
    "1,Johan,2\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", "level", 1 }, labels());
        assertNode(nodes.next(), 1L, 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 14 with InputNode

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

the class CsvInputTest method shouldIgnoreNodeEntriesMarkedIgnoreUsingHeader.

@Test
public void shouldIgnoreNodeEntriesMarkedIgnoreUsingHeader() throws Exception {
    // GIVEN
    Iterable<DataFactory<InputNode>> data = DataFactories.nodeData(CsvInputTest.<InputNode>data(":ID,name:IGNORE,other:int,:LABEL\n" + "1,Mattias,10,Person\n" + "2,Johan,111,Person\n" + "3,Emil,12,Person"));
    Input input = new CsvInput(data, defaultFormatNodeFileHeader(), null, null, IdType.INTEGER, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
    // WHEN
    try (InputIterator<InputNode> nodes = input.nodes().iterator()) {
        assertNode(nodes.next(), 1L, new Object[] { "other", 10 }, labels("Person"));
        assertNode(nodes.next(), 2L, new Object[] { "other", 111 }, labels("Person"));
        assertNode(nodes.next(), 3L, new Object[] { "other", 12 }, labels("Person"));
        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 15 with InputNode

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

the class CsvInputTest method shouldAllowNodesWithoutIdHeader.

@Test
public void shouldAllowNodesWithoutIdHeader() throws Exception {
    // GIVEN
    DataFactory<InputNode> data = data("name:string,level:int\n" + "Mattias,1\n" + "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(), null, 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)

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