示例#1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldHaveEmptyHeadersBeInterpretedAsIgnored() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldHaveEmptyHeadersBeInterpretedAsIgnored()
        {
            // 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, _groups);

            // 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.Dispose();
        }
示例#2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldParseDefaultNodeFileHeaderCorrectly() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldParseDefaultNodeFileHeaderCorrectly()
        {
            // 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, _groups);

            // 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.Dispose();
        }
示例#3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldParseDefaultRelationshipFileHeaderCorrectly() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldParseDefaultRelationshipFileHeaderCorrectly()
        {
            // 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, _groups);

            // THEN
            assertArrayEquals(array(Entry(null, Type.StartId, idType.extractor(extractors)), Entry(null, Type.EndId, idType.extractor(extractors)), Entry("type", Type.Type, extractors.String()), Entry("date", Type.Property, extractors.Long_()), Entry("more", Type.Property, extractors.LongArray())), header.Entries());
            seeker.Dispose();
        }
示例#4
0
        internal CsvInput(IEnumerable <DataFactory> nodeDataFactory, Header.Factory nodeHeaderFactory, IEnumerable <DataFactory> relationshipDataFactory, Header.Factory relationshipHeaderFactory, IdType idType, Configuration config, Collector badCollector, Monitor monitor, Groups groups)
        {
            AssertSaneConfiguration(config);

            this._nodeDataFactory           = nodeDataFactory;
            this._nodeHeaderFactory         = nodeHeaderFactory;
            this._relationshipDataFactory   = relationshipDataFactory;
            this._relationshipHeaderFactory = relationshipHeaderFactory;
            this._idType       = idType;
            this._config       = config;
            this._badCollector = badCollector;
            this._monitor      = monitor;
            this._groups       = groups;

            VerifyHeaders();
            WarnAboutDuplicateSourceFiles();
        }
示例#5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFailOnUnexpectedRelationshipHeaderType()
        public virtual void ShouldFailOnUnexpectedRelationshipHeaderType()
        {
            // GIVEN
            CharSeeker seeker = seeker(":LABEL,:START_ID,:END_ID,:TYPE");
            IdType     idType = IdType.Actual;

            // WHEN
            try
            {
                Header header = DataFactories.DefaultFormatRelationshipFileHeader().create(seeker, _commas, idType, _groups);
                fail("Should have failed");
            }
            catch (InputException e)
            {
                // THEN
                assertThat(e.Message, containsString("LABEL"));
            }
        }
示例#6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFailForDuplicateIdHeaderEntries() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldFailForDuplicateIdHeaderEntries()
        {
            // 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, _groups);
                fail("Should fail");
            }
            catch (DuplicateHeaderException e)
            {
                assertEquals(Entry("one", Type.Id, extractors.Long_()), e.First);
                assertEquals(Entry("two", Type.Id, extractors.Long_()), e.Other);
            }
            seeker.Dispose();
        }
示例#7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: static Header extractHeader(org.neo4j.csv.reader.CharReadable stream, Header.Factory headerFactory, IdType idType, Configuration config, org.neo4j.unsafe.impl.batchimport.input.Groups groups) throws java.io.IOException
        internal static Header ExtractHeader(CharReadable stream, Header.Factory headerFactory, IdType idType, Configuration config, Groups groups)
        {
            if (!headerFactory.Defined)
            {
                char[] firstLineBuffer = Readables.extractFirstLineFrom(stream);
                // make the chunk slightly bigger than the header to not have the seeker think that it's reading
                // a value bigger than its max buffer size
                ChunkImpl firstChunk = new ChunkImpl(copyOf(firstLineBuffer, firstLineBuffer.Length + 1));
                firstChunk.Initialize(firstLineBuffer.Length, stream.SourceDescription());
                CharSeeker firstSeeker = Seeker(firstChunk, config);
                return(headerFactory.Create(firstSeeker, config, idType, groups));
            }

            return(headerFactory.Create(null, null, null, null));
        }
示例#8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: CsvInputIterator(org.neo4j.csv.reader.CharReadable stream, Decorator decorator, Header.Factory headerFactory, IdType idType, Configuration config, org.neo4j.unsafe.impl.batchimport.input.Groups groups, org.neo4j.unsafe.impl.batchimport.input.Collector badCollector, org.neo4j.csv.reader.Extractors extractors, int groupId) throws java.io.IOException
        internal CsvInputIterator(CharReadable stream, Decorator decorator, Header.Factory headerFactory, IdType idType, Configuration config, Groups groups, Collector badCollector, Extractors extractors, int groupId) : this(stream, decorator, ExtractHeader(stream, headerFactory, idType, config, groups), config, idType, badCollector, extractors, groupId)
        {
        }
