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);
}
}
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));
}
}
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));
}
}
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));
}
}
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));
}
}
Aggregations