Search in sources :

Example 36 with InputNode

use of org.neo4j.unsafe.impl.batchimport.input.InputNode in project neo4j by neo4j.

the class CsvInputTest method shouldNotIncludeEmptyArraysInEntities.

@Test
public void shouldNotIncludeEmptyArraysInEntities() throws Exception {
    // GIVEN
    Iterable<DataFactory<InputNode>> data = DataFactories.nodeData(CsvInputTest.<InputNode>data(":ID,sprop:String[],lprop:long[]\n" + "1,,\n" + "2,a;b,10;20"));
    Input input = new CsvInput(data, defaultFormatNodeFileHeader(), null, null, IdType.INTEGER, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
    // WHEN/THEN
    try (InputIterator<InputNode> nodes = input.nodes().iterator()) {
        assertNode(nodes.next(), 1L, NO_PROPERTIES, labels());
        assertNode(nodes.next(), 2L, properties("sprop", new String[] { "a", "b" }, "lprop", new long[] { 10, 20 }), labels());
        assertFalse(nodes.hasNext());
    }
}
Also used : InputNode(org.neo4j.unsafe.impl.batchimport.input.InputNode) Input(org.neo4j.unsafe.impl.batchimport.input.Input) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 37 with InputNode

use of org.neo4j.unsafe.impl.batchimport.input.InputNode in project neo4j by neo4j.

the class CsvInputBatchImportIT method shouldImportDataComingFromCsvFiles.

@Test
public void shouldImportDataComingFromCsvFiles() throws Exception {
    // GIVEN
    BatchImporter importer = new ParallelBatchImporter(directory.graphDbDir(), fileSystemRule.get(), smallBatchSizeConfig(), NullLogService.getInstance(), invisible(), Config.empty());
    List<InputNode> nodeData = randomNodeData();
    List<InputRelationship> relationshipData = randomRelationshipData(nodeData);
    // WHEN
    boolean success = false;
    try {
        importer.doImport(csv(nodeDataAsFile(nodeData), relationshipDataAsFile(relationshipData), IdType.STRING, lowBufferSize(COMMAS), silentBadCollector(0), getRuntime().availableProcessors()));
        // THEN
        verifyImportedData(nodeData, relationshipData);
        success = true;
    } finally {
        if (!success) {
            System.err.println("Seed " + seed);
        }
    }
}
Also used : ParallelBatchImporter(org.neo4j.unsafe.impl.batchimport.ParallelBatchImporter) InputNode(org.neo4j.unsafe.impl.batchimport.input.InputNode) BatchImporter(org.neo4j.unsafe.impl.batchimport.BatchImporter) ParallelBatchImporter(org.neo4j.unsafe.impl.batchimport.ParallelBatchImporter) InputRelationship(org.neo4j.unsafe.impl.batchimport.input.InputRelationship) Test(org.junit.Test)

Example 38 with InputNode

use of org.neo4j.unsafe.impl.batchimport.input.InputNode in project neo4j by neo4j.

the class CsvInputTest method shouldAllowNodesToBeAnonymousEvenIfIdHeaderIsNamed.

@Test
public void shouldAllowNodesToBeAnonymousEvenIfIdHeaderIsNamed() throws Exception {
    // GIVEN
    DataFactory<InputNode> data = data("id:ID,name:string,level:int\n" + "abc,Mattias,1\n" + // this node is anonymous
    ",Johan,2\n");
    Iterable<DataFactory<InputNode>> dataIterable = dataIterable(data);
    Input input = new CsvInput(dataIterable, defaultFormatNodeFileHeader(), null, null, IdType.STRING, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
    // WHEN
    try (ResourceIterator<InputNode> nodes = input.nodes().iterator()) {
        // THEN
        assertNode(nodes.next(), "abc", new Object[] { "id", "abc", "name", "Mattias", "level", 1 }, labels());
        assertNode(nodes.next(), null, new Object[] { "name", "Johan", "level", 2 }, labels());
        assertFalse(nodes.hasNext());
    }
}
Also used : InputNode(org.neo4j.unsafe.impl.batchimport.input.InputNode) Input(org.neo4j.unsafe.impl.batchimport.input.Input) Test(org.junit.Test)

Example 39 with InputNode

use of org.neo4j.unsafe.impl.batchimport.input.InputNode in project neo4j by neo4j.

the class CsvInputTest method shouldPropagateExceptionFromFailingDecorator.

@Test
public void shouldPropagateExceptionFromFailingDecorator() throws Exception {
    // GIVEN
    RuntimeException failure = new RuntimeException("FAILURE");
    Iterable<DataFactory<InputNode>> data = DataFactories.nodeData(CsvInputTest.<InputNode>data(":ID,name\n1,Mattias", new FailingNodeDecorator(failure)));
    Input input = new CsvInput(data, defaultFormatNodeFileHeader(), null, null, IdType.INTEGER, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
    // WHEN
    try (InputIterator<InputNode> nodes = input.nodes().iterator()) {
        nodes.next();
    } catch (RuntimeException e) {
        // THEN
        assertTrue(e == failure);
    }
}
Also used : InputNode(org.neo4j.unsafe.impl.batchimport.input.InputNode) Input(org.neo4j.unsafe.impl.batchimport.input.Input) Test(org.junit.Test)

Example 40 with InputNode

use of org.neo4j.unsafe.impl.batchimport.input.InputNode in project neo4j by neo4j.

the class DataFactoriesTest method shouldParseHeaderFromFirstLineOfFirstInputFile.

@Test
public void shouldParseHeaderFromFirstLineOfFirstInputFile() throws Exception {
    // GIVEN
    final Reader firstSource = new StringReader("id:ID\tname:String\tbirth_date:long");
    final Reader secondSource = new StringReader("0\tThe node\t123456789");
    DataFactory<InputNode> dataFactory = data(value -> value, () -> {
        try {
            return sources(firstSource, secondSource);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    });
    Header.Factory headerFactory = defaultFormatNodeFileHeader();
    Extractors extractors = new Extractors(';');
    // WHEN
    CharSeeker seeker = CharSeekers.charSeeker(dataFactory.create(TABS).stream(), TABS, false);
    Header header = headerFactory.create(seeker, TABS, IdType.ACTUAL);
    // THEN
    assertArrayEquals(array(entry("id", Type.ID, extractors.long_()), entry("name", Type.PROPERTY, extractors.string()), entry("birth_date", Type.PROPERTY, extractors.long_())), header.entries());
    seeker.close();
}
Also used : InputNode(org.neo4j.unsafe.impl.batchimport.input.InputNode) Extractors(org.neo4j.csv.reader.Extractors) DataFactories.defaultFormatNodeFileHeader(org.neo4j.unsafe.impl.batchimport.input.csv.DataFactories.defaultFormatNodeFileHeader) CharSeeker(org.neo4j.csv.reader.CharSeeker) StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

InputNode (org.neo4j.unsafe.impl.batchimport.input.InputNode)42 Test (org.junit.Test)32 Input (org.neo4j.unsafe.impl.batchimport.input.Input)21 InputRelationship (org.neo4j.unsafe.impl.batchimport.input.InputRelationship)8 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)6 Collector (org.neo4j.unsafe.impl.batchimport.input.Collector)6 Groups (org.neo4j.unsafe.impl.batchimport.input.Groups)4 File (java.io.File)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 Matchers.anyString (org.mockito.Matchers.anyString)3 StatsProvider (org.neo4j.unsafe.impl.batchimport.stats.StatsProvider)3 StringReader (java.io.StringReader)2 Writer (java.io.Writer)2 CharReadable (org.neo4j.csv.reader.CharReadable)2 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)2 Transaction (org.neo4j.graphdb.Transaction)2 NeoStores (org.neo4j.kernel.impl.store.NeoStores)2