Search in sources :

Example 1 with DataFactories.defaultFormatNodeFileHeader

use of org.neo4j.unsafe.impl.batchimport.input.csv.DataFactories.defaultFormatNodeFileHeader in project neo4j by neo4j.

the class DataFactoriesTest method shouldParseDefaultNodeFileHeaderCorrectly.

@Test
public void shouldParseDefaultNodeFileHeaderCorrectly() throws Exception {
    // GIVEN
    CharSeeker seeker = seeker("ID:ID,label-one:label,also-labels:LABEL,name,age:long");
    IdType idType = IdType.STRING;
    Extractors extractors = new Extractors(',');
    // WHEN
    Header header = DataFactories.defaultFormatNodeFileHeader().create(seeker, COMMAS, idType);
    // THEN
    assertArrayEquals(array(entry("ID", Type.ID, idType.extractor(extractors)), entry("label-one", Type.LABEL, extractors.stringArray()), entry("also-labels", Type.LABEL, extractors.stringArray()), entry("name", Type.PROPERTY, extractors.string()), entry("age", Type.PROPERTY, extractors.long_())), header.entries());
    seeker.close();
}
Also used : Extractors(org.neo4j.csv.reader.Extractors) CharSeeker(org.neo4j.csv.reader.CharSeeker) DataFactories.defaultFormatNodeFileHeader(org.neo4j.unsafe.impl.batchimport.input.csv.DataFactories.defaultFormatNodeFileHeader) Test(org.junit.Test)

Example 2 with DataFactories.defaultFormatNodeFileHeader

use of org.neo4j.unsafe.impl.batchimport.input.csv.DataFactories.defaultFormatNodeFileHeader in project neo4j by neo4j.

the class DataFactoriesTest method shouldAllowMissingIdHeaderEntry.

@Test
public void shouldAllowMissingIdHeaderEntry() throws Exception {
    // GIVEN
    CharSeeker seeker = seeker("one\ttwo");
    Extractors extractors = new Extractors(';');
    // WHEN
    Header header = DataFactories.defaultFormatNodeFileHeader().create(seeker, TABS, IdType.ACTUAL);
    // THEN
    assertArrayEquals(array(entry("one", Type.PROPERTY, extractors.string()), entry("two", Type.PROPERTY, extractors.string())), header.entries());
    seeker.close();
}
Also used : Extractors(org.neo4j.csv.reader.Extractors) CharSeeker(org.neo4j.csv.reader.CharSeeker) DataFactories.defaultFormatNodeFileHeader(org.neo4j.unsafe.impl.batchimport.input.csv.DataFactories.defaultFormatNodeFileHeader) Test(org.junit.Test)

Example 3 with DataFactories.defaultFormatNodeFileHeader

use of org.neo4j.unsafe.impl.batchimport.input.csv.DataFactories.defaultFormatNodeFileHeader in project neo4j by neo4j.

the class DataFactoriesTest method shouldHaveEmptyHeadersBeInterpretedAsIgnored.

@Test
public void shouldHaveEmptyHeadersBeInterpretedAsIgnored() throws Exception {
    // GIVEN
    CharSeeker seeker = seeker("one:id\ttwo\t\tdate:long");
    IdType idType = IdType.ACTUAL;
    Extractors extractors = new Extractors('\t');
    // WHEN
    Header header = DataFactories.defaultFormatNodeFileHeader().create(seeker, TABS, idType);
    // THEN
    assertArrayEquals(array(entry("one", Type.ID, extractors.long_()), entry("two", Type.PROPERTY, extractors.string()), entry(null, Type.IGNORE, null), entry("date", Type.PROPERTY, extractors.long_())), header.entries());
    seeker.close();
}
Also used : Extractors(org.neo4j.csv.reader.Extractors) CharSeeker(org.neo4j.csv.reader.CharSeeker) DataFactories.defaultFormatNodeFileHeader(org.neo4j.unsafe.impl.batchimport.input.csv.DataFactories.defaultFormatNodeFileHeader) Test(org.junit.Test)

Example 4 with DataFactories.defaultFormatNodeFileHeader

use of org.neo4j.unsafe.impl.batchimport.input.csv.DataFactories.defaultFormatNodeFileHeader in project neo4j by neo4j.

the class DataFactoriesTest method shouldFailOnUnexpectedNodeHeaderType.

@Test
public void shouldFailOnUnexpectedNodeHeaderType() throws Exception {
    // GIVEN
    CharSeeker seeker = seeker(":ID,:START_ID");
    IdType idType = IdType.ACTUAL;
    // WHEN
    try {
        Header header = DataFactories.defaultFormatNodeFileHeader().create(seeker, COMMAS, idType);
        fail("Should have failed");
    } catch (InputException e) {
        // THEN
        assertThat(e.getMessage(), containsString("START_ID"));
    }
}
Also used : CharSeeker(org.neo4j.csv.reader.CharSeeker) DataFactories.defaultFormatNodeFileHeader(org.neo4j.unsafe.impl.batchimport.input.csv.DataFactories.defaultFormatNodeFileHeader) InputException(org.neo4j.unsafe.impl.batchimport.input.InputException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 CharSeeker (org.neo4j.csv.reader.CharSeeker)4 DataFactories.defaultFormatNodeFileHeader (org.neo4j.unsafe.impl.batchimport.input.csv.DataFactories.defaultFormatNodeFileHeader)4 Extractors (org.neo4j.csv.reader.Extractors)3 InputException (org.neo4j.unsafe.impl.batchimport.input.InputException)1