Search in sources :

Example 31 with Input

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

the class CsvInputTest method shouldIgnoreEmptyIntPropertyValues.

@Test
public void shouldIgnoreEmptyIntPropertyValues() throws Exception {
    // GIVEN
    DataFactory data = data(":ID,name,extra:int\n" + // here we leave out "extra" property
    "0,Mattias,\n" + "1,Johan,10\n");
    Iterable<DataFactory> dataIterable = dataIterable(data);
    Input input = new CsvInput(dataIterable, defaultFormatNodeFileHeader(), datas(), defaultFormatRelationshipFileHeader(), ACTUAL, config(), NO_MONITOR, INSTANCE);
    // WHEN
    try (InputIterator nodes = input.nodes(EMPTY).iterator()) {
        // THEN
        assertNextNode(nodes, 0L, new Object[] { "name", "Mattias" }, labels());
        assertNextNode(nodes, 1L, new Object[] { "name", "Johan", "extra", 10 }, labels());
        assertFalse(readNext(nodes));
    }
}
Also used : InputIterator(org.neo4j.internal.batchimport.InputIterator) Input(org.neo4j.internal.batchimport.input.Input) Test(org.junit.Test)

Example 32 with Input

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

the class CsvInputTest method shouldParsePointPropertyValuesWithCRSInHeader.

@Test
public void shouldParsePointPropertyValuesWithCRSInHeader() throws Exception {
    // GIVEN
    DataFactory data = data(":ID,name,point:Point{crs:WGS-84-3D}\n" + "0,Johan,\" { height :0.01 ,longitude:5, latitude : -4.2 } \"\n");
    Iterable<DataFactory> dataIterable = dataIterable(data);
    Input input = new CsvInput(dataIterable, defaultFormatNodeFileHeader(), datas(), defaultFormatRelationshipFileHeader(), ACTUAL, config(), NO_MONITOR, INSTANCE);
    // WHEN
    try (InputIterator nodes = input.nodes(EMPTY).iterator()) {
        // THEN
        assertNextNode(nodes, 0L, new Object[] { "name", "Johan", "point", Values.pointValue(CoordinateReferenceSystem.WGS84_3D, 5, -4.2, 0.01) }, labels());
        assertFalse(readNext(nodes));
    }
}
Also used : InputIterator(org.neo4j.internal.batchimport.InputIterator) Input(org.neo4j.internal.batchimport.input.Input) Test(org.junit.Test)

Example 33 with Input

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

the class CsvInputTest method shouldProvideAdditiveLabels.

@Test
public void shouldProvideAdditiveLabels() throws Exception {
    // GIVEN
    String[] addedLabels = { "Two", "AddTwo" };
    DataFactory data = data(":ID,name,:LABEL\n" + "0,First,\n" + "1,Second,One\n" + "2,Third,One;Two", InputEntityDecorators.additiveLabels(addedLabels));
    Iterable<DataFactory> dataIterable = dataIterable(data);
    Input input = new CsvInput(dataIterable, defaultFormatNodeFileHeader(), datas(), defaultFormatRelationshipFileHeader(), ACTUAL, config(), NO_MONITOR, INSTANCE);
    // WHEN/THEN
    try (InputIterator nodes = input.nodes(EMPTY).iterator()) {
        assertNextNode(nodes, 0L, properties("name", "First"), labels(addedLabels));
        assertNextNode(nodes, 1L, properties("name", "Second"), labels(union(new String[] { "One" }, addedLabels)));
        assertNextNode(nodes, 2L, properties("name", "Third"), labels(union(new String[] { "One" }, addedLabels)));
        assertFalse(readNext(nodes));
    }
}
Also used : InputIterator(org.neo4j.internal.batchimport.InputIterator) Input(org.neo4j.internal.batchimport.input.Input) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 34 with Input

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

the class CsvInputTest method shouldNotIncludeEmptyArraysInEntities.

@Test
public void shouldNotIncludeEmptyArraysInEntities() throws Exception {
    // GIVEN
    Iterable<DataFactory> data = datas(CsvInputTest.data(":ID,sprop:String[],lprop:long[]\n" + "1,,\n" + "2,a;b,10;20"));
    Input input = new CsvInput(data, defaultFormatNodeFileHeader(), datas(), defaultFormatNodeFileHeader(), IdType.INTEGER, config(), NO_MONITOR, INSTANCE);
    // WHEN/THEN
    try (InputIterator nodes = input.nodes(EMPTY).iterator()) {
        assertNextNode(nodes, 1L, InputEntity.NO_PROPERTIES, labels());
        assertNextNode(nodes, 2L, properties("sprop", new String[] { "a", "b" }, "lprop", new long[] { 10, 20 }), labels());
        assertFalse(readNext(nodes));
    }
}
Also used : InputIterator(org.neo4j.internal.batchimport.InputIterator) Input(org.neo4j.internal.batchimport.input.Input) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 35 with Input

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

the class CsvInputTest method shouldNotParsePointPropertyValuesWithDuplicateKeys.

@Test
public void shouldNotParsePointPropertyValuesWithDuplicateKeys() throws Exception {
    // GIVEN
    DataFactory data = data(":ID,name,point:Point\n" + "1,Johan,\" { height :0.01 ,longitude:5, latitude : -4.2, latitude : 4.2 } \"\n");
    Iterable<DataFactory> dataIterable = dataIterable(data);
    Input input = new CsvInput(dataIterable, defaultFormatNodeFileHeader(), datas(), defaultFormatRelationshipFileHeader(), ACTUAL, config(), NO_MONITOR, INSTANCE);
    // WHEN
    try (InputIterator nodes = input.nodes(EMPTY).iterator()) {
        // THEN
        readNext(nodes);
        fail("Should have failed when key assigned multiple times, but didn't.");
    } catch (InputException ignore) {
    // this is fine
    }
}
Also used : InputIterator(org.neo4j.internal.batchimport.InputIterator) Input(org.neo4j.internal.batchimport.input.Input) InputException(org.neo4j.internal.batchimport.input.InputException) 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