Search in sources :

Example 11 with Input

use of org.neo4j.internal.batchimport.input.Input in project neo4j by neo4j.

the class CsvInputTest method shouldCopeWithLinesThatHasTooFewValuesButStillValidates.

@Test
public void shouldCopeWithLinesThatHasTooFewValuesButStillValidates() throws Exception {
    // GIVEN
    Iterable<DataFactory> data = dataIterable(data("1,ultralisk,ZERG,10\n" + "2,corruptor,ZERG\n" + "3,mutalisk,ZERG,3"));
    Input input = new CsvInput(data, header(entry(null, Type.ID, extractors.long_()), entry("unit", Type.PROPERTY, extractors.string()), entry("type", Type.LABEL, extractors.string()), entry("kills", Type.PROPERTY, extractors.int_())), datas(), defaultFormatRelationshipFileHeader(), ACTUAL, config(), NO_MONITOR, INSTANCE);
    // WHEN
    try (InputIterator nodes = input.nodes(EMPTY).iterator()) {
        // THEN
        assertNextNode(nodes, 1L, new Object[] { "unit", "ultralisk", "kills", 10 }, labels("ZERG"));
        assertNextNode(nodes, 2L, new Object[] { "unit", "corruptor" }, labels("ZERG"));
        assertNextNode(nodes, 3L, new Object[] { "unit", "mutalisk", "kills", 3 }, labels("ZERG"));
        assertFalse(readNext(nodes));
    }
}
Also used : InputIterator(org.neo4j.internal.batchimport.InputIterator) Input(org.neo4j.internal.batchimport.input.Input) Test(org.junit.Test)

Example 12 with Input

use of org.neo4j.internal.batchimport.input.Input 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)

Example 13 with Input

use of org.neo4j.internal.batchimport.input.Input in project neo4j by neo4j.

the class CsvInputTest method shouldHaveRelationshipsSpecifyStartEndNodeIdGroupsInHeader.

@Test
public void shouldHaveRelationshipsSpecifyStartEndNodeIdGroupsInHeader() throws Exception {
    // GIVEN
    IdType idType = IdType.INTEGER;
    Iterable<DataFactory> data = dataIterable(data("123,TYPE,234\n" + "345,TYPE,456"));
    Groups groups = new Groups();
    Group startNodeGroup = groups.getOrCreate("StartGroup");
    Group endNodeGroup = groups.getOrCreate("EndGroup");
    Iterable<DataFactory> nodeHeader = dataIterable(data(":ID(" + startNodeGroup.name() + ")"), data(":ID(" + endNodeGroup.name() + ")"));
    Input input = new CsvInput(nodeHeader, defaultFormatNodeFileHeader(), data, header(entry(null, Type.START_ID, startNodeGroup.name(), CsvInput.idExtractor(idType, extractors)), entry(null, Type.TYPE, extractors.string()), entry(null, Type.END_ID, endNodeGroup.name(), CsvInput.idExtractor(idType, extractors))), idType, config(), NO_MONITOR, INSTANCE);
    // WHEN/THEN
    try (InputIterator relationships = input.relationships(EMPTY).iterator()) {
        assertRelationship(relationships, startNodeGroup, 123L, endNodeGroup, 234L, "TYPE", properties());
        assertRelationship(relationships, startNodeGroup, 345L, endNodeGroup, 456L, "TYPE", properties());
        assertFalse(readNext(relationships));
    }
}
Also used : Group(org.neo4j.internal.batchimport.input.Group) InputIterator(org.neo4j.internal.batchimport.InputIterator) Input(org.neo4j.internal.batchimport.input.Input) Groups(org.neo4j.internal.batchimport.input.Groups) IdType(org.neo4j.internal.batchimport.input.IdType) Test(org.junit.Test)

Example 14 with Input

use of org.neo4j.internal.batchimport.input.Input in project neo4j by neo4j.

the class CsvInputTest method shouldProvideRelationshipsFromCsvInput.

@Test
public void shouldProvideRelationshipsFromCsvInput() throws Exception {
    // GIVEN
    IdType idType = IdType.STRING;
    Iterable<DataFactory> data = dataIterable(data("node1,node2,KNOWS,1234567\n" + "node2,node10,HACKS,987654"));
    Input input = new CsvInput(datas(), defaultFormatNodeFileHeader(), data, header(entry("from", Type.START_ID, CsvInput.idExtractor(idType, extractors)), entry("to", Type.END_ID, CsvInput.idExtractor(idType, extractors)), entry("type", Type.TYPE, extractors.string()), entry("since", Type.PROPERTY, extractors.long_())), idType, config(), NO_MONITOR, INSTANCE);
    // WHEN/THEN
    try (InputIterator relationships = input.relationships(EMPTY).iterator()) {
        assertNextRelationship(relationships, "node1", "node2", "KNOWS", properties("since", 1234567L));
        assertNextRelationship(relationships, "node2", "node10", "HACKS", properties("since", 987654L));
    }
}
Also used : InputIterator(org.neo4j.internal.batchimport.InputIterator) Input(org.neo4j.internal.batchimport.input.Input) IdType(org.neo4j.internal.batchimport.input.IdType) Test(org.junit.Test)

Example 15 with Input

use of org.neo4j.internal.batchimport.input.Input in project neo4j by neo4j.

the class CsvInputTest method shouldAllowNodesWithoutIdHeader.

@Test
public void shouldAllowNodesWithoutIdHeader() throws Exception {
    // GIVEN
    DataFactory data = data("name:string,level:int\n" + "Mattias,1\n" + "Johan,2\n");
    Iterable<DataFactory> dataIterable = dataIterable(data);
    Input input = new CsvInput(dataIterable, defaultFormatNodeFileHeader(), datas(), defaultFormatRelationshipFileHeader(), IdType.STRING, config(), NO_MONITOR, INSTANCE);
    // WHEN
    try (InputIterator nodes = input.nodes(EMPTY).iterator()) {
        // THEN
        assertNextNode(nodes, null, new Object[] { "name", "Mattias", "level", 1 }, labels());
        assertNextNode(nodes, null, new Object[] { "name", "Johan", "level", 2 }, labels());
        assertFalse(readNext(nodes));
    }
}
Also used : InputIterator(org.neo4j.internal.batchimport.InputIterator) Input(org.neo4j.internal.batchimport.input.Input) Test(org.junit.Test)

Aggregations

Input (org.neo4j.internal.batchimport.input.Input)43 Test (org.junit.Test)36 InputIterator (org.neo4j.internal.batchimport.InputIterator)36 IdType (org.neo4j.internal.batchimport.input.IdType)8 Groups (org.neo4j.internal.batchimport.input.Groups)5 JobScheduler (org.neo4j.scheduler.JobScheduler)5 Matchers.containsString (org.hamcrest.Matchers.containsString)4 Test (org.junit.jupiter.api.Test)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 Config (org.neo4j.configuration.Config)3 Group (org.neo4j.internal.batchimport.input.Group)3 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)3 ThreadPoolJobScheduler (org.neo4j.test.scheduler.ThreadPoolJobScheduler)3 Path (java.nio.file.Path)2 ParallelBatchImporter (org.neo4j.internal.batchimport.ParallelBatchImporter)2 ExecutionMonitor (org.neo4j.internal.batchimport.staging.ExecutionMonitor)2 IndexImporterFactoryImpl (org.neo4j.kernel.impl.index.schema.IndexImporterFactoryImpl)2 NullLogProvider (org.neo4j.logging.NullLogProvider)2 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1