Search in sources :

Example 21 with InputIterator

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

the class CsvInputTest method shouldCloseDataIteratorsInTheEnd.

@Test
public void shouldCloseDataIteratorsInTheEnd() throws Exception {
    // GIVEN
    CapturingDataFactories nodeData = new CapturingDataFactories(config -> charReader("1"), NO_DECORATOR);
    CapturingDataFactories relationshipData = new CapturingDataFactories(config -> charReader("1,1"), InputEntityDecorators.defaultRelationshipType("TYPE"));
    IdType idType = IdType.STRING;
    Input input = new CsvInput(nodeData, header(entry(null, Type.ID, CsvInput.idExtractor(idType, extractors))), relationshipData, header(entry(null, Type.START_ID, CsvInput.idExtractor(idType, extractors)), entry(null, Type.END_ID, CsvInput.idExtractor(idType, extractors))), idType, config(), NO_MONITOR, INSTANCE);
    // WHEN
    try (InputIterator iterator = input.nodes(EMPTY).iterator()) {
        readNext(iterator);
    }
    try (InputIterator iterator = input.relationships(EMPTY).iterator()) {
        readNext(iterator);
    }
    // THEN
    assertClosed(nodeData.last());
    assertClosed(relationshipData.last());
}
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 22 with InputIterator

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

the class CsvInputTest method shouldAllowSomeNodesToBeAnonymous.

@Test
public void shouldAllowSomeNodesToBeAnonymous() throws Exception {
    // GIVEN
    DataFactory data = data(":ID,name:string,level:int\n" + "abc,Mattias,1\n" + // this node is anonymous
    ",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, "abc", 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 23 with InputIterator

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

the class CsvInputTest method shouldAllowNodesToBeAnonymousEvenIfIdHeaderIsNamed.

@Test
public void shouldAllowNodesToBeAnonymousEvenIfIdHeaderIsNamed() throws Exception {
    // GIVEN
    DataFactory data = data("id:ID,name:string,level:int\n" + "abc,Mattias,1\n" + // this node is anonymous
    ",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, "abc", new Object[] { "id", "abc", "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 24 with InputIterator

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

the class CsvInputTest method shouldSkipRelationshipValidationIfToldTo.

@Test
public void shouldSkipRelationshipValidationIfToldTo() throws Exception {
    // GIVEN
    Iterable<DataFactory> data = datas(CsvInputTest.data(":START_ID,:END_ID,:TYPE\n" + ",,"));
    Input input = new CsvInput(datas(), defaultFormatNodeFileHeader(), data, defaultFormatRelationshipFileHeader(), IdType.INTEGER, config(), NO_MONITOR, INSTANCE);
    // WHEN
    try (InputIterator relationships = input.relationships(EMPTY).iterator()) {
        readNext(relationships);
        assertNull(visitor.startId());
        assertNull(visitor.endId());
        assertNull(visitor.stringType);
    }
}
Also used : InputIterator(org.neo4j.internal.batchimport.InputIterator) Input(org.neo4j.internal.batchimport.input.Input) Test(org.junit.Test)

Example 25 with InputIterator

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

the class CsvInputTest method shouldHaveNodesBelongToGroupSpecifiedInHeader.

@Test
public void shouldHaveNodesBelongToGroupSpecifiedInHeader() throws Exception {
    // GIVEN
    IdType idType = IdType.INTEGER;
    Iterable<DataFactory> 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(), CsvInput.idExtractor(idType, extractors)), entry("name", Type.PROPERTY, extractors.string())), datas(), defaultFormatRelationshipFileHeader(), idType, config(), NO_MONITOR, INSTANCE);
    // WHEN/THEN
    try (InputIterator nodes = input.nodes(EMPTY).iterator()) {
        assertNextNode(nodes, group, 123L, properties("name", "one"), labels());
        assertNextNode(nodes, group, 456L, properties("name", "two"), labels());
        assertFalse(readNext(nodes));
    }
}
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