Search in sources :

Example 16 with Configuration

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

the class ImportCommandTest method shouldSupplyArgumentsAsFile.

@Test
void shouldSupplyArgumentsAsFile() throws Exception {
    // given
    List<String> nodeIds = nodeIds();
    Configuration config = COMMAS;
    Path argumentFile = file("args");
    String nodesEscapedSpaces = nodeData(true, config, nodeIds, TRUE).toAbsolutePath().toString();
    String relationshipsEscapedSpaced = relationshipData(true, config, nodeIds, TRUE, true).toAbsolutePath().toString();
    Path dbConfig = prepareDefaultConfigFile();
    String arguments = format("--additional-config=%s%n" + "--nodes=%s%n" + "--relationships=%s%n", dbConfig.toAbsolutePath().toString(), nodesEscapedSpaces, relationshipsEscapedSpaced);
    writeToFile(argumentFile, arguments, false);
    // when
    runImport("@" + argumentFile.toAbsolutePath().toString());
    // then
    verifyData();
}
Also used : Path(java.nio.file.Path) Configuration(org.neo4j.csv.reader.Configuration) Test(org.junit.jupiter.api.Test)

Example 17 with Configuration

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

the class ImportCommandTest method shouldAcceptSpecialTabCharacterAsDelimiterConfiguration.

@Test
void shouldAcceptSpecialTabCharacterAsDelimiterConfiguration() throws Exception {
    // GIVEN
    List<String> nodeIds = nodeIds();
    Configuration config = Configuration.TABS;
    Path dbConfig = prepareDefaultConfigFile();
    // WHEN
    runImport("--additional-config", dbConfig.toAbsolutePath().toString(), "--delimiter", "\\t", "--array-delimiter", String.valueOf(config.arrayDelimiter()), "--nodes", nodeData(true, config, nodeIds, TRUE).toAbsolutePath().toString(), "--relationships", relationshipData(true, 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 18 with Configuration

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

the class ImportCommandTest method shouldBeAbleToImportAnonymousNodes.

@Test
void shouldBeAbleToImportAnonymousNodes() throws Exception {
    // GIVEN
    List<String> nodeIds = asList("1", "", "", "", "3", "", "", "", "", "", "5");
    Configuration config = Configuration.COMMAS;
    List<RelationshipDataLine> relationshipData = asList(relationship("1", "3", "KNOWS"));
    Path dbConfig = prepareDefaultConfigFile();
    // WHEN
    runImport("--additional-config", dbConfig.toAbsolutePath().toString(), "--nodes", nodeData(true, config, nodeIds, TRUE).toAbsolutePath().toString(), "--relationships", relationshipData(true, config, relationshipData.iterator(), TRUE, true).toAbsolutePath().toString());
    // THEN
    GraphDatabaseService db = getDatabaseApi();
    try (Transaction tx = db.beginTx()) {
        Iterable<Node> allNodes = tx.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.commit();
    }
}
Also used : Path(java.nio.file.Path) GraphDatabaseService(org.neo4j.graphdb.GraphDatabaseService) Configuration(org.neo4j.csv.reader.Configuration) Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Test(org.junit.jupiter.api.Test)

Example 19 with Configuration

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

the class ImportCommandTest method shouldIncludeSourceInformationInNodeIdCollisionError.

@Test
void shouldIncludeSourceInformationInNodeIdCollisionError() throws Exception {
    // GIVEN
    List<String> nodeIds = asList("a", "b", "c", "d", "e", "f", "a", "g");
    Configuration config = Configuration.COMMAS;
    Path nodeHeaderFile = nodeHeader(config);
    Path nodeData1 = nodeData(false, config, nodeIds, lines(0, 4));
    Path nodeData2 = nodeData(false, config, nodeIds, lines(4, nodeIds.size()));
    // WHEN
    var e = assertThrows(Exception.class, () -> runImport("--nodes", nodeHeaderFile.toAbsolutePath().toString() + "," + nodeData1.toAbsolutePath().toString() + "," + nodeData2.toAbsolutePath().toString()));
    assertExceptionContains(e, "'a' is defined more than once", DuplicateInputIdException.class);
}
Also used : Path(java.nio.file.Path) Configuration(org.neo4j.csv.reader.Configuration) Test(org.junit.jupiter.api.Test)

Example 20 with Configuration

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

the class ImportCommandTest method shouldKeepStoreFilesAfterFailedImport.

@Test
void shouldKeepStoreFilesAfterFailedImport() throws Exception {
    // GIVEN
    List<String> nodeIds = nodeIds();
    Configuration config = Configuration.COMMAS;
    final var configFile = prepareDefaultConfigFile();
    // WHEN data file contains more columns than header file
    int extraColumns = 3;
    var e = assertThrows(InputException.class, () -> runImport("--additional-config=" + configFile.toAbsolutePath().toString(), "--nodes", nodeHeader(config).toAbsolutePath().toString() + "," + nodeData(false, config, nodeIds, TRUE, Charset.defaultCharset(), extraColumns).toAbsolutePath().toString()));
    // THEN the store files should be there
    for (StoreType storeType : StoreType.values()) {
        assertTrue(Files.exists(databaseLayout.file(storeType.getDatabaseFile())));
    }
    List<String> errorLines = suppressOutput.getErrorVoice().lines();
    assertContains(errorLines, "Starting a database on these store files will likely fail or observe inconsistent records");
}
Also used : StoreType(org.neo4j.kernel.impl.store.StoreType) 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