use of org.neo4j.unsafe.impl.batchimport.input.InputNode in project neo4j by neo4j.
the class CsvInputTest method shouldAllowSomeNodesToBeAnonymous.
@Test
public void shouldAllowSomeNodesToBeAnonymous() throws Exception {
// GIVEN
DataFactory<InputNode> data = data(":ID,name:string,level:int\n" + "abc,Mattias,1\n" + // this node is anonymous
",Johan,2\n");
Iterable<DataFactory<InputNode>> dataIterable = dataIterable(data);
Input input = new CsvInput(dataIterable, defaultFormatNodeFileHeader(), null, null, IdType.STRING, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
// WHEN
try (ResourceIterator<InputNode> nodes = input.nodes().iterator()) {
// THEN
assertNode(nodes.next(), "abc", new Object[] { "name", "Mattias", "level", 1 }, labels());
assertNode(nodes.next(), null, new Object[] { "name", "Johan", "level", 2 }, labels());
assertFalse(nodes.hasNext());
}
}
use of org.neo4j.unsafe.impl.batchimport.input.InputNode in project neo4j by neo4j.
the class CsvInputTest method shouldHaveNodesBelongToGroupSpecifiedInHeader.
@Test
public void shouldHaveNodesBelongToGroupSpecifiedInHeader() throws Exception {
// GIVEN
IdType idType = IdType.ACTUAL;
Iterable<DataFactory<InputNode>> 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(), idType.extractor(extractors)), entry("name", Type.PROPERTY, extractors.string())), null, null, idType, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
// WHEN/THEN
try (InputIterator<InputNode> nodes = input.nodes().iterator()) {
assertNode(nodes.next(), group, 123L, properties("name", "one"), labels());
assertNode(nodes.next(), group, 456L, properties("name", "two"), labels());
assertFalse(nodes.hasNext());
}
}
use of org.neo4j.unsafe.impl.batchimport.input.InputNode in project neo4j by neo4j.
the class CsvInputTest method shouldProvideNodesFromCsvInput.
@Test
public void shouldProvideNodesFromCsvInput() throws Exception {
// GIVEN
IdType idType = IdType.ACTUAL;
Iterable<DataFactory<InputNode>> data = dataIterable(data("123,Mattias Persson,HACKER"));
Input input = new CsvInput(data, header(entry(null, Type.ID, idType.extractor(extractors)), entry("name", Type.PROPERTY, extractors.string()), entry("labels", Type.LABEL, extractors.string())), null, null, idType, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
// WHEN/THEN
try (InputIterator<InputNode> nodes = input.nodes().iterator()) {
assertNode(nodes.next(), 123L, properties("name", "Mattias Persson"), labels("HACKER"));
assertFalse(nodes.hasNext());
}
}
use of org.neo4j.unsafe.impl.batchimport.input.InputNode in project neo4j by neo4j.
the class CsvInputTest method shouldIgnoreEmptyExtraColumns.
@Test
public void shouldIgnoreEmptyExtraColumns() throws Exception {
// GIVEN
Iterable<DataFactory<InputNode>> data = DataFactories.nodeData(CsvInputTest.<InputNode>data(":ID,one\n" + "1,test,\n" + "2,test,,additional"));
// WHEN
Collector collector = mock(Collector.class);
Input input = new CsvInput(data, defaultFormatNodeFileHeader(), null, null, IdType.INTEGER, config(COMMAS), collector, getRuntime().availableProcessors());
// THEN
try (InputIterator<InputNode> nodes = input.nodes().iterator()) {
// THEN
assertNode(nodes.next(), 1L, properties("one", "test"), labels());
assertNode(nodes.next(), 2L, properties("one", "test"), labels());
assertFalse(nodes.hasNext());
}
verify(collector, times(1)).collectExtraColumns(anyString(), eq(1L), eq((String) null));
verify(collector, times(1)).collectExtraColumns(anyString(), eq(2L), eq((String) null));
verify(collector, times(1)).collectExtraColumns(anyString(), eq(2L), eq("additional"));
}
use of org.neo4j.unsafe.impl.batchimport.input.InputNode in project neo4j by neo4j.
the class CsvInputTest method shouldCloseDataIteratorsInTheEnd.
@Test
public void shouldCloseDataIteratorsInTheEnd() throws Exception {
// GIVEN
CharReadable nodeData = charReader("1");
CharReadable relationshipData = charReader("1,1");
IdType idType = IdType.STRING;
Iterable<DataFactory<InputNode>> nodeDataIterable = dataIterable(given(nodeData));
Iterable<DataFactory<InputRelationship>> relationshipDataIterable = dataIterable(data(relationshipData, defaultRelationshipType("TYPE")));
Input input = new CsvInput(nodeDataIterable, header(entry(null, Type.ID, idType.extractor(extractors))), relationshipDataIterable, header(entry(null, Type.START_ID, idType.extractor(extractors)), entry(null, Type.END_ID, idType.extractor(extractors))), idType, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
// WHEN
try (ResourceIterator<InputNode> iterator = input.nodes().iterator()) {
iterator.next();
}
try (ResourceIterator<InputRelationship> iterator = input.relationships().iterator()) {
iterator.next();
}
// THEN
assertClosed(nodeData);
assertClosed(relationshipData);
}
Aggregations