Search in sources :

Example 21 with Configuration

use of org.neo4j.unsafe.impl.batchimport.input.csv.Configuration in project neo4j by neo4j.

the class ImportToolTest method shouldFailIfTooManyBadRelationships.

@Test
public void shouldFailIfTooManyBadRelationships() 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"), //         line 1 of file2
    relationship("b", "c", "KNOWS"), //         line 2 of file2
    relationship("c", "a", "KNOWS"), // line 3 of file2
    relationship("missing", "a", "KNOWS"));
    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(), "--bad-tolerance", "1", "--relationships", relationshipData1.getAbsolutePath() + MULTI_FILE_DELIMITER + relationshipData2.getAbsolutePath());
    } catch (Exception e) {
        // THEN
        assertExceptionContains(e, relationshipData2.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 22 with Configuration

use of org.neo4j.unsafe.impl.batchimport.input.csv.Configuration in project neo4j by neo4j.

the class ImportToolTest method shouldDisallowImportWithoutNodesInput.

@Test
public void shouldDisallowImportWithoutNodesInput() throws Exception {
    // GIVEN
    List<String> nodeIds = nodeIds();
    Configuration config = Configuration.COMMAS;
    // WHEN
    try {
        importTool("--into", dbRule.getStoreDirAbsolutePath(), "--relationships", relationshipData(true, config, nodeIds, TRUE, true).getAbsolutePath());
        fail("Should have failed");
    } catch (IllegalArgumentException e) {
        // THEN
        assertThat(e.getMessage(), containsString("No node input"));
    }
}
Also used : Configuration(org.neo4j.unsafe.impl.batchimport.input.csv.Configuration) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 23 with Configuration

use of org.neo4j.unsafe.impl.batchimport.input.csv.Configuration in project neo4j by neo4j.

the class ImportToolTest method shouldFailIfHeaderHasLessColumnsThanData.

@Test
public void shouldFailIfHeaderHasLessColumnsThanData() throws Exception {
    // GIVEN
    List<String> nodeIds = nodeIds();
    Configuration config = Configuration.TABS;
    // WHEN data file contains more columns than header file
    int extraColumns = 3;
    try {
        importTool("--into", dbRule.getStoreDirAbsolutePath(), "--delimiter", "TAB", "--array-delimiter", String.valueOf(config.arrayDelimiter()), "--nodes", nodeHeader(config).getAbsolutePath() + MULTI_FILE_DELIMITER + nodeData(false, config, nodeIds, TRUE, Charset.defaultCharset(), extraColumns).getAbsolutePath(), "--relationships", relationshipHeader(config).getAbsolutePath() + MULTI_FILE_DELIMITER + relationshipData(false, config, nodeIds, TRUE, true).getAbsolutePath());
        fail("Should have thrown exception");
    } catch (InputException e) {
        // THEN
        assertFalse(suppressOutput.getErrorVoice().containsMessage(e.getClass().getName()));
        assertTrue(e.getMessage().contains("Extra column not present in header on line"));
    }
}
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) Test(org.junit.Test)

Example 24 with Configuration

use of org.neo4j.unsafe.impl.batchimport.input.csv.Configuration in project neo4j by neo4j.

the class ImportToolTest method shouldImportOnlyNodes.

@Test
public void shouldImportOnlyNodes() throws Exception {
    // GIVEN
    List<String> nodeIds = nodeIds();
    Configuration config = Configuration.COMMAS;
    // WHEN
    importTool("--into", dbRule.getStoreDirAbsolutePath(), "--nodes", nodeData(true, config, nodeIds, TRUE).getAbsolutePath());
    // no relationships
    // THEN
    GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
    try (Transaction tx = db.beginTx()) {
        int nodeCount = 0;
        for (Node node : db.getAllNodes()) {
            assertTrue(node.hasProperty("name"));
            nodeCount++;
            assertFalse(node.hasRelationship());
        }
        assertEquals(NODE_COUNT, 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 25 with Configuration

use of org.neo4j.unsafe.impl.batchimport.input.csv.Configuration in project neo4j by neo4j.

the class ImportToolTest method shouldHandleAdditiveLabelsWithSpaces.

@Test
public void shouldHandleAdditiveLabelsWithSpaces() throws Exception {
    // GIVEN
    List<String> nodeIds = nodeIds();
    Configuration config = Configuration.COMMAS;
    final Label label1 = label("My First Label");
    final Label label2 = label("My Other Label");
    // WHEN
    importTool("--into", dbRule.getStoreDirAbsolutePath(), "--nodes:My First Label:My Other Label", nodeData(true, config, nodeIds, TRUE).getAbsolutePath(), "--relationships", relationshipData(true, config, nodeIds, TRUE, true).getAbsolutePath());
    // THEN
    verifyData(node -> {
        assertTrue(node.hasLabel(label1));
        assertTrue(node.hasLabel(label2));
    }, Validators.<Relationship>emptyValidator());
}
Also used : Configuration(org.neo4j.unsafe.impl.batchimport.input.csv.Configuration) Label(org.neo4j.graphdb.Label) DynamicLabel(org.neo4j.graphdb.DynamicLabel) 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