use of org.neo4j.unsafe.impl.batchimport.input.InputNode in project neo4j by neo4j.
the class CsvInputTest method shouldIgnoreEmptyIntPropertyValues.
@Test
public void shouldIgnoreEmptyIntPropertyValues() throws Exception {
// GIVEN
DataFactory<InputNode> data = data(":ID,name,extra:int\n" + // here we leave out "extra" property
"0,Mattias,\n" + "1,Johan,10\n");
Iterable<DataFactory<InputNode>> dataIterable = dataIterable(data);
Input input = new CsvInput(dataIterable, defaultFormatNodeFileHeader(), null, null, IdType.ACTUAL, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
// WHEN
try (ResourceIterator<InputNode> nodes = input.nodes().iterator()) {
// THEN
assertNode(nodes.next(), 0L, new Object[] { "name", "Mattias" }, labels());
assertNode(nodes.next(), 1L, new Object[] { "name", "Johan", "extra", 10 }, labels());
assertFalse(nodes.hasNext());
}
}
use of org.neo4j.unsafe.impl.batchimport.input.InputNode in project neo4j by neo4j.
the class CsvInputTest method shouldCopeWithLinesThatHasTooFewValuesButStillValidates.
@Test
public void shouldCopeWithLinesThatHasTooFewValuesButStillValidates() throws Exception {
// GIVEN
Iterable<DataFactory<InputNode>> data = dataIterable(data("1,ultralisk,ZERG,10\n" + "2,corruptor,ZERG\n" + "3,mutalisk,ZERG,3"));
Input input = new CsvInput(data, header(entry(null, Type.ID, extractors.long_()), entry("unit", Type.PROPERTY, extractors.string()), entry("type", Type.LABEL, extractors.string()), entry("kills", Type.PROPERTY, extractors.int_())), null, null, IdType.ACTUAL, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
// WHEN
try (ResourceIterator<InputNode> nodes = input.nodes().iterator()) {
// THEN
assertNode(nodes.next(), 1L, new Object[] { "unit", "ultralisk", "kills", 10 }, labels("ZERG"));
assertNode(nodes.next(), 2L, new Object[] { "unit", "corruptor" }, labels("ZERG"));
assertNode(nodes.next(), 3L, new Object[] { "unit", "mutalisk", "kills", 3 }, labels("ZERG"));
assertFalse(nodes.hasNext());
}
}
use of org.neo4j.unsafe.impl.batchimport.input.InputNode in project neo4j by neo4j.
the class CsvInputTest method shouldNotHaveIdSetAsPropertyIfIdHeaderEntryIsNamedForActualIds.
@Test
public void shouldNotHaveIdSetAsPropertyIfIdHeaderEntryIsNamedForActualIds() throws Exception {
// GIVEN
DataFactory<InputNode> data = data("myId:ID,name:string,level:int\n" + "0,Mattias,1\n" + // this node is anonymous
"1,Johan,2\n");
Iterable<DataFactory<InputNode>> dataIterable = dataIterable(data);
Input input = new CsvInput(dataIterable, defaultFormatNodeFileHeader(), null, null, IdType.ACTUAL, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
// WHEN
try (ResourceIterator<InputNode> nodes = input.nodes().iterator()) {
// THEN
assertNode(nodes.next(), 0L, new Object[] { "name", "Mattias", "level", 1 }, labels());
assertNode(nodes.next(), 1L, 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 shouldIgnoreNodeEntriesMarkedIgnoreUsingHeader.
@Test
public void shouldIgnoreNodeEntriesMarkedIgnoreUsingHeader() throws Exception {
// GIVEN
Iterable<DataFactory<InputNode>> data = DataFactories.nodeData(CsvInputTest.<InputNode>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(), null, null, IdType.INTEGER, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
// WHEN
try (InputIterator<InputNode> nodes = input.nodes().iterator()) {
assertNode(nodes.next(), 1L, new Object[] { "other", 10 }, labels("Person"));
assertNode(nodes.next(), 2L, new Object[] { "other", 111 }, labels("Person"));
assertNode(nodes.next(), 3L, new Object[] { "other", 12 }, labels("Person"));
assertFalse(nodes.hasNext());
}
}
use of org.neo4j.unsafe.impl.batchimport.input.InputNode in project neo4j by neo4j.
the class CsvInputTest method shouldAllowNodesWithoutIdHeader.
@Test
public void shouldAllowNodesWithoutIdHeader() throws Exception {
// GIVEN
DataFactory<InputNode> data = data("name:string,level:int\n" + "Mattias,1\n" + "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(), null, new Object[] { "name", "Mattias", "level", 1 }, labels());
assertNode(nodes.next(), null, new Object[] { "name", "Johan", "level", 2 }, labels());
assertFalse(nodes.hasNext());
}
}
Aggregations