use of org.neo4j.unsafe.impl.batchimport.input.Input in project neo4j by neo4j.
the class CsvInputTest method shouldHandleMultipleInputGroups.
@Test
public void shouldHandleMultipleInputGroups() throws Exception {
// GIVEN multiple input groups, each with their own, specific, header
DataFactory<InputNode> group1 = data(":ID,name,kills:int,health:int\n" + "1,Jim,10,100\n" + "2,Abathur,0,200\n");
DataFactory<InputNode> group2 = data(":ID,type\n" + "3,zergling\n" + "4,csv\n");
Iterable<DataFactory<InputNode>> data = dataIterable(group1, group2);
Input input = new CsvInput(data, defaultFormatNodeFileHeader(), null, null, IdType.STRING, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
// WHEN iterating over them, THEN the expected data should come out
try (InputIterator<InputNode> nodes = input.nodes().iterator()) {
assertNode(nodes.next(), "1", properties("name", "Jim", "kills", 10, "health", 100), labels());
assertNode(nodes.next(), "2", properties("name", "Abathur", "kills", 0, "health", 200), labels());
assertNode(nodes.next(), "3", properties("type", "zergling"), labels());
assertNode(nodes.next(), "4", properties("type", "csv"), labels());
assertFalse(nodes.hasNext());
}
}
use of org.neo4j.unsafe.impl.batchimport.input.Input in project neo4j by neo4j.
the class CsvInputTest method shouldProvideDefaultRelationshipType.
@Test
public void shouldProvideDefaultRelationshipType() throws Exception {
// GIVEN
String defaultType = "DEFAULT";
String customType = "CUSTOM";
DataFactory<InputRelationship> data = data(":START_ID,:END_ID,:TYPE\n" + "0,1,\n" + "1,2," + customType + "\n" + "2,1," + defaultType, defaultRelationshipType(defaultType));
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()) {
assertRelationship(relationships.next(), 0L, 1L, defaultType, NO_PROPERTIES);
assertRelationship(relationships.next(), 1L, 2L, customType, NO_PROPERTIES);
assertRelationship(relationships.next(), 2L, 1L, defaultType, NO_PROPERTIES);
assertFalse(relationships.hasNext());
}
}
use of org.neo4j.unsafe.impl.batchimport.input.Input in project neo4j by neo4j.
the class CsvInputTest method shouldFailOnRelationshipWithMissingStartIdField.
@Test
public void shouldFailOnRelationshipWithMissingStartIdField() throws Exception {
// GIVEN
Iterable<DataFactory<InputRelationship>> data = relationshipData(CsvInputTest.<InputRelationship>data(":START_ID,:END_ID,:TYPE\n" + ",1,"));
Input input = new CsvInput(null, null, data, defaultFormatRelationshipFileHeader(), IdType.INTEGER, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
// WHEN
try (InputIterator<InputRelationship> relationships = input.relationships().iterator()) {
relationships.next();
fail("Should have failed");
} catch (InputException e) {
// THEN good
assertThat(e.getMessage(), containsString(Type.START_ID.name()));
}
}
use of org.neo4j.unsafe.impl.batchimport.input.Input in project neo4j by neo4j.
the class CsvInputTest method shouldHaveIdSetAsPropertyIfIdHeaderEntryIsNamed.
@Test
public void shouldHaveIdSetAsPropertyIfIdHeaderEntryIsNamed() throws Exception {
// GIVEN
DataFactory<InputNode> data = data("myId:ID,name:string,level:int\n" + "abc,Mattias,1\n" + // this node is anonymous
"def,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[] { "myId", "abc", "name", "Mattias", "level", 1 }, labels());
assertNode(nodes.next(), "def", new Object[] { "myId", "def", "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 shouldTreatEmptyQuotedStringsAsNullIfConfiguredTo.
@Test
public void shouldTreatEmptyQuotedStringsAsNullIfConfiguredTo() throws Exception {
// GIVEN
Iterable<DataFactory<InputNode>> data = DataFactories.nodeData(CsvInputTest.<InputNode>data(":ID,one,two,three\n" + "1,\"\",,value"));
Configuration config = config(new Configuration.Overridden(COMMAS) {
@Override
public boolean emptyQuotedStringsAsNull() {
return true;
}
});
Input input = new CsvInput(data, defaultFormatNodeFileHeader(), null, null, IdType.INTEGER, config, silentBadCollector(0), getRuntime().availableProcessors());
// WHEN
try (InputIterator<InputNode> nodes = input.nodes().iterator()) {
InputNode node = nodes.next();
// THEN
assertNode(node, 1L, properties("three", "value"), labels());
assertFalse(nodes.hasNext());
}
}
Aggregations