Search in sources :

Example 26 with Input

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

the class CsvInputTest method shouldCloseDataIteratorsInTheEnd.

@Test
public void shouldCloseDataIteratorsInTheEnd() throws Exception {
    // GIVEN
    CapturingDataFactories nodeData = new CapturingDataFactories(config -> charReader("1"), NO_DECORATOR);
    CapturingDataFactories relationshipData = new CapturingDataFactories(config -> charReader("1,1"), InputEntityDecorators.defaultRelationshipType("TYPE"));
    IdType idType = IdType.STRING;
    Input input = new CsvInput(nodeData, header(entry(null, Type.ID, CsvInput.idExtractor(idType, extractors))), relationshipData, header(entry(null, Type.START_ID, CsvInput.idExtractor(idType, extractors)), entry(null, Type.END_ID, CsvInput.idExtractor(idType, extractors))), idType, config(), NO_MONITOR, INSTANCE);
    // WHEN
    try (InputIterator iterator = input.nodes(EMPTY).iterator()) {
        readNext(iterator);
    }
    try (InputIterator iterator = input.relationships(EMPTY).iterator()) {
        readNext(iterator);
    }
    // THEN
    assertClosed(nodeData.last());
    assertClosed(relationshipData.last());
}
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 27 with Input

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

the class CsvInputTest method shouldAllowSomeNodesToBeAnonymous.

@Test
public void shouldAllowSomeNodesToBeAnonymous() throws Exception {
    // GIVEN
    DataFactory data = data(":ID,name:string,level:int\n" + "abc,Mattias,1\n" + // this node is anonymous
    ",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, "abc", 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)

Example 28 with Input

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

the class CsvInputTest method shouldAllowNodesToBeAnonymousEvenIfIdHeaderIsNamed.

@Test
public void shouldAllowNodesToBeAnonymousEvenIfIdHeaderIsNamed() throws Exception {
    // GIVEN
    DataFactory data = data("id:ID,name:string,level:int\n" + "abc,Mattias,1\n" + // this node is anonymous
    ",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, "abc", new Object[] { "id", "abc", "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)

Example 29 with Input

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

the class CsvInputTest method shouldSkipRelationshipValidationIfToldTo.

@Test
public void shouldSkipRelationshipValidationIfToldTo() throws Exception {
    // GIVEN
    Iterable<DataFactory> data = datas(CsvInputTest.data(":START_ID,:END_ID,:TYPE\n" + ",,"));
    Input input = new CsvInput(datas(), defaultFormatNodeFileHeader(), data, defaultFormatRelationshipFileHeader(), IdType.INTEGER, config(), NO_MONITOR, INSTANCE);
    // WHEN
    try (InputIterator relationships = input.relationships(EMPTY).iterator()) {
        readNext(relationships);
        assertNull(visitor.startId());
        assertNull(visitor.endId());
        assertNull(visitor.stringType);
    }
}
Also used : InputIterator(org.neo4j.internal.batchimport.InputIterator) Input(org.neo4j.internal.batchimport.input.Input) Test(org.junit.Test)

Example 30 with Input

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

the class CsvInputTest method shouldHaveNodesBelongToGroupSpecifiedInHeader.

@Test
public void shouldHaveNodesBelongToGroupSpecifiedInHeader() throws Exception {
    // GIVEN
    IdType idType = IdType.INTEGER;
    Iterable<DataFactory> data = dataIterable(data("123,one\n" + "456,two"));
    Groups groups = new Groups();
    Group group = groups.getOrCreate("MyGroup");
    Input input = new CsvInput(data, header(entry(null, Type.ID, group.name(), CsvInput.idExtractor(idType, extractors)), entry("name", Type.PROPERTY, extractors.string())), datas(), defaultFormatRelationshipFileHeader(), idType, config(), NO_MONITOR, INSTANCE);
    // WHEN/THEN
    try (InputIterator nodes = input.nodes(EMPTY).iterator()) {
        assertNextNode(nodes, group, 123L, properties("name", "one"), labels());
        assertNextNode(nodes, group, 456L, properties("name", "two"), labels());
        assertFalse(readNext(nodes));
    }
}
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)

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