use of org.neo4j.csv.reader.Configuration in project neo4j by neo4j.
the class ImportCommandTest method shouldImportGroupsOfOverlappingIds.
@Test
void shouldImportGroupsOfOverlappingIds() throws Exception {
// GIVEN
List<String> groupOneNodeIds = asList("1", "2", "3");
List<String> groupTwoNodeIds = asList("4", "5", "2");
List<RelationshipDataLine> rels = asList(relationship("1", "4", "TYPE"), relationship("2", "5", "TYPE"), relationship("3", "2", "TYPE"));
Configuration config = Configuration.COMMAS;
String groupOne = "Actor";
String groupTwo = "Movie";
Path dbConfig = prepareDefaultConfigFile();
// WHEN
runImport("--additional-config", dbConfig.toAbsolutePath().toString(), "--nodes", nodeHeader(config, groupOne) + "," + nodeData(false, config, groupOneNodeIds, TRUE), "--nodes", nodeHeader(config, groupTwo) + "," + nodeData(false, config, groupTwoNodeIds, TRUE), "--relationships", relationshipHeader(config, groupOne, groupTwo, true) + "," + relationshipData(false, config, rels.iterator(), TRUE, true));
// THEN
GraphDatabaseService db = getDatabaseApi();
try (Transaction tx = db.beginTx()) {
int nodeCount = 0;
for (Node node : tx.getAllNodes()) {
assertTrue(node.hasProperty("name"));
nodeCount++;
assertEquals(1, Iterables.count(node.getRelationships()));
}
assertEquals(6, nodeCount);
tx.commit();
}
}
use of org.neo4j.csv.reader.Configuration in project neo4j by neo4j.
the class ImportCommandTest method shouldFailIfTooManyBadRelationships.
@Test
void shouldFailIfTooManyBadRelationships() throws Exception {
// GIVEN
List<String> nodeIds = asList("a", "b", "c");
Configuration config = Configuration.COMMAS;
Path nodeData = nodeData(true, config, nodeIds, TRUE);
List<RelationshipDataLine> relationships = Arrays.asList(// line 2 of file1
relationship("a", "b", "TYPE"), // line 3 of file1
relationship("c", "bogus", "TYPE"), // line 1 of file2
relationship("b", "c", "KNOWS"), // line 2 of file2
relationship("c", "a", "KNOWS"), // line 3 of file2
relationship("missing", "a", "KNOWS"));
Path relationshipData = relationshipData(true, config, relationships.iterator(), TRUE, true);
Path bad = badFile();
// WHEN importing data where some relationships refer to missing nodes
var e = assertThrows(Exception.class, () -> runImport("--nodes", nodeData.toAbsolutePath().toString(), "--report-file", bad.toAbsolutePath().toString(), "--bad-tolerance", "1", "--relationships", relationshipData.toAbsolutePath().toString()));
assertExceptionContains(e, relationshipData.toAbsolutePath().toString(), InputException.class);
}
use of org.neo4j.csv.reader.Configuration in project neo4j by neo4j.
the class ImportCommandTest method shouldSkipDuplicateNodesIfToldTo.
@Test
void shouldSkipDuplicateNodesIfToldTo() throws Exception {
// GIVEN
List<String> nodeIds = asList("a", "b", "c", "d", "e", "f", "a", "g");
Configuration config = Configuration.COMMAS;
Path nodeHeaderFile = nodeHeader(config);
Path nodeData1 = nodeData(false, config, nodeIds, lines(0, 4));
Path nodeData2 = nodeData(false, config, nodeIds, lines(4, nodeIds.size()));
Path dbConfig = prepareDefaultConfigFile();
// WHEN
runImport("--additional-config", dbConfig.toAbsolutePath().toString(), "--skip-duplicate-nodes", "--nodes", nodeHeaderFile.toAbsolutePath().toString() + "," + nodeData1.toAbsolutePath().toString() + "," + nodeData2.toAbsolutePath().toString());
// THEN there should not be duplicates of any node
GraphDatabaseService db = getDatabaseApi();
Set<String> expectedNodeIds = new HashSet<>(nodeIds);
try (Transaction tx = db.beginTx()) {
Set<String> foundNodesIds = new HashSet<>();
for (Node node : tx.getAllNodes()) {
String id = (String) node.getProperty("id");
assertTrue(foundNodesIds.add(id), id + ", " + foundNodesIds);
assertTrue(expectedNodeIds.contains(id));
}
assertEquals(expectedNodeIds, foundNodesIds);
// also all nodes in the label index should exist
for (int i = 0; i < MAX_LABEL_ID; i++) {
Label label = label(labelName(i));
try (ResourceIterator<Node> nodesByLabel = tx.findNodes(label)) {
while (nodesByLabel.hasNext()) {
Node node = nodesByLabel.next();
if (!node.hasLabel(label)) {
fail("Expected " + node + " to have label " + label.name() + ", but instead had " + asList(node.getLabels()));
}
}
}
}
tx.commit();
}
}
use of org.neo4j.csv.reader.Configuration in project neo4j by neo4j.
the class ImportCommandTest method shouldImportMultipleInputsWithAddedLabelsAndDefaultRelationshipType.
@Test
void shouldImportMultipleInputsWithAddedLabelsAndDefaultRelationshipType() throws Exception {
// GIVEN
List<String> nodeIds = nodeIds();
Configuration config = Configuration.COMMAS;
final String[] firstLabels = { "AddedOne", "AddedTwo" };
final String[] secondLabels = { "AddedThree" };
final String firstType = "TYPE_1";
final String secondType = "TYPE_2";
Path dbConfig = prepareDefaultConfigFile();
// WHEN
runImport("--additional-config", dbConfig.toAbsolutePath().toString(), "--nodes=" + join(":", firstLabels) + "=" + nodeData(true, config, nodeIds, lines(0, NODE_COUNT / 2)).toAbsolutePath().toString(), "--nodes=" + join(":", secondLabels) + "=" + nodeData(true, config, nodeIds, lines(NODE_COUNT / 2, NODE_COUNT)).toAbsolutePath().toString(), "--relationships=" + firstType + "=" + relationshipData(true, config, nodeIds, lines(0, RELATIONSHIP_COUNT / 2), false).toAbsolutePath().toString(), "--relationships=" + secondType + "=" + relationshipData(true, config, nodeIds, lines(RELATIONSHIP_COUNT / 2, RELATIONSHIP_COUNT), false).toAbsolutePath().toString());
// THEN
MutableInt numberOfNodesWithFirstSetOfLabels = new MutableInt();
MutableInt numberOfNodesWithSecondSetOfLabels = new MutableInt();
MutableInt numberOfRelationshipsWithFirstType = new MutableInt();
MutableInt numberOfRelationshipsWithSecondType = new MutableInt();
verifyData(node -> {
if (nodeHasLabels(node, firstLabels)) {
numberOfNodesWithFirstSetOfLabels.increment();
} else if (nodeHasLabels(node, secondLabels)) {
numberOfNodesWithSecondSetOfLabels.increment();
} else {
fail(node + " has neither set of labels, it has " + labelsOf(node));
}
}, relationship -> {
if (relationship.isType(RelationshipType.withName(firstType))) {
numberOfRelationshipsWithFirstType.increment();
} else if (relationship.isType(RelationshipType.withName(secondType))) {
numberOfRelationshipsWithSecondType.increment();
} else {
fail(relationship + " didn't have either type, it has " + relationship.getType().name());
}
});
assertEquals(NODE_COUNT / 2, numberOfNodesWithFirstSetOfLabels.intValue());
assertEquals(NODE_COUNT / 2, numberOfNodesWithSecondSetOfLabels.intValue());
assertEquals(RELATIONSHIP_COUNT / 2, numberOfRelationshipsWithFirstType.intValue());
assertEquals(RELATIONSHIP_COUNT / 2, numberOfRelationshipsWithSecondType.intValue());
}
use of org.neo4j.csv.reader.Configuration in project neo4j by neo4j.
the class QuickImport method parseRelationshipHeader.
private static Header parseRelationshipHeader(Args args, IdType idType, Extractors extractors, Groups groups) {
String definition = args.get("relationship-header", null);
if (definition == null) {
return DataGeneratorInput.bareboneRelationshipHeader(idType, extractors);
}
Configuration config = Configuration.COMMAS;
return DataFactories.defaultFormatRelationshipFileHeader().create(seeker(definition, config), config, idType, groups);
}
Aggregations