Search in sources :

Example 11 with InputRelationship

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

the class CsvInputTest method shouldProvideRelationshipsFromCsvInput.

@Test
public void shouldProvideRelationshipsFromCsvInput() throws Exception {
    // GIVEN
    IdType idType = IdType.STRING;
    Iterable<DataFactory<InputRelationship>> data = dataIterable(data("node1,node2,KNOWS,1234567\n" + "node2,node10,HACKS,987654"));
    Input input = new CsvInput(null, null, data, header(entry("from", Type.START_ID, idType.extractor(extractors)), entry("to", Type.END_ID, idType.extractor(extractors)), entry("type", Type.TYPE, extractors.string()), entry("since", Type.PROPERTY, extractors.long_())), idType, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
    // WHEN/THEN
    try (InputIterator<InputRelationship> relationships = input.relationships().iterator()) {
        assertRelationship(relationships.next(), "node1", "node2", "KNOWS", properties("since", 1234567L));
        assertRelationship(relationships.next(), "node2", "node10", "HACKS", properties("since", 987654L));
    }
}
Also used : Input(org.neo4j.unsafe.impl.batchimport.input.Input) InputRelationship(org.neo4j.unsafe.impl.batchimport.input.InputRelationship) Test(org.junit.Test)

Example 12 with InputRelationship

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

the class CsvInputTest method shouldFailOnRelationshipWithMissingEndIdField.

@Test
public void shouldFailOnRelationshipWithMissingEndIdField() throws Exception {
    // GIVEN
    Iterable<DataFactory<InputRelationship>> data = relationshipData(CsvInputTest.<InputRelationship>data(":START_ID,:END_ID,:TYPE\n" + "1,,"));
    Input input = new CsvInput(null, null, data, defaultFormatRelationshipFileHeader(), IdType.INTEGER, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
    // WHEN
    try (InputIterator<InputRelationship> relationships = input.relationships().iterator()) {
        relationships.next();
        fail("Should have failed");
    } catch (InputException e) {
        // THEN good
        assertThat(e.getMessage(), containsString(Type.END_ID.name()));
    }
}
Also used : Input(org.neo4j.unsafe.impl.batchimport.input.Input) InputException(org.neo4j.unsafe.impl.batchimport.input.InputException) InputRelationship(org.neo4j.unsafe.impl.batchimport.input.InputRelationship) Test(org.junit.Test)

Example 13 with InputRelationship

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

the class CsvInputTest method shouldFailOnMissingRelationshipType.

@Test
public void shouldFailOnMissingRelationshipType() throws Exception {
    // GIVEN
    String type = "CUSTOM";
    DataFactory<InputRelationship> data = data(":START_ID,:END_ID,:TYPE\n" + "0,1," + type + "\n" + "1,2,");
    Iterable<DataFactory<InputRelationship>> dataIterable = dataIterable(data);
    Input input = new CsvInput(null, null, dataIterable, defaultFormatRelationshipFileHeader(), IdType.ACTUAL, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
    // WHEN/THEN
    try (ResourceIterator<InputRelationship> relationships = input.relationships().iterator()) {
        try {
            assertRelationship(relationships.next(), 0L, 1L, type, NO_PROPERTIES);
            relationships.next();
            fail("Should have failed");
        } catch (DataException e) {
            assertTrue(e.getMessage().contains(Type.TYPE.name()));
        }
    }
}
Also used : DataException(org.neo4j.unsafe.impl.batchimport.input.DataException) Input(org.neo4j.unsafe.impl.batchimport.input.Input) InputRelationship(org.neo4j.unsafe.impl.batchimport.input.InputRelationship) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 14 with InputRelationship

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

the class RelationshipTypeCheckerStepTest method batchOfRelationshipsWithRandomTypes.

private Batch<InputRelationship, RelationshipRecord> batchOfRelationshipsWithRandomTypes(int maxTypes, boolean typeIds) {
    InputRelationship[] relationships = new InputRelationship[100];
    for (int i = 0; i < relationships.length; i++) {
        int typeId = random.nextInt(maxTypes);
        relationships[i] = new InputRelationship("test", i, i, NO_PROPERTIES, null, GLOBAL, 0L, GLOBAL, 0L, typeIds ? null : "TYPE_" + String.valueOf(typeId), typeIds ? typeId : null);
    }
    return new Batch<>(relationships);
}
Also used : InputRelationship(org.neo4j.unsafe.impl.batchimport.input.InputRelationship)

Example 15 with InputRelationship

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

the class CsvInputTest method shouldProvideDefaultRelationshipType.

@Test
public void shouldProvideDefaultRelationshipType() throws Exception {
    // GIVEN
    String defaultType = "DEFAULT";
    String customType = "CUSTOM";
    DataFactory<InputRelationship> data = data(":START_ID,:END_ID,:TYPE\n" + "0,1,\n" + "1,2," + customType + "\n" + "2,1," + defaultType, defaultRelationshipType(defaultType));
    Iterable<DataFactory<InputRelationship>> dataIterable = dataIterable(data);
    Input input = new CsvInput(null, null, dataIterable, defaultFormatRelationshipFileHeader(), IdType.ACTUAL, config(COMMAS), silentBadCollector(0), getRuntime().availableProcessors());
    // WHEN/THEN
    try (ResourceIterator<InputRelationship> relationships = input.relationships().iterator()) {
        assertRelationship(relationships.next(), 0L, 1L, defaultType, NO_PROPERTIES);
        assertRelationship(relationships.next(), 1L, 2L, customType, NO_PROPERTIES);
        assertRelationship(relationships.next(), 2L, 1L, defaultType, NO_PROPERTIES);
        assertFalse(relationships.hasNext());
    }
}
Also used : Input(org.neo4j.unsafe.impl.batchimport.input.Input) InputRelationship(org.neo4j.unsafe.impl.batchimport.input.InputRelationship) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

InputRelationship (org.neo4j.unsafe.impl.batchimport.input.InputRelationship)29 Test (org.junit.Test)14 RelationshipRecord (org.neo4j.kernel.impl.store.record.RelationshipRecord)9 Input (org.neo4j.unsafe.impl.batchimport.input.Input)9 InputNode (org.neo4j.unsafe.impl.batchimport.input.InputNode)8 StageControl (org.neo4j.unsafe.impl.batchimport.staging.StageControl)4 HashMap (java.util.HashMap)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 Matchers.anyString (org.mockito.Matchers.anyString)3 RelationshipStore (org.neo4j.kernel.impl.store.RelationshipStore)3 File (java.io.File)2 IOException (java.io.IOException)2 Map (java.util.Map)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)2 Transaction (org.neo4j.graphdb.Transaction)2 NeoStores (org.neo4j.kernel.impl.store.NeoStores)2 TestGraphDatabaseFactory (org.neo4j.test.TestGraphDatabaseFactory)2 BatchImporter (org.neo4j.unsafe.impl.batchimport.BatchImporter)2 ParallelBatchImporter (org.neo4j.unsafe.impl.batchimport.ParallelBatchImporter)2