示例#9
0
        internal CsvInputIterator(CharReadable stream, Decorator decorator, Header header, Configuration config, IdType idType, Collector badCollector, Extractors extractors, int groupId)
        {
            this._stream    = stream;
            this._decorator = decorator;
            this._groupId   = groupId;
            if (config.multilineFields())
            {
                // If we're expecting multi-line fields then there's no way to arbitrarily chunk the underlying data source
                // and find record delimiters with certainty. This is why we opt for a chunker that does parsing inside
                // the call that normally just hands out an arbitrary amount of characters to parse outside and in parallel.
                // This chunker is single-threaded, as it was previously too and keeps the functionality of multi-line fields.
                this._chunker = new EagerParserChunker(stream, idType, header, badCollector, extractors, 1_000, config, decorator);
//JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter:
                this._realInputChunkSupplier = EagerCsvInputChunk::new;
            }
            else
            {
                this._chunker = new ClosestNewLineChunker(stream, config.bufferSize());
                this._realInputChunkSupplier = () => new LazyCsvInputChunk(idType, config.delimiter(), badCollector, extractors(config), _chunker.newChunk(), config, decorator, header);
            }
        }
示例#10
0
 /// <param name="nodeDataFactory"> multiple <seealso cref="DataFactory"/> instances providing data, each <seealso cref="DataFactory"/>
 /// specifies an input group with its own header, extracted by the {@code nodeHeaderFactory}. From the outside
 /// it looks like one stream of nodes. </param>
 /// <param name="nodeHeaderFactory"> factory for reading node headers. </param>
 /// <param name="relationshipDataFactory"> multiple <seealso cref="DataFactory"/> instances providing data, each <seealso cref="DataFactory"/>
 /// specifies an input group with its own header, extracted by the {@code relationshipHeaderFactory}.
 /// From the outside it looks like one stream of relationships. </param>
 /// <param name="relationshipHeaderFactory"> factory for reading relationship headers. </param>
 /// <param name="idType"> <seealso cref="IdType"/> to expect in id fields of node and relationship input. </param>
 /// <param name="config"> CSV configuration. </param>
 /// <param name="badCollector"> Collector getting calls about bad input data. </param>
 /// <param name="monitor"> <seealso cref="Monitor"/> for internal events. </param>
 public CsvInput(IEnumerable <DataFactory> nodeDataFactory, Header.Factory nodeHeaderFactory, IEnumerable <DataFactory> relationshipDataFactory, Header.Factory relationshipHeaderFactory, IdType idType, Configuration config, Collector badCollector, Monitor monitor) : this(nodeDataFactory, nodeHeaderFactory, relationshipDataFactory, relationshipHeaderFactory, idType, config, badCollector, monitor, new Groups())
 {
 }
示例#11
0
 public static Input Csv(File nodes, File relationships, IdType idType, [email protected] configuration, Collector badCollector)
 {
     return(new CsvInput(datas(data(NO_DECORATOR, defaultCharset(), nodes)), defaultFormatNodeFileHeader(_testDefaultTimeZone), datas(data(NO_DECORATOR, defaultCharset(), relationships)), defaultFormatRelationshipFileHeader(_testDefaultTimeZone), idType, configuration, badCollector, CsvInput.NoMonitor));
 }
示例#12
0
 public CsvGroupInputIterator(IEnumerator <DataFactory> source, Header.Factory headerFactory, IdType idType, Configuration config, Collector badCollector, Groups groups)
 {
     this._source        = source;
     this._headerFactory = headerFactory;
     this._idType        = idType;
     this._config        = config;
     this._badCollector  = badCollector;
     this._groups        = groups;
 }
示例#13
0
            public override Header Create(CharSeeker dataSeeker, Configuration config, IdType idType, Groups groups)
            {
                try
                {
                    Mark       mark       = new Mark();
                    Extractors extractors = new Extractors(config.arrayDelimiter(), config.emptyQuotedStringsAsNull(), config.trimStrings(), DefaultTimeZone);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.csv.reader.Extractor<?> idExtractor = idType.extractor(extractors);
                    Extractor <object> idExtractor = idType.extractor(extractors);
                    int delimiter = config.delimiter();
                    IList <Header.Entry> columns = new List <Header.Entry>();
                    for (int i = 0; !mark.EndOfLine && dataSeeker.Seek(mark, delimiter); i++)
                    {
                        string          entryString = dataSeeker.TryExtract(mark, extractors.String()) ? extractors.String().value() : null;
                        HeaderEntrySpec spec        = new HeaderEntrySpec(entryString);

                        if ((string.ReferenceEquals(spec.Name, null) && string.ReferenceEquals(spec.Type, null)) || (!string.ReferenceEquals(spec.Type, null) && spec.Type.Equals(Type.Ignore.name())))
                        {
                            columns.Add(new Header.Entry(null, Type.Ignore, [email protected]_Fields.Global, null, null));
                        }
                        else
                        {
                            Group group = CreateGroups ? groups.GetOrCreate(spec.GroupName) : groups.Get(spec.GroupName);
                            columns.Add(Entry(i, spec.Name, spec.Type, group, extractors, idExtractor));
                        }
                    }
                    Entry[] entries = columns.ToArray();
                    ValidateHeader(entries);
                    return(new Header(entries));
                }
                catch (IOException e)
                {
                    throw new Exception(e);
                }
            }