Search in sources :

Example 16 with InputIterator

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

the class DataGeneratorInput method sample.

private InputEntity[] sample(InputIterable source, int size) {
    try (InputIterator iterator = source.iterator();
        InputChunk chunk = iterator.newChunk()) {
        InputEntity[] sample = new InputEntity[size];
        int cursor = 0;
        while (cursor < size && iterator.next(chunk)) {
            while (cursor < size && chunk.next(sample[cursor++] = new InputEntity())) {
            // just loop
            }
        }
        return sample;
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : InputIterator(org.neo4j.internal.batchimport.InputIterator) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 17 with InputIterator

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

the class CsvInputTest method shouldIgnoreRelationshipEntriesMarkedIgnoreUsingHeader.

@Test
public void shouldIgnoreRelationshipEntriesMarkedIgnoreUsingHeader() throws Exception {
    // GIVEN
    Iterable<DataFactory> data = datas(CsvInputTest.data(":START_ID,:TYPE,:END_ID,prop:IGNORE,other:int\n" + "1,KNOWS,2,Mattias,10\n" + "2,KNOWS,3,Johan,111\n" + "3,KNOWS,4,Emil,12"));
    Input input = new CsvInput(datas(), defaultFormatNodeFileHeader(), data, defaultFormatRelationshipFileHeader(), IdType.INTEGER, config(), NO_MONITOR, INSTANCE);
    // WHEN
    try (InputIterator relationships = input.relationships(EMPTY).iterator()) {
        assertNextRelationship(relationships, 1L, 2L, "KNOWS", new Object[] { "other", 10 });
        assertNextRelationship(relationships, 2L, 3L, "KNOWS", new Object[] { "other", 111 });
        assertNextRelationship(relationships, 3L, 4L, "KNOWS", new Object[] { "other", 12 });
        assertFalse(readNext(relationships));
    }
}
Also used : InputIterator(org.neo4j.internal.batchimport.InputIterator) Input(org.neo4j.internal.batchimport.input.Input) Test(org.junit.Test)

Example 18 with InputIterator

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

the class CsvInputTest method shouldUseHeaderInformationToParsePoint.

@Test
public void shouldUseHeaderInformationToParsePoint() throws Exception {
    // GIVEN
    DataFactory data = data(":ID,name,point:Point{crs:WGS-84}\n" + "0,Johan,\" { x :1 ,y:2 } \"\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", "Johan", "point", Values.pointValue(CoordinateReferenceSystem.WGS84, 1, 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 19 with InputIterator

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

the class CsvInputTest method shouldParseTimePropertyValues.

@Test
public void shouldParseTimePropertyValues() throws Exception {
    // GIVEN
    DataFactory data = data(":ID,name,time:Time\n" + "0,Mattias,13:37\n" + "1,Johan,\"16:20:01\"\n" + "2,Bob,07:30-05:00\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", "time", TimeValue.time(13, 37, 0, 0, "+00:00") }, labels());
        assertNextNode(nodes, 1L, new Object[] { "name", "Johan", "time", TimeValue.time(16, 20, 1, 0, "+00:00") }, labels());
        assertNextNode(nodes, 2L, new Object[] { "name", "Bob", "time", TimeValue.time(7, 30, 0, 0, "-05:00") }, labels());
        assertFalse(readNext(nodes));
    }
}
Also used : InputIterator(org.neo4j.internal.batchimport.InputIterator) Input(org.neo4j.internal.batchimport.input.Input) Test(org.junit.Test)

Example 20 with InputIterator

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

the class CsvInputTest method shouldIgnoreNodeEntriesMarkedIgnoreUsingHeader.

@Test
public void shouldIgnoreNodeEntriesMarkedIgnoreUsingHeader() throws Exception {
    // GIVEN
    Iterable<DataFactory> data = datas(CsvInputTest.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(), datas(), defaultFormatNodeFileHeader(), IdType.INTEGER, config(), NO_MONITOR, INSTANCE);
    // WHEN
    try (InputIterator nodes = input.nodes(EMPTY).iterator()) {
        assertNextNode(nodes, 1L, new Object[] { "other", 10 }, labels("Person"));
        assertNextNode(nodes, 2L, new Object[] { "other", 111 }, labels("Person"));
        assertNextNode(nodes, 3L, new Object[] { "other", 12 }, labels("Person"));
        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