Search in sources :

Example 6 with Configuration

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

the class ImportCommandTest method shouldImportWithHeadersBeingInSeparateFiles.

@Test
void shouldImportWithHeadersBeingInSeparateFiles() throws Exception {
    // GIVEN
    List<String> nodeIds = nodeIds();
    Configuration config = Configuration.TABS;
    Path dbConfig = prepareDefaultConfigFile();
    // WHEN
    runImport("--additional-config", dbConfig.toAbsolutePath().toString(), "--delimiter", "TAB", "--array-delimiter", String.valueOf(config.arrayDelimiter()), "--nodes", nodeHeader(config).toAbsolutePath().toString() + "," + nodeData(false, config, nodeIds, TRUE).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 7 with Configuration

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

the class ImportCommandTest method shouldBeAbleToMixSpecifiedAndUnspecifiedGroups.

@Test
void shouldBeAbleToMixSpecifiedAndUnspecifiedGroups() throws Exception {
    // GIVEN
    List<String> groupOneNodeIds = asList("1", "2", "3");
    List<String> groupTwoNodeIds = asList("4", "5", "2");
    Configuration config = Configuration.COMMAS;
    Path dbConfig = prepareDefaultConfigFile();
    // WHEN
    runImport("--additional-config", dbConfig.toAbsolutePath().toString(), "--nodes", nodeHeader(config, "MyGroup").toAbsolutePath().toString() + "," + nodeData(false, config, groupOneNodeIds, TRUE).toAbsolutePath().toString(), "--nodes", nodeHeader(config).toAbsolutePath().toString() + "," + nodeData(false, config, groupTwoNodeIds, TRUE).toAbsolutePath().toString());
    // THEN
    verifyData(6, 0, Validators.emptyValidator(), Validators.emptyValidator());
}
Also used : Path(java.nio.file.Path) Configuration(org.neo4j.csv.reader.Configuration) Test(org.junit.jupiter.api.Test)

Example 8 with Configuration

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

the class ImportCommandTest method shouldTreatRelationshipWithMissingStartOrEndIdOrTypeAsBadRelationship.

@Test
void shouldTreatRelationshipWithMissingStartOrEndIdOrTypeAsBadRelationship() 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(relationship("a", null, "TYPE"), relationship(null, "b", "TYPE"), relationship("a", "b", null));
    Path relationshipData = relationshipData(true, config, relationships.iterator(), TRUE, true);
    Path bad = badFile();
    // WHEN importing data where some relationships refer to missing nodes
    runImport("--nodes", nodeData.toAbsolutePath().toString(), "--report-file", bad.toAbsolutePath().toString(), "--skip-bad-relationships", "true", "--relationships", relationshipData.toAbsolutePath().toString());
    String badContents = Files.readString(bad, Charset.defaultCharset());
    assertEquals(3, occurrencesOf(badContents, "is missing data"), badContents);
}
Also used : Path(java.nio.file.Path) Configuration(org.neo4j.csv.reader.Configuration) Test(org.junit.jupiter.api.Test)

Example 9 with Configuration

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

the class QuickImport method parseNodeHeader.

private static Header parseNodeHeader(Args args, IdType idType, Extractors extractors, Groups groups) {
    String definition = args.get("node-header", null);
    if (definition == null) {
        return DataGeneratorInput.bareboneNodeHeader(idType, extractors);
    }
    Configuration config = Configuration.COMMAS;
    return DataFactories.defaultFormatNodeFileHeader().create(seeker(definition, config), config, idType, groups);
}
Also used : Configuration(org.neo4j.csv.reader.Configuration) Configuration.defaultConfiguration(org.neo4j.internal.batchimport.Configuration.defaultConfiguration)

Example 10 with Configuration

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

the class CsvInputTest method shouldTreatEmptyQuotedStringsAsNullIfConfiguredTo.

@Test
public void shouldTreatEmptyQuotedStringsAsNullIfConfiguredTo() throws Exception {
    // GIVEN
    Iterable<DataFactory> data = datas(CsvInputTest.data(":ID,one,two,three\n" + "1,\"\",,value"));
    Configuration config = config().toBuilder().withEmptyQuotedStringsAsNull(true).build();
    Input input = new CsvInput(data, defaultFormatNodeFileHeader(), datas(), defaultFormatRelationshipFileHeader(), IdType.INTEGER, config, NO_MONITOR, INSTANCE);
    // WHEN
    try (InputIterator nodes = input.nodes(EMPTY).iterator()) {
        // THEN
        assertNextNode(nodes, 1L, properties("three", "value"), labels());
        assertFalse(readNext(nodes));
    }
}
Also used : InputIterator(org.neo4j.internal.batchimport.InputIterator) Input(org.neo4j.internal.batchimport.input.Input) Configuration(org.neo4j.csv.reader.Configuration) Test(org.junit.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