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