use of org.neo4j.unsafe.impl.batchimport.input.InputRelationship 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.InputRelationship 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()));
}
}
use of org.neo4j.unsafe.impl.batchimport.input.InputRelationship 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.InputRelationship in project neo4j by neo4j.
the class RelationshipTypeCheckerStepTest method batchOfRelationshipsWithRandomTypes.
private Batch<InputRelationship, RelationshipRecord> batchOfRelationshipsWithRandomTypes(int maxTypes, boolean typeIds) {
InputRelationship[] relationships = new InputRelationship[100];
for (int i = 0; i < relationships.length; i++) {
int typeId = random.nextInt(maxTypes);
relationships[i] = new InputRelationship("test", i, i, NO_PROPERTIES, null, GLOBAL, 0L, GLOBAL, 0L, typeIds ? null : "TYPE_" + String.valueOf(typeId), typeIds ? typeId : null);
}
return new Batch<>(relationships);
}
use of org.neo4j.unsafe.impl.batchimport.input.InputRelationship 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());
}
}
Aggregations