Search in sources :

Example 11 with Configuration

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

the class ImportCommandTest method shouldImportSplitInputFiles.

@Test
void shouldImportSplitInputFiles() throws Exception {
    // GIVEN
    List<String> nodeIds = nodeIds();
    Configuration config = Configuration.COMMAS;
    Path dbConfig = prepareDefaultConfigFile();
    // WHEN
    runImport("--additional-config", dbConfig.toAbsolutePath().toString(), // One group with one header file and one data file
    "--nodes", nodeHeader(config).toAbsolutePath().toString() + "," + nodeData(false, config, nodeIds, lines(0, NODE_COUNT / 2)).toAbsolutePath().toString(), // One group with two data files, where the header sits in the first file
    "--nodes", nodeData(true, config, nodeIds, lines(NODE_COUNT / 2, NODE_COUNT * 3 / 4)).toAbsolutePath().toString() + "," + nodeData(false, config, nodeIds, lines(NODE_COUNT * 3 / 4, NODE_COUNT)).toAbsolutePath().toString(), "--relationships", relationshipHeader(config).toAbsolutePath().toString() + "," + relationshipData(false, config, nodeIds, TRUE, true).toAbsolutePath().toString());
    // THEN
    verifyData();
}
Also used : Path(java.nio.file.Path) Configuration(org.neo4j.csv.reader.Configuration) Test(org.junit.jupiter.api.Test)

Example 12 with Configuration

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

the class ImportCommandTest method shouldNotImportOnEmptyExistingDatabase.

@Test
void shouldNotImportOnEmptyExistingDatabase() throws Exception {
    // Given a db with default token indexes
    createDefaultDatabaseWithTokenIndexes();
    List<String> nodeIds = nodeIds();
    Configuration config = COMMAS;
    Path dbConfig = defaultConfig();
    // When csv is imported
    assertThatThrownBy(() -> runImport("--additional-config", dbConfig.toAbsolutePath().toString(), "--nodes", nodeData(true, config, nodeIds, TRUE).toAbsolutePath().toString(), "--high-io", "false", "--relationships", relationshipData(true, config, nodeIds, TRUE, true).toAbsolutePath().toString())).hasCauseInstanceOf(DirectoryNotEmptyException.class);
}
Also used : Path(java.nio.file.Path) Configuration(org.neo4j.csv.reader.Configuration) Test(org.junit.jupiter.api.Test)

Example 13 with Configuration

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

the class ImportCommandTest method shouldFailIfHeaderHasLessColumnsThanData.

@Test
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;
    var e = assertThrows(InputException.class, () -> runImport("--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()));
    assertTrue(suppressOutput.getOutputVoice().containsMessage("IMPORT FAILED"));
    assertFalse(suppressOutput.getErrorVoice().containsMessage(e.getClass().getName()));
    assertTrue(e.getMessage().contains("Extra column not present in header on line"));
}
Also used : Configuration(org.neo4j.csv.reader.Configuration) Test(org.junit.jupiter.api.Test)

Example 14 with Configuration

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

the class ImportCommandTest method failOnInvalidDatabaseName.

@Test
void failOnInvalidDatabaseName() throws Exception {
    List<String> nodeIds = nodeIds();
    Configuration config = Configuration.COMMAS;
    Path dbConfig = prepareDefaultConfigFile();
    var e = assertThrows(Exception.class, () -> runImport("--additional-config", dbConfig.toAbsolutePath().toString(), "--nodes", nodeData(true, config, nodeIds, TRUE).toAbsolutePath().toString(), "--database", "__incorrect_db__"));
    assertThat(e).hasMessageContaining("Invalid database name '__incorrect_db__'.");
}
Also used : Path(java.nio.file.Path) Configuration(org.neo4j.csv.reader.Configuration) Test(org.junit.jupiter.api.Test)

Example 15 with Configuration

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

the class ImportCommandTest method shouldLogRelationshipsReferringToMissingNode.

@Test
void shouldLogRelationshipsReferringToMissingNode() 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 bad = badFile();
    Path dbConfig = prepareDefaultConfigFile();
    // WHEN importing data where some relationships refer to missing nodes
    runImport("--nodes", nodeData.toAbsolutePath().toString(), "--report-file", bad.toAbsolutePath().toString(), "--skip-bad-relationships", "--bad-tolerance", "2", "--additional-config", dbConfig.toAbsolutePath().toString(), "--relationships", relationshipData1.toAbsolutePath().toString() + "," + relationshipData2.toAbsolutePath().toString());
    // THEN
    String badContents = Files.readString(bad, Charset.defaultCharset());
    assertTrue(badContents.contains("bogus"), "Didn't contain first bad relationship");
    assertTrue(badContents.contains("missing"), "Didn't contain second bad relationship");
    verifyRelationships(relationships);
}
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