use of org.neo4j.unsafe.impl.batchimport.input.Input in project neo4j by neo4j.
the class CsvInputTest method shouldIncludeDataSourceInformationOnBadFieldValueOrLine.
@Test
public void shouldIncludeDataSourceInformationOnBadFieldValueOrLine() throws Exception {
// GIVEN
Iterable<DataFactory<InputNode>> data = DataFactories.nodeData(CsvInputTest.<InputNode>data(":ID,name,other:int\n" + "1,Mattias,10\n" + "2,Johan,abc\n" + "3,Emil,12"));
Input input = new CsvInput(data, DataFactories.defaultFormatNodeFileHeader(), null, null, IdType.INTEGER, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
// WHEN
try (InputIterator<InputNode> nodes = input.nodes().iterator()) {
try {
assertNode(nodes.next(), 1L, new Object[] { "name", "Mattias", "other", 10 }, labels());
nodes.next();
fail("Should have failed");
} catch (InputException e) {
// THEN
assertThat(e.getMessage(), containsString("other"));
assertThat(e.getMessage(), containsString("abc"));
}
}
}
use of org.neo4j.unsafe.impl.batchimport.input.Input in project neo4j by neo4j.
the class CsvInputTest method shouldIgnoreRelationshipEntriesMarkedIgnoreUsingHeader.
@Test
public void shouldIgnoreRelationshipEntriesMarkedIgnoreUsingHeader() throws Exception {
// GIVEN
Iterable<DataFactory<InputRelationship>> data = DataFactories.relationshipData(CsvInputTest.<InputRelationship>data(":START_ID,:TYPE,:END_ID,prop:IGNORE,other:int\n" + "1,KNOWS,2,Mattias,10\n" + "2,KNOWS,3,Johan,111\n" + "3,KNOWS,4,Emil,12"));
Input input = new CsvInput(null, null, data, defaultFormatRelationshipFileHeader(), IdType.INTEGER, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
// WHEN
try (InputIterator<InputRelationship> relationships = input.relationships().iterator()) {
assertRelationship(relationships.next(), 1L, 2L, "KNOWS", new Object[] { "other", 10 });
assertRelationship(relationships.next(), 2L, 3L, "KNOWS", new Object[] { "other", 111 });
assertRelationship(relationships.next(), 3L, 4L, "KNOWS", new Object[] { "other", 12 });
assertFalse(relationships.hasNext());
}
}
use of org.neo4j.unsafe.impl.batchimport.input.Input in project neo4j by neo4j.
the class CsvInputTest method shouldProvideRelationshipsFromCsvInput.
@Test
public void shouldProvideRelationshipsFromCsvInput() throws Exception {
// GIVEN
IdType idType = IdType.STRING;
Iterable<DataFactory<InputRelationship>> data = dataIterable(data("node1,node2,KNOWS,1234567\n" + "node2,node10,HACKS,987654"));
Input input = new CsvInput(null, null, data, header(entry("from", Type.START_ID, idType.extractor(extractors)), entry("to", Type.END_ID, idType.extractor(extractors)), entry("type", Type.TYPE, extractors.string()), entry("since", Type.PROPERTY, extractors.long_())), idType, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
// WHEN/THEN
try (InputIterator<InputRelationship> relationships = input.relationships().iterator()) {
assertRelationship(relationships.next(), "node1", "node2", "KNOWS", properties("since", 1234567L));
assertRelationship(relationships.next(), "node2", "node10", "HACKS", properties("since", 987654L));
}
}
use of org.neo4j.unsafe.impl.batchimport.input.Input 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.Input in project neo4j by neo4j.
the class CsvInputTest method shouldFailOnRelationshipWithMissingEndIdField.
@Test
public void shouldFailOnRelationshipWithMissingEndIdField() 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.END_ID.name()));
}
}
Aggregations