use of org.neo4j.unsafe.impl.batchimport.input.Input 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.Input 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.Input in project neo4j by neo4j.
the class CsvInputTest method shouldFailOnMissingRelationshipType.
@Test
public void shouldFailOnMissingRelationshipType() throws Exception {
// GIVEN
String type = "CUSTOM";
DataFactory<InputRelationship> data = data(":START_ID,:END_ID,:TYPE\n" + "0,1," + type + "\n" + "1,2,");
Iterable<DataFactory<InputRelationship>> dataIterable = dataIterable(data);
Input input = new CsvInput(null, null, dataIterable, defaultFormatRelationshipFileHeader(), IdType.ACTUAL, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
// WHEN/THEN
try (ResourceIterator<InputRelationship> relationships = input.relationships().iterator()) {
try {
assertRelationship(relationships.next(), 0L, 1L, type, NO_PROPERTIES);
relationships.next();
fail("Should have failed");
} catch (DataException e) {
assertTrue(e.getMessage().contains(Type.TYPE.name()));
}
}
}
use of org.neo4j.unsafe.impl.batchimport.input.Input 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.Input 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