Search in sources :

Example 6 with CharReadable

use of org.neo4j.csv.reader.CharReadable 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 7 with CharReadable

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

the class CsvInputTest method shouldReportDuplicateSourceFileUsedAsBothNodeAndRelationshipSourceFile.

@Test
public void shouldReportDuplicateSourceFileUsedAsBothNodeAndRelationshipSourceFile() {
    // given
    String sourceDescription = "The single data source";
    Supplier<CharReadable> nodeHeaderSource = () -> wrap(dataWithSourceDescription(":ID", "node source"), 3);
    Supplier<CharReadable> relationshipHeaderSource = () -> wrap(dataWithSourceDescription(":START_ID,:END_ID,:TYPE", "relationship source"), 10);
    Supplier<CharReadable> source = () -> wrap(dataWithSourceDescription("1,2,3", sourceDescription), 6);
    Iterable<DataFactory> nodeData = datas(config -> new Data() {

        @Override
        public RawIterator<CharReadable, IOException> stream() {
            return asRawIterator(iterator(nodeHeaderSource.get(), source.get()));
        }

        @Override
        public Decorator decorator() {
            return NO_DECORATOR;
        }
    });
    Iterable<DataFactory> relationshipData = datas(config -> new Data() {

        @Override
        public RawIterator<CharReadable, IOException> stream() {
            return asRawIterator(iterator(relationshipHeaderSource.get(), source.get()));
        }

        @Override
        public Decorator decorator() {
            return NO_DECORATOR;
        }
    });
    CsvInput.Monitor monitor = mock(CsvInput.Monitor.class);
    // when
    new CsvInput(nodeData, defaultFormatNodeFileHeader(), relationshipData, defaultFormatRelationshipFileHeader(), IdType.INTEGER, COMMAS, monitor, INSTANCE);
    // then
    verify(monitor).duplicateSourceFile(sourceDescription);
}
Also used : CharReadable(org.neo4j.csv.reader.CharReadable) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RawIterator(org.neo4j.collection.RawIterator) Iterators.asRawIterator(org.neo4j.internal.helpers.collection.Iterators.asRawIterator) Test(org.junit.Test)

Example 8 with CharReadable

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

the class CsvInputTest method shouldReportDuplicateNodeSourceFiles.

@Test
public void shouldReportDuplicateNodeSourceFiles() {
    // given
    String sourceDescription = "The single data source";
    Supplier<CharReadable> source = () -> wrap(dataWithSourceDescription(":ID", sourceDescription), 3);
    Iterable<DataFactory> data = datas(config -> new Data() {

        @Override
        public RawIterator<CharReadable, IOException> stream() {
            // Contains two of the same file
            return asRawIterator(iterator(source.get(), source.get()));
        }

        @Override
        public Decorator decorator() {
            return NO_DECORATOR;
        }
    });
    CsvInput.Monitor monitor = mock(CsvInput.Monitor.class);
    // when
    new CsvInput(data, defaultFormatNodeFileHeader(), datas(), defaultFormatRelationshipFileHeader(), IdType.INTEGER, COMMAS, monitor, INSTANCE);
    // then
    verify(monitor).duplicateSourceFile(sourceDescription);
}
Also used : CharReadable(org.neo4j.csv.reader.CharReadable) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RawIterator(org.neo4j.collection.RawIterator) Iterators.asRawIterator(org.neo4j.internal.helpers.collection.Iterators.asRawIterator) Test(org.junit.Test)

Example 9 with CharReadable

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

the class CsvInputTest method shouldReportNoNodeLabels.

@Test
public void shouldReportNoNodeLabels() {
    // given
    String sourceDescription = "source";
    Supplier<CharReadable> headerSource = () -> wrap(dataWithSourceDescription(":ID", sourceDescription), 3);
    Iterable<DataFactory> data = datas(config -> new Data() {

        @Override
        public RawIterator<CharReadable, IOException> stream() {
            return asRawIterator(iterator(headerSource.get()));
        }

        @Override
        public Decorator decorator() {
            return NO_DECORATOR;
        }
    });
    CsvInput.Monitor monitor = mock(CsvInput.Monitor.class);
    // when
    new CsvInput(data, defaultFormatNodeFileHeader(), datas(), defaultFormatRelationshipFileHeader(), IdType.INTEGER, COMMAS, monitor, INSTANCE);
    // then
    verify(monitor).noNodeLabelsSpecified(sourceDescription);
}
Also used : CharReadable(org.neo4j.csv.reader.CharReadable) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RawIterator(org.neo4j.collection.RawIterator) Iterators.asRawIterator(org.neo4j.internal.helpers.collection.Iterators.asRawIterator) Test(org.junit.Test)

Example 10 with CharReadable

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

the class CsvInputTest method shouldReportDuplicateRelationshipSourceFiles.

@Test
public void shouldReportDuplicateRelationshipSourceFiles() {
    // given
    String sourceDescription = "The single data source";
    Supplier<CharReadable> source = () -> wrap(dataWithSourceDescription(":START_ID,:END_ID,:TYPE", sourceDescription), 3);
    Iterable<DataFactory> data = datas(config -> new Data() {

        @Override
        public RawIterator<CharReadable, IOException> stream() {
            // Contains two of the same file
            return asRawIterator(iterator(source.get(), source.get()));
        }

        @Override
        public Decorator decorator() {
            return NO_DECORATOR;
        }
    });
    CsvInput.Monitor monitor = mock(CsvInput.Monitor.class);
    // when
    new CsvInput(datas(), defaultFormatNodeFileHeader(), data, defaultFormatRelationshipFileHeader(), IdType.INTEGER, COMMAS, monitor, INSTANCE);
    // then
    verify(monitor).duplicateSourceFile(sourceDescription);
}
Also used : CharReadable(org.neo4j.csv.reader.CharReadable) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RawIterator(org.neo4j.collection.RawIterator) Iterators.asRawIterator(org.neo4j.internal.helpers.collection.Iterators.asRawIterator) Test(org.junit.Test)

Aggregations

CharReadable (org.neo4j.csv.reader.CharReadable)10 Test (org.junit.Test)8 Matchers.containsString (org.hamcrest.Matchers.containsString)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 RawIterator (org.neo4j.collection.RawIterator)7 Iterators.asRawIterator (org.neo4j.internal.helpers.collection.Iterators.asRawIterator)7 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 Test (org.junit.jupiter.api.Test)1 CharSeeker (org.neo4j.csv.reader.CharSeeker)1 Extractors (org.neo4j.csv.reader.Extractors)1 MultiReadable (org.neo4j.csv.reader.MultiReadable)1 InputEntity (org.neo4j.internal.batchimport.input.InputEntity)1 CsvInputIterator.extractHeader (org.neo4j.internal.batchimport.input.csv.CsvInputIterator.extractHeader)1 DataFactories.defaultFormatNodeFileHeader (org.neo4j.internal.batchimport.input.csv.DataFactories.defaultFormatNodeFileHeader)1 DataFactories.defaultFormatRelationshipFileHeader (org.neo4j.internal.batchimport.input.csv.DataFactories.defaultFormatRelationshipFileHeader)1 Input (org.neo4j.unsafe.impl.batchimport.input.Input)1 InputNode (org.neo4j.unsafe.impl.batchimport.input.InputNode)1 InputRelationship (org.neo4j.unsafe.impl.batchimport.input.InputRelationship)1