Search in sources :

Example 11 with InputIterator

use of org.neo4j.internal.batchimport.InputIterator in project neo4j by neo4j.

the class CsvInputTest method shouldProvideRelationshipsFromCsvInput.

@Test
public void shouldProvideRelationshipsFromCsvInput() throws Exception {
    // GIVEN
    IdType idType = IdType.STRING;
    Iterable<DataFactory> data = dataIterable(data("node1,node2,KNOWS,1234567\n" + "node2,node10,HACKS,987654"));
    Input input = new CsvInput(datas(), defaultFormatNodeFileHeader(), data, header(entry("from", Type.START_ID, CsvInput.idExtractor(idType, extractors)), entry("to", Type.END_ID, CsvInput.idExtractor(idType, extractors)), entry("type", Type.TYPE, extractors.string()), entry("since", Type.PROPERTY, extractors.long_())), idType, config(), NO_MONITOR, INSTANCE);
    // WHEN/THEN
    try (InputIterator relationships = input.relationships(EMPTY).iterator()) {
        assertNextRelationship(relationships, "node1", "node2", "KNOWS", properties("since", 1234567L));
        assertNextRelationship(relationships, "node2", "node10", "HACKS", properties("since", 987654L));
    }
}
Also used : InputIterator(org.neo4j.internal.batchimport.InputIterator) Input(org.neo4j.internal.batchimport.input.Input) IdType(org.neo4j.internal.batchimport.input.IdType) Test(org.junit.Test)

Example 12 with InputIterator

use of org.neo4j.internal.batchimport.InputIterator in project neo4j by neo4j.

the class CsvInputTest method shouldAllowNodesWithoutIdHeader.

@Test
public void shouldAllowNodesWithoutIdHeader() throws Exception {
    // GIVEN
    DataFactory data = data("name:string,level:int\n" + "Mattias,1\n" + "Johan,2\n");
    Iterable<DataFactory> dataIterable = dataIterable(data);
    Input input = new CsvInput(dataIterable, defaultFormatNodeFileHeader(), datas(), defaultFormatRelationshipFileHeader(), IdType.STRING, config(), NO_MONITOR, INSTANCE);
    // WHEN
    try (InputIterator nodes = input.nodes(EMPTY).iterator()) {
        // THEN
        assertNextNode(nodes, null, new Object[] { "name", "Mattias", "level", 1 }, labels());
        assertNextNode(nodes, null, new Object[] { "name", "Johan", "level", 2 }, labels());
        assertFalse(readNext(nodes));
    }
}
Also used : InputIterator(org.neo4j.internal.batchimport.InputIterator) Input(org.neo4j.internal.batchimport.input.Input) Test(org.junit.Test)

Example 13 with InputIterator

use of org.neo4j.internal.batchimport.InputIterator in project neo4j by neo4j.

the class CsvInputTest method shouldParseDatePropertyValues.

@Test
public void shouldParseDatePropertyValues() throws Exception {
    // GIVEN
    DataFactory data = data(":ID,name,date:Date\n" + "0,Mattias,2018-02-27\n" + "1,Johan,2018-03-01\n");
    Iterable<DataFactory> dataIterable = dataIterable(data);
    Input input = new CsvInput(dataIterable, defaultFormatNodeFileHeader(), datas(), defaultFormatRelationshipFileHeader(), ACTUAL, config(), NO_MONITOR, INSTANCE);
    // WHEN
    try (InputIterator nodes = input.nodes(EMPTY).iterator()) {
        // THEN
        assertNextNode(nodes, 0L, new Object[] { "name", "Mattias", "date", DateValue.date(2018, 2, 27) }, labels());
        assertNextNode(nodes, 1L, new Object[] { "name", "Johan", "date", DateValue.date(2018, 3, 1) }, labels());
        assertFalse(readNext(nodes));
    }
}
Also used : InputIterator(org.neo4j.internal.batchimport.InputIterator) Input(org.neo4j.internal.batchimport.input.Input) Test(org.junit.Test)

Example 14 with InputIterator

use of org.neo4j.internal.batchimport.InputIterator in project neo4j by neo4j.

the class CsvInputTest method shouldIgnoreEmptyExtraColumns.

@Test
public void shouldIgnoreEmptyExtraColumns() throws Exception {
    // GIVEN
    Iterable<DataFactory> data = datas(CsvInputTest.data(":ID,one\n" + "1,test,\n" + "2,test,,additional"));
    // WHEN
    Collector collector = mock(Collector.class);
    Input input = new CsvInput(data, defaultFormatNodeFileHeader(), datas(), defaultFormatRelationshipFileHeader(), IdType.INTEGER, config(), NO_MONITOR, INSTANCE);
    // THEN
    try (InputIterator nodes = input.nodes(collector).iterator()) {
        // THEN
        assertNextNode(nodes, 1L, properties("one", "test"), labels());
        assertNextNode(nodes, 2L, properties("one", "test"), labels());
        assertFalse(readNext(nodes));
    }
    verify(collector).collectExtraColumns(anyString(), eq(1L), eq(null));
    verify(collector).collectExtraColumns(anyString(), eq(2L), eq(null));
    verify(collector).collectExtraColumns(anyString(), eq(2L), eq("additional"));
}
Also used : InputIterator(org.neo4j.internal.batchimport.InputIterator) Input(org.neo4j.internal.batchimport.input.Input) Collector(org.neo4j.internal.batchimport.input.Collector) Test(org.junit.Test)

Example 15 with InputIterator

use of org.neo4j.internal.batchimport.InputIterator in project neo4j by neo4j.

the class CsvInputTest method shouldHandleMultipleInputGroups.

@Test
public void shouldHandleMultipleInputGroups() throws Exception {
    // GIVEN multiple input groups, each with their own, specific, header
    DataFactory group1 = data(":ID,name,kills:int,health:int\n" + "1,Jim,10,100\n" + "2,Abathur,0,200\n");
    DataFactory group2 = data(":ID,type\n" + "3,zergling\n" + "4,csv\n");
    Iterable<DataFactory> data = dataIterable(group1, group2);
    Input input = new CsvInput(data, defaultFormatNodeFileHeader(), datas(), defaultFormatRelationshipFileHeader(), IdType.STRING, config(), NO_MONITOR, INSTANCE);
    // WHEN iterating over them, THEN the expected data should come out
    try (InputIterator nodes = input.nodes(EMPTY).iterator()) {
        assertNextNode(nodes, "1", properties("name", "Jim", "kills", 10, "health", 100), labels());
        assertNextNode(nodes, "2", properties("name", "Abathur", "kills", 0, "health", 200), labels());
        assertNextNode(nodes, "3", properties("type", "zergling"), labels());
        assertNextNode(nodes, "4", properties("type", "csv"), labels());
        assertFalse(readNext(nodes));
    }
}
Also used : InputIterator(org.neo4j.internal.batchimport.InputIterator) Input(org.neo4j.internal.batchimport.input.Input) Test(org.junit.Test)

Aggregations

InputIterator (org.neo4j.internal.batchimport.InputIterator)37 Test (org.junit.Test)36 Input (org.neo4j.internal.batchimport.input.Input)36 IdType (org.neo4j.internal.batchimport.input.IdType)5 Matchers.containsString (org.hamcrest.Matchers.containsString)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 Group (org.neo4j.internal.batchimport.input.Group)2 Groups (org.neo4j.internal.batchimport.input.Groups)2 InputException (org.neo4j.internal.batchimport.input.InputException)2 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 Configuration (org.neo4j.csv.reader.Configuration)1 Collector (org.neo4j.internal.batchimport.input.Collector)1