Search in sources :

Example 1 with Configuration

use of org.neo4j.csv.reader.Configuration in project neo4j by neo4j.

the class ImportCommandTest method skipLoggingOfBadEntries.

@Test
void skipLoggingOfBadEntries() 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", "aa"), // line 3 of file1
    relationship("c", "bogus", "TYPE", "bb"), // line 1 of file2
    relationship("b", "c", "KNOWS", "cc"), // line 2 of file2
    relationship("c", "a", "KNOWS", "dd"), // line 3 of file2
    relationship("missing", "a", "KNOWS", "ee"));
    Path relationshipData1 = relationshipData(true, config, relationships.iterator(), lines(0, 2), true);
    Path relationshipData2 = relationshipData(false, config, relationships.iterator(), lines(2, 5), true);
    Path dbConfig = prepareDefaultConfigFile();
    // WHEN importing data where some relationships refer to missing nodes
    runImport("--additional-config", dbConfig.toAbsolutePath().toString(), "--nodes", nodeData.toAbsolutePath().toString(), "--bad-tolerance", "2", "--skip-bad-entries-logging", "true", "--relationships", relationshipData1.toAbsolutePath().toString() + "," + relationshipData2.toAbsolutePath().toString());
    assertFalse(Files.exists(badFile()));
    verifyRelationships(relationships);
}
Also used : Path(java.nio.file.Path) Configuration(org.neo4j.csv.reader.Configuration) Test(org.junit.jupiter.api.Test)

Example 2 with Configuration

use of org.neo4j.csv.reader.Configuration in project neo4j by neo4j.

the class ImportCommandTest method shouldHandleAdditiveLabelsWithSpaces.

@Test
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");
    Path dbConfig = prepareDefaultConfigFile();
    // WHEN
    runImport("--additional-config", dbConfig.toAbsolutePath().toString(), "--nodes=My First Label:My Other Label=" + nodeData(true, config, nodeIds, TRUE).toAbsolutePath().toString(), "--relationships", relationshipData(true, config, nodeIds, TRUE, true).toAbsolutePath().toString());
    // THEN
    verifyData(node -> {
        assertTrue(node.hasLabel(label1));
        assertTrue(node.hasLabel(label2));
    }, Validators.emptyValidator());
}
Also used : Path(java.nio.file.Path) Configuration(org.neo4j.csv.reader.Configuration) Label(org.neo4j.graphdb.Label) Test(org.junit.jupiter.api.Test)

Example 3 with Configuration

use of org.neo4j.csv.reader.Configuration in project neo4j by neo4j.

the class ImportCommandTest method shouldBeAbleToDisableSkippingOfBadRelationships.

@Test
void shouldBeAbleToDisableSkippingOfBadRelationships() 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"));
    Path relationshipData1 = relationshipData(true, config, relationships.iterator(), lines(0, 2), true);
    Path relationshipData2 = relationshipData(false, config, relationships.iterator(), lines(2, 5), 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(), "--skip-bad-relationships=false", "--relationships", relationshipData1.toAbsolutePath().toString() + "," + relationshipData2.toAbsolutePath().toString()));
    assertExceptionContains(e, relationshipData1.toAbsolutePath().toString(), InputException.class);
}
Also used : Path(java.nio.file.Path) Configuration(org.neo4j.csv.reader.Configuration) Test(org.junit.jupiter.api.Test)

Example 4 with Configuration

use of org.neo4j.csv.reader.Configuration in project neo4j by neo4j.

the class ImportCommandTest method shouldDisallowImportWithoutNodesInput.

@Test
void shouldDisallowImportWithoutNodesInput() throws Exception {
    // GIVEN
    List<String> nodeIds = nodeIds();
    Configuration config = Configuration.COMMAS;
    // WHEN
    var e = assertThrows(MissingParameterException.class, () -> runImport("--relationships", relationshipData(true, config, nodeIds, TRUE, true).toAbsolutePath().toString()));
    assertThat(e).hasMessageContaining("Missing required option: '--nodes");
}
Also used : Configuration(org.neo4j.csv.reader.Configuration) Test(org.junit.jupiter.api.Test)

Example 5 with Configuration

use of org.neo4j.csv.reader.Configuration in project neo4j by neo4j.

the class ImportCommandTest method shouldWarnIfHeaderHasLessColumnsThanDataWhenToldTo.

@Test
void shouldWarnIfHeaderHasLessColumnsThanDataWhenToldTo() throws Exception {
    // GIVEN
    List<String> nodeIds = nodeIds();
    Configuration config = Configuration.TABS;
    Path bad = badFile();
    // WHEN data file contains more columns than header file
    int extraColumns = 3;
    runImport("--report-file", bad.toAbsolutePath().toString(), "--bad-tolerance", Integer.toString(nodeIds.size() * extraColumns), "--ignore-extra-columns", "--delimiter", "TAB", "--array-delimiter", String.valueOf(config.arrayDelimiter()), "--nodes=" + nodeHeader(config).toAbsolutePath().toString() + "," + nodeData(false, config, nodeIds, TRUE, Charset.defaultCharset(), extraColumns).toAbsolutePath().toString(), "--relationships", relationshipHeader(config).toAbsolutePath().toString() + "," + relationshipData(false, config, nodeIds, TRUE, true).toAbsolutePath().toString());
    // THEN
    String badContents = Files.readString(bad, Charset.defaultCharset());
    assertTrue(badContents.contains("Extra column not present in header on line"));
}
Also used : Path(java.nio.file.Path) Configuration(org.neo4j.csv.reader.Configuration) Test(org.junit.jupiter.api.Test)

Aggregations

Configuration (org.neo4j.csv.reader.Configuration)31 Test (org.junit.jupiter.api.Test)27 Path (java.nio.file.Path)24 Node (org.neo4j.graphdb.Node)5 Transaction (org.neo4j.graphdb.Transaction)5 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)4 Configuration.defaultConfiguration (org.neo4j.internal.batchimport.Configuration.defaultConfiguration)3 Label (org.neo4j.graphdb.Label)2 Input (org.neo4j.internal.batchimport.input.Input)2 Charset (java.nio.charset.Charset)1 HashSet (java.util.HashSet)1 MutableInt (org.apache.commons.lang3.mutable.MutableInt)1 Test (org.junit.Test)1 Config (org.neo4j.configuration.Config)1 Extractors (org.neo4j.csv.reader.Extractors)1 BatchImporter (org.neo4j.internal.batchimport.BatchImporter)1 IndexConfig (org.neo4j.internal.batchimport.IndexConfig)1 InputIterator (org.neo4j.internal.batchimport.InputIterator)1 ParallelBatchImporter (org.neo4j.internal.batchimport.ParallelBatchImporter)1 DataGeneratorInput (org.neo4j.internal.batchimport.input.DataGeneratorInput)1