Search in sources :

Example 11 with Input

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

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

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

the class CsvInputTest method shouldFailOnMissingRelationshipType.

@Test
public void shouldFailOnMissingRelationshipType() throws Exception {
    // GIVEN
    String type = "CUSTOM";
    DataFactory<InputRelationship> data = data(":START_ID,:END_ID,:TYPE\n" + "0,1," + type + "\n" + "1,2,");
    Iterable<DataFactory<InputRelationship>> dataIterable = dataIterable(data);
    Input input = new CsvInput(null, null, dataIterable, defaultFormatRelationshipFileHeader(), IdType.ACTUAL, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
    // WHEN/THEN
    try (ResourceIterator<InputRelationship> relationships = input.relationships().iterator()) {
        try {
            assertRelationship(relationships.next(), 0L, 1L, type, NO_PROPERTIES);
            relationships.next();
            fail("Should have failed");
        } catch (DataException e) {
            assertTrue(e.getMessage().contains(Type.TYPE.name()));
        }
    }
}
Also used : DataException(org.neo4j.unsafe.impl.batchimport.input.DataException) 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 14 with Input

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

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

Input (org.neo4j.unsafe.impl.batchimport.input.Input)31 Test (org.junit.Test)30 InputNode (org.neo4j.unsafe.impl.batchimport.input.InputNode)21 InputRelationship (org.neo4j.unsafe.impl.batchimport.input.InputRelationship)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 Matchers.anyString (org.mockito.Matchers.anyString)6 InputException (org.neo4j.unsafe.impl.batchimport.input.InputException)4 Collector (org.neo4j.unsafe.impl.batchimport.input.Collector)3 BadCollector (org.neo4j.unsafe.impl.batchimport.input.BadCollector)2 Group (org.neo4j.unsafe.impl.batchimport.input.Group)2 Groups (org.neo4j.unsafe.impl.batchimport.input.Groups)2 CsvInput (org.neo4j.unsafe.impl.batchimport.input.csv.CsvInput)2 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 PrintStream (java.io.PrintStream)1 Charset (java.nio.charset.Charset)1 Charset.defaultCharset (java.nio.charset.Charset.defaultCharset)1 CharReadable (org.neo4j.csv.reader.CharReadable)1