use of org.neo4j.unsafe.impl.batchimport.input.csv.Configuration in project neo4j by neo4j.
the class ImportToolTest method shouldBeAbleToDisableSkippingOfBadRelationships.
@Test
public void shouldBeAbleToDisableSkippingOfBadRelationships() throws Exception {
// GIVEN
List<String> nodeIds = asList("a", "b", "c");
Configuration config = Configuration.COMMAS;
File 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"));
File relationshipData1 = relationshipData(true, config, relationships.iterator(), lines(0, 2), true);
File relationshipData2 = relationshipData(false, config, relationships.iterator(), lines(2, 5), true);
File bad = badFile();
// WHEN importing data where some relationships refer to missing nodes
try {
importTool("--into", dbRule.getStoreDirAbsolutePath(), "--nodes", nodeData.getAbsolutePath(), "--bad", bad.getAbsolutePath(), "--skip-bad-relationships", "false", "--relationships", relationshipData1.getAbsolutePath() + MULTI_FILE_DELIMITER + relationshipData2.getAbsolutePath());
} catch (Exception e) {
// THEN
assertExceptionContains(e, relationshipData1.getAbsolutePath() + ":3", InputException.class);
}
}
use of org.neo4j.unsafe.impl.batchimport.input.csv.Configuration in project neo4j by neo4j.
the class ImportToolTest method shouldIncludeSourceInformationInNodeIdCollisionError.
@Test
public void shouldIncludeSourceInformationInNodeIdCollisionError() throws Exception {
// GIVEN
List<String> nodeIds = asList("a", "b", "c", "d", "e", "f", "a", "g");
Configuration config = Configuration.COMMAS;
File nodeHeaderFile = nodeHeader(config);
File nodeData1 = nodeData(false, config, nodeIds, lines(0, 4));
File nodeData2 = nodeData(false, config, nodeIds, lines(4, nodeIds.size()));
// WHEN
try {
importTool("--into", dbRule.getStoreDirAbsolutePath(), "--nodes", nodeHeaderFile.getAbsolutePath() + MULTI_FILE_DELIMITER + nodeData1.getAbsolutePath() + MULTI_FILE_DELIMITER + nodeData2.getAbsolutePath());
fail("Should have failed with duplicate node IDs");
} catch (Exception e) {
// THEN
assertExceptionContains(e, nodeData1.getPath() + ":" + 1, DuplicateInputIdException.class);
assertExceptionContains(e, nodeData2.getPath() + ":" + 3, DuplicateInputIdException.class);
}
}
use of org.neo4j.unsafe.impl.batchimport.input.csv.Configuration in project neo4j by neo4j.
the class ImportToolTest method shouldSkipDuplicateNodesIfToldTo.
@Test
public void shouldSkipDuplicateNodesIfToldTo() throws Exception {
// GIVEN
List<String> nodeIds = asList("a", "b", "c", "d", "e", "f", "a", "g");
Configuration config = Configuration.COMMAS;
File nodeHeaderFile = nodeHeader(config);
File nodeData1 = nodeData(false, config, nodeIds, lines(0, 4));
File nodeData2 = nodeData(false, config, nodeIds, lines(4, nodeIds.size()));
// WHEN
importTool("--into", dbRule.getStoreDirAbsolutePath(), "--skip-duplicate-nodes", "--nodes", nodeHeaderFile.getAbsolutePath() + MULTI_FILE_DELIMITER + nodeData1.getAbsolutePath() + MULTI_FILE_DELIMITER + nodeData2.getAbsolutePath());
// THEN
GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
try (Transaction tx = db.beginTx()) {
// there should not be duplicates of any node
Iterator<Node> nodes = db.getAllNodes().iterator();
Iterator<String> expectedIds = FilteringIterator.noDuplicates(nodeIds.iterator());
while (expectedIds.hasNext()) {
assertTrue(nodes.hasNext());
assertEquals(expectedIds.next(), nodes.next().getProperty("id"));
}
assertFalse(nodes.hasNext());
// also all nodes in the label index should exist
for (int i = 0; i < MAX_LABEL_ID; i++) {
Label label = Label.label(labelName(i));
try (ResourceIterator<Node> nodesByLabel = db.findNodes(label)) {
while (nodesByLabel.hasNext()) {
assertTrue(nodesByLabel.next().hasLabel(label));
}
}
}
tx.success();
} finally {
db.shutdown();
}
}
use of org.neo4j.unsafe.impl.batchimport.input.csv.Configuration in project neo4j by neo4j.
the class ImportToolTest method shouldImportGroupsOfOverlappingIds.
@Test
public 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";
// WHEN
importTool("--into", dbRule.getStoreDirAbsolutePath(), "--nodes", nodeHeader(config, groupOne) + MULTI_FILE_DELIMITER + nodeData(false, config, groupOneNodeIds, TRUE), "--nodes", nodeHeader(config, groupTwo) + MULTI_FILE_DELIMITER + nodeData(false, config, groupTwoNodeIds, TRUE), "--relationships", relationshipHeader(config, groupOne, groupTwo, true) + MULTI_FILE_DELIMITER + relationshipData(false, config, rels.iterator(), TRUE, true));
// THEN
GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
try (Transaction tx = db.beginTx()) {
int nodeCount = 0;
for (Node node : db.getAllNodes()) {
assertTrue(node.hasProperty("name"));
nodeCount++;
assertEquals(1, Iterables.count(node.getRelationships()));
}
assertEquals(6, nodeCount);
tx.success();
}
}
use of org.neo4j.unsafe.impl.batchimport.input.csv.Configuration in project neo4j by neo4j.
the class ImportToolTest method shouldBeAbleToImportAnonymousNodes.
@Test
public void shouldBeAbleToImportAnonymousNodes() throws Exception {
// GIVEN
List<String> nodeIds = asList("1", "", "", "", "3", "", "", "", "", "", "5");
Configuration config = Configuration.COMMAS;
List<RelationshipDataLine> relationshipData = asList(relationship("1", "3", "KNOWS"));
// WHEN
importTool("--into", dbRule.getStoreDirAbsolutePath(), "--nodes", nodeData(true, config, nodeIds, TRUE).getAbsolutePath(), "--relationships", relationshipData(true, config, relationshipData.iterator(), TRUE, true).getAbsolutePath());
// THEN
GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
try (Transaction tx = db.beginTx()) {
Iterable<Node> allNodes = db.getAllNodes();
int anonymousCount = 0;
for (final String id : nodeIds) {
if (id.isEmpty()) {
anonymousCount++;
} else {
assertNotNull(Iterators.single(Iterators.filter(nodeFilter(id), allNodes.iterator())));
}
}
assertEquals(anonymousCount, count(Iterators.filter(nodeFilter(""), allNodes.iterator())));
tx.success();
}
}
Aggregations