Search in sources :

Example 16 with CharSeeker

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

the class DataFactoriesTest method shouldFailForDuplicateIdHeaderEntries.

@Test
public void shouldFailForDuplicateIdHeaderEntries() throws Exception {
    // GIVEN
    CharSeeker seeker = seeker("one:id\ttwo:id");
    IdType idType = IdType.ACTUAL;
    Extractors extractors = new Extractors('\t');
    // WHEN
    try {
        DataFactories.defaultFormatNodeFileHeader().create(seeker, TABS, idType);
        fail("Should fail");
    } catch (DuplicateHeaderException e) {
        assertEquals(entry("one", Type.ID, extractors.long_()), e.getFirst());
        assertEquals(entry("two", Type.ID, extractors.long_()), e.getOther());
    }
    seeker.close();
}
Also used : Extractors(org.neo4j.csv.reader.Extractors) CharSeeker(org.neo4j.csv.reader.CharSeeker) DuplicateHeaderException(org.neo4j.unsafe.impl.batchimport.input.DuplicateHeaderException) Test(org.junit.Test)

Example 17 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 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)

Example 18 with CharSeeker

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

the class DataFactoriesTest method shouldParseDefaultRelationshipFileHeaderCorrectly.

@Test
public void shouldParseDefaultRelationshipFileHeaderCorrectly() throws Exception {
    // GIVEN
    CharSeeker seeker = seeker(":START_ID\t:END_ID\ttype:TYPE\tdate:long\tmore:long[]");
    IdType idType = IdType.ACTUAL;
    Extractors extractors = new Extractors('\t');
    // WHEN
    Header header = DataFactories.defaultFormatRelationshipFileHeader().create(seeker, TABS, idType);
    // THEN
    assertArrayEquals(array(entry(null, Type.START_ID, idType.extractor(extractors)), entry(null, Type.END_ID, idType.extractor(extractors)), entry("type", Type.TYPE, extractors.string()), entry("date", Type.PROPERTY, extractors.long_()), entry("more", Type.PROPERTY, extractors.longArray())), 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 19 with CharSeeker

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

the class DataFactoriesTest method shouldFailForDuplicateIdHeaderEntries.

@Test
public void shouldFailForDuplicateIdHeaderEntries() throws Exception {
    // GIVEN
    CharSeeker seeker = seeker("one:id\ttwo:id");
    IdType idType = IdType.ACTUAL;
    Extractors extractors = new Extractors('\t');
    var e = assertThrows(DuplicateHeaderException.class, () -> defaultFormatNodeFileHeader().create(seeker, TABS, idType, groups));
    assertEquals(entry("one", Type.ID, extractors.long_()), e.getFirst());
    assertEquals(entry("two", Type.ID, extractors.long_()), e.getOther());
}
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)

Example 20 with CharSeeker

use of org.neo4j.csv.reader.CharSeeker 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,location:Point{crs:WGS-84}");
    IdType idType = IdType.STRING;
    Extractors extractors = new Extractors(',');
    // WHEN
    Header header = defaultFormatNodeFileHeader().create(seeker, COMMAS, idType, groups);
    // THEN
    assertArrayEquals(array(entry("ID", Type.ID, CsvInput.idExtractor(idType, 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_()), entry("location", Type.PROPERTY, extractors.point(), PointValue.parseHeaderInformation("{crs:WGS-84}"))), 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) 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