Search in sources :

Example 6 with Configuration

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);
    }
}
Also used : Configuration(org.neo4j.unsafe.impl.batchimport.input.csv.Configuration) InputException(org.neo4j.unsafe.impl.batchimport.input.InputException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) File(java.io.File) IllegalMultilineFieldException(org.neo4j.csv.reader.IllegalMultilineFieldException) FileNotFoundException(java.io.FileNotFoundException) DuplicateInputIdException(org.neo4j.unsafe.impl.batchimport.cache.idmapping.string.DuplicateInputIdException) InputException(org.neo4j.unsafe.impl.batchimport.input.InputException) IOException(java.io.IOException) Test(org.junit.Test)

Example 7 with Configuration

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);
    }
}
Also used : Configuration(org.neo4j.unsafe.impl.batchimport.input.csv.Configuration) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) File(java.io.File) IllegalMultilineFieldException(org.neo4j.csv.reader.IllegalMultilineFieldException) FileNotFoundException(java.io.FileNotFoundException) DuplicateInputIdException(org.neo4j.unsafe.impl.batchimport.cache.idmapping.string.DuplicateInputIdException) InputException(org.neo4j.unsafe.impl.batchimport.input.InputException) IOException(java.io.IOException) DuplicateInputIdException(org.neo4j.unsafe.impl.batchimport.cache.idmapping.string.DuplicateInputIdException) Test(org.junit.Test)

Example 8 with Configuration

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();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Configuration(org.neo4j.unsafe.impl.batchimport.input.csv.Configuration) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) DynamicLabel(org.neo4j.graphdb.DynamicLabel) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) File(java.io.File) Test(org.junit.Test)

Example 9 with Configuration

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();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Configuration(org.neo4j.unsafe.impl.batchimport.input.csv.Configuration) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 10 with Configuration

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();
    }
}
Also used : GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Configuration(org.neo4j.unsafe.impl.batchimport.input.csv.Configuration) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Aggregations

Configuration (org.neo4j.unsafe.impl.batchimport.input.csv.Configuration)27 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)22 Test (org.junit.Test)22 File (java.io.File)7 InputException (org.neo4j.unsafe.impl.batchimport.input.InputException)7 FileNotFoundException (java.io.FileNotFoundException)5 IOException (java.io.IOException)5 IllegalMultilineFieldException (org.neo4j.csv.reader.IllegalMultilineFieldException)5 DuplicateInputIdException (org.neo4j.unsafe.impl.batchimport.cache.idmapping.string.DuplicateInputIdException)5 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)4 Node (org.neo4j.graphdb.Node)4 Transaction (org.neo4j.graphdb.Transaction)4 DynamicLabel (org.neo4j.graphdb.DynamicLabel)2 Label (org.neo4j.graphdb.Label)2 Charset (java.nio.charset.Charset)1 Extractors (org.neo4j.csv.reader.Extractors)1 Args (org.neo4j.helpers.Args)1 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)1 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)1 SimpleLogService (org.neo4j.kernel.impl.logging.SimpleLogService)1