Search in sources :

Example 21 with CharSeeker

use of org.neo4j.csv.reader.CharSeeker in project neo4j by neo4j.

the class DataFactoriesTest method shouldFailOnUnexpectedRelationshipHeaderType.

@Test
public void shouldFailOnUnexpectedRelationshipHeaderType() {
    // GIVEN
    CharSeeker seeker = seeker(":LABEL,:START_ID,:END_ID,:TYPE");
    IdType idType = IdType.ACTUAL;
    // WHEN
    var e = assertThrows(InputException.class, () -> defaultFormatRelationshipFileHeader().create(seeker, COMMAS, idType, groups));
    assertThat(e.getMessage()).contains("LABEL");
}
Also used : CharSeeker(org.neo4j.csv.reader.CharSeeker) IdType(org.neo4j.internal.batchimport.input.IdType) Test(org.junit.jupiter.api.Test)

Example 22 with CharSeeker

use of org.neo4j.csv.reader.CharSeeker 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 = defaultFormatNodeFileHeader().create(seeker, TABS, IdType.ACTUAL, groups);
    // 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.internal.batchimport.input.csv.DataFactories.defaultFormatNodeFileHeader) DataFactories.defaultFormatRelationshipFileHeader(org.neo4j.internal.batchimport.input.csv.DataFactories.defaultFormatRelationshipFileHeader) Test(org.junit.jupiter.api.Test)

Example 23 with CharSeeker

use of org.neo4j.csv.reader.CharSeeker in project neo4j by neo4j.

the class DataFactoriesTest method shouldParseHeaderFromFirstLineOfFirstInputFile.

@Test
public void shouldParseHeaderFromFirstLineOfFirstInputFile() throws Exception {
    // GIVEN
    final CharReadable firstSource = wrap("id:ID\tname:String\tbirth_date:long");
    final CharReadable secondSource = wrap("0\tThe node\t123456789");
    DataFactory dataFactory = DataFactories.data(value -> value, () -> new MultiReadable(Readables.iterator(IOFunctions.identity(), firstSource, secondSource)));
    Header.Factory headerFactory = defaultFormatNodeFileHeader();
    Extractors extractors = new Extractors(';');
    // WHEN
    CharSeeker seeker = CharSeekers.charSeeker(new MultiReadable(dataFactory.create(TABS).stream()), TABS, false);
    Header header = headerFactory.create(seeker, TABS, IdType.ACTUAL, groups);
    // 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 : MultiReadable(org.neo4j.csv.reader.MultiReadable) Extractors(org.neo4j.csv.reader.Extractors) DataFactories.defaultFormatNodeFileHeader(org.neo4j.internal.batchimport.input.csv.DataFactories.defaultFormatNodeFileHeader) DataFactories.defaultFormatRelationshipFileHeader(org.neo4j.internal.batchimport.input.csv.DataFactories.defaultFormatRelationshipFileHeader) CharSeeker(org.neo4j.csv.reader.CharSeeker) CharReadable(org.neo4j.csv.reader.CharReadable) Test(org.junit.jupiter.api.Test)

Example 24 with CharSeeker

use of org.neo4j.csv.reader.CharSeeker in project neo4j by neo4j.

the class DataFactoriesTest method shouldFailForDuplicatePropertyHeaderEntries.

@Test
public void shouldFailForDuplicatePropertyHeaderEntries() throws Exception {
    // GIVEN
    CharSeeker seeker = seeker("one:id\tname\tname:long");
    IdType idType = IdType.ACTUAL;
    Extractors extractors = new Extractors('\t');
    var e = assertThrows(DuplicateHeaderException.class, () -> defaultFormatNodeFileHeader().create(seeker, TABS, idType, groups));
    assertEquals(entry("name", Type.PROPERTY, extractors.string()), e.getFirst());
    assertEquals(entry("name", Type.PROPERTY, extractors.long_()), e.getOther());
    seeker.close();
}
Also used : Extractors(org.neo4j.csv.reader.Extractors) CharSeeker(org.neo4j.csv.reader.CharSeeker) IdType(org.neo4j.internal.batchimport.input.IdType) Test(org.junit.jupiter.api.Test)

Aggregations

CharSeeker (org.neo4j.csv.reader.CharSeeker)24 Extractors (org.neo4j.csv.reader.Extractors)18 Test (org.junit.jupiter.api.Test)12 Test (org.junit.Test)10 IdType (org.neo4j.internal.batchimport.input.IdType)10 DataFactories.defaultFormatNodeFileHeader (org.neo4j.internal.batchimport.input.csv.DataFactories.defaultFormatNodeFileHeader)8 DataFactories.defaultFormatRelationshipFileHeader (org.neo4j.internal.batchimport.input.csv.DataFactories.defaultFormatRelationshipFileHeader)8 DataFactories.defaultFormatNodeFileHeader (org.neo4j.unsafe.impl.batchimport.input.csv.DataFactories.defaultFormatNodeFileHeader)8 DuplicateHeaderException (org.neo4j.unsafe.impl.batchimport.input.DuplicateHeaderException)2 InputException (org.neo4j.unsafe.impl.batchimport.input.InputException)2 IOException (java.io.IOException)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 BufferedCharSeeker (org.neo4j.csv.reader.BufferedCharSeeker)1 CharReadable (org.neo4j.csv.reader.CharReadable)1 ChunkImpl (org.neo4j.csv.reader.CharReadableChunker.ChunkImpl)1 MultiReadable (org.neo4j.csv.reader.MultiReadable)1 InputNode (org.neo4j.unsafe.impl.batchimport.input.InputNode)1