Search in sources :

Example 6 with InputIterator

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

the class CsvInputTest method shouldIgnoreValuesAfterHeaderEntries.

@Test
public void shouldIgnoreValuesAfterHeaderEntries() throws Exception {
    // GIVEN
    Iterable<DataFactory> data = dataIterable(data("1,zergling,bubble,bobble\n" + "2,scv,pun,intended"));
    Input input = new CsvInput(data, header(entry(null, Type.ID, extractors.long_()), entry("name", Type.PROPERTY, extractors.string())), datas(), defaultFormatRelationshipFileHeader(), ACTUAL, config(), NO_MONITOR, INSTANCE);
    // WHEN
    try (InputIterator nodes = input.nodes(EMPTY).iterator()) {
        // THEN
        assertNextNode(nodes, 1L, new Object[] { "name", "zergling" }, labels());
        assertNextNode(nodes, 2L, new Object[] { "name", "scv" }, labels());
        assertFalse(readNext(nodes));
    }
}
Also used : InputIterator(org.neo4j.internal.batchimport.InputIterator) Input(org.neo4j.internal.batchimport.input.Input) Test(org.junit.Test)

Example 7 with InputIterator

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

the class CsvInputTest method shouldPropagateExceptionFromFailingDecorator.

@Test
public void shouldPropagateExceptionFromFailingDecorator() throws Exception {
    // GIVEN
    RuntimeException failure = new RuntimeException("FAILURE");
    Iterable<DataFactory> data = datas(CsvInputTest.data(":ID,name\n1,Mattias", new FailingNodeDecorator(failure)));
    Input input = new CsvInput(data, defaultFormatNodeFileHeader(), datas(), defaultFormatNodeFileHeader(), IdType.INTEGER, config(), NO_MONITOR, INSTANCE);
    // WHEN
    try (InputIterator nodes = input.nodes(EMPTY).iterator()) {
        readNext(nodes);
    } catch (InputException e) {
        // THEN
        assertSame(e.getCause(), failure);
    }
}
Also used : InputIterator(org.neo4j.internal.batchimport.InputIterator) Input(org.neo4j.internal.batchimport.input.Input) InputException(org.neo4j.internal.batchimport.input.InputException) Test(org.junit.Test)

Example 8 with InputIterator

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

the class CsvInputTest method shouldCopeWithLinesThatHasTooFewValuesButStillValidates.

@Test
public void shouldCopeWithLinesThatHasTooFewValuesButStillValidates() throws Exception {
    // GIVEN
    Iterable<DataFactory> 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_())), datas(), defaultFormatRelationshipFileHeader(), ACTUAL, config(), NO_MONITOR, INSTANCE);
    // WHEN
    try (InputIterator nodes = input.nodes(EMPTY).iterator()) {
        // THEN
        assertNextNode(nodes, 1L, new Object[] { "unit", "ultralisk", "kills", 10 }, labels("ZERG"));
        assertNextNode(nodes, 2L, new Object[] { "unit", "corruptor" }, labels("ZERG"));
        assertNextNode(nodes, 3L, new Object[] { "unit", "mutalisk", "kills", 3 }, labels("ZERG"));
        assertFalse(readNext(nodes));
    }
}
Also used : InputIterator(org.neo4j.internal.batchimport.InputIterator) Input(org.neo4j.internal.batchimport.input.Input) Test(org.junit.Test)

Example 9 with InputIterator

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

the class CsvInputTest method shouldTreatEmptyQuotedStringsAsNullIfConfiguredTo.

@Test
public void shouldTreatEmptyQuotedStringsAsNullIfConfiguredTo() throws Exception {
    // GIVEN
    Iterable<DataFactory> data = datas(CsvInputTest.data(":ID,one,two,three\n" + "1,\"\",,value"));
    Configuration config = config().toBuilder().withEmptyQuotedStringsAsNull(true).build();
    Input input = new CsvInput(data, defaultFormatNodeFileHeader(), datas(), defaultFormatRelationshipFileHeader(), IdType.INTEGER, config, NO_MONITOR, INSTANCE);
    // WHEN
    try (InputIterator nodes = input.nodes(EMPTY).iterator()) {
        // THEN
        assertNextNode(nodes, 1L, properties("three", "value"), labels());
        assertFalse(readNext(nodes));
    }
}
Also used : InputIterator(org.neo4j.internal.batchimport.InputIterator) Input(org.neo4j.internal.batchimport.input.Input) Configuration(org.neo4j.csv.reader.Configuration) Test(org.junit.Test)

Example 10 with InputIterator

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

the class CsvInputTest method shouldHaveRelationshipsSpecifyStartEndNodeIdGroupsInHeader.

@Test
public void shouldHaveRelationshipsSpecifyStartEndNodeIdGroupsInHeader() throws Exception {
    // GIVEN
    IdType idType = IdType.INTEGER;
    Iterable<DataFactory> data = dataIterable(data("123,TYPE,234\n" + "345,TYPE,456"));
    Groups groups = new Groups();
    Group startNodeGroup = groups.getOrCreate("StartGroup");
    Group endNodeGroup = groups.getOrCreate("EndGroup");
    Iterable<DataFactory> nodeHeader = dataIterable(data(":ID(" + startNodeGroup.name() + ")"), data(":ID(" + endNodeGroup.name() + ")"));
    Input input = new CsvInput(nodeHeader, defaultFormatNodeFileHeader(), data, header(entry(null, Type.START_ID, startNodeGroup.name(), CsvInput.idExtractor(idType, extractors)), entry(null, Type.TYPE, extractors.string()), entry(null, Type.END_ID, endNodeGroup.name(), CsvInput.idExtractor(idType, extractors))), idType, config(), NO_MONITOR, INSTANCE);
    // WHEN/THEN
    try (InputIterator relationships = input.relationships(EMPTY).iterator()) {
        assertRelationship(relationships, startNodeGroup, 123L, endNodeGroup, 234L, "TYPE", properties());
        assertRelationship(relationships, startNodeGroup, 345L, endNodeGroup, 456L, "TYPE", properties());
        assertFalse(readNext(relationships));
    }
}
Also used : Group(org.neo4j.internal.batchimport.input.Group) InputIterator(org.neo4j.internal.batchimport.InputIterator) Input(org.neo4j.internal.batchimport.input.Input) Groups(org.neo4j.internal.batchimport.input.Groups) IdType(org.neo4j.internal.batchimport.input.IdType) 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