Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor/renames-get-records #75

Merged
merged 1 commit into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions RecordParser.Benchmark/FixedLengthReaderBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void Read_FixedLength_RecordParser_Parallel(bool parallel)
Parser = parser.Parse,
};

var items = streamReader.GetRecords(readOptions);
var items = streamReader.ReadRecords(readOptions);

var i = 0;
foreach (var person in items)
Expand Down Expand Up @@ -127,7 +127,7 @@ public void Read_FixedLength_RecordParser_GetLines()
using var fileStream = File.OpenRead(PathSampleDataTXT);
using var streamReader = new StreamReader(fileStream, Encoding.UTF8, true, BufferSize);

var lines = streamReader.GetRecords();
var lines = streamReader.ReadRecords();

var i = 0;
foreach (var line in lines)
Expand Down
6 changes: 3 additions & 3 deletions RecordParser.Benchmark/VariableLengthReaderBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void Read_VariableLength_FullQuoted_RecordParser_Parallel(bool parallel,
ContainsQuotedFields = quoted,
};

var items = streamReader.GetRecords(parser, readOptions);
var items = streamReader.ReadRecords(parser, readOptions);

var i = 0;
foreach (var person in items)
Expand Down Expand Up @@ -151,7 +151,7 @@ public void Read_VariableLength_RecordParser_Parallel(bool parallel, bool quoted
ContainsQuotedFields = quoted,
};

var items = streamReader.GetRecords(parser, readOptions);
var items = streamReader.ReadRecords(parser, readOptions);

var i = 0;
foreach (var person in items)
Expand Down Expand Up @@ -184,7 +184,7 @@ public void Read_VariableLength_RecordParser_Raw(bool parallel, bool quoted)
StringPoolFactory = () => new InternPool().Intern
};

var items = streamReader.GetRecordsRaw(readOptions, PersonFactory);
var items = streamReader.ReadRecordsRaw(readOptions, PersonFactory);

var i = 0;
foreach (var person in items)
Expand Down
10 changes: 5 additions & 5 deletions RecordParser.Test/FileReaderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void Read_csv_file_all_fields_quoted(string fileContent, bool hasHeader,

// Act

var items = streamReader.GetRecords(parser, readOptions);
var items = streamReader.ReadRecords(parser, readOptions);

// Assert

Expand Down Expand Up @@ -157,7 +157,7 @@ public void Read_quoted_csv_file(string fileContent, bool hasHeader, bool parall

// Act

var items = streamReader.GetRecords(parser, readOptions);
var items = streamReader.ReadRecords(parser, readOptions);

// Assert

Expand Down Expand Up @@ -247,7 +247,7 @@ public void Read_not_quoted_csv_file(string fileContent, bool hasHeader, bool pa

// Act

var items = streamReader.GetRecords(parser, readOptions);
var items = streamReader.ReadRecords(parser, readOptions);

// Assert

Expand Down Expand Up @@ -354,7 +354,7 @@ public void Read_fixed_length_file(string fileContent, bool parallelProcessing,

// Act

var records = streamReader.GetRecords(readOptions);
var records = streamReader.ReadRecords(readOptions);

var linesByType = records.ToLookup(x => x.GetType());
var result = linesByType[typeof(HeaderFixedLength)].Cast<HeaderFixedLength>().Single();
Expand Down Expand Up @@ -410,7 +410,7 @@ public void Read_plain_text_of_fixed_length_file(string fileContent, bool parall

var result = new List<string>();

foreach (var item in streamReader.GetRecords())
foreach (var item in streamReader.ReadRecords())
{
result.Add(item.Span.ToString());
}
Expand Down
4 changes: 2 additions & 2 deletions RecordParser.Test/FileWriterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void Write_csv_file(int repeat, bool parallel, bool ordered)
ParallelismOptions = new() { Enabled = parallel }
};

var reads = textReader.GetRecords(reader, readOptions);
var reads = textReader.ReadRecords(reader, readOptions);

reads.Should().BeEquivalentTo(expectedItems);
}
Expand Down Expand Up @@ -140,7 +140,7 @@ public void Write_fixed_length_file(int repeat, bool parallel, bool ordered)
ParallelismOptions = new() { Enabled = parallel }
};

var reads = textReader.GetRecords(readOptions);
var reads = textReader.ReadRecords(readOptions);

reads.Should().BeEquivalentTo(expectedItems);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ public static class FixedLengthReaderExtensions
/// <returns>
/// Sequence of records.
/// </returns>
public static IEnumerable<T> GetRecords<T>(this TextReader reader, FixedLengthReaderOptions<T> options)
public static IEnumerable<T> ReadRecords<T>(this TextReader reader, FixedLengthReaderOptions<T> options)
{
var func = () => new RowByLine(reader, Length);
var parser = (ReadOnlyMemory<char> memory, int i) => options.Parser(memory.Span);
var parallelOptions = options.ParallelismOptions ?? new();

return
parallelOptions.Enabled
? GetRecordsParallel(parser, func, HasHeader, parallelOptions)
: GetRecordsSequential(parser, func, HasHeader);
? ReadRecordsParallel(parser, func, HasHeader, parallelOptions)
: ReadRecordsSequential(parser, func, HasHeader);
}

/// <summary>
Expand All @@ -57,9 +57,9 @@ public static IEnumerable<T> GetRecords<T>(this TextReader reader, FixedLengthRe
/// Store ReadOnlyMemory values will not hold record's values since the content of the buffer changes
/// as it goes forward through the file.
/// </remarks>
public static IEnumerable<ReadOnlyMemory<char>> GetRecords(this TextReader reader)
public static IEnumerable<ReadOnlyMemory<char>> ReadRecords(this TextReader reader)
{
return GetRecordsSequential((memory, i) => memory, () => new RowByLine(reader, Length), HasHeader);
return ReadRecordsSequential((memory, i) => memory, () => new RowByLine(reader, Length), HasHeader);
}
}
}
4 changes: 2 additions & 2 deletions RecordParser/Extensions/FileReader/ReaderCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static ParallelQuery<T> AsParallel<T>(this IEnumerable<T> source, Paralle
return query;
}

public static IEnumerable<T> GetRecordsParallel<T>(
public static IEnumerable<T> ReadRecordsParallel<T>(
Func<ReadOnlyMemory<char>, int, T> reader,
Func<IFL> getItems,
bool hasHeader,
Expand All @@ -87,7 +87,7 @@ public static IEnumerable<T> GetRecordsParallel<T>(
}
}

public static IEnumerable<T> GetRecordsSequential<T>(Func<ReadOnlyMemory<char>, int, T> reader, Func<IFL> getItems, bool hasHeader)
public static IEnumerable<T> ReadRecordsSequential<T>(Func<ReadOnlyMemory<char>, int, T> reader, Func<IFL> getItems, bool hasHeader)
{
using var items = getItems();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static class VariableLengthReaderExtensions
/// <returns>
/// Sequence of records.
/// </returns>
public static IEnumerable<T> GetRecords<T>(this TextReader reader, IVariableLengthReader<T> parser, VariableLengthReaderOptions options)
public static IEnumerable<T> ReadRecords<T>(this TextReader reader, IVariableLengthReader<T> parser, VariableLengthReaderOptions options)
{
Func<IFL> func = options.ContainsQuotedFields
? () => new RowByQuote(reader, Length, parser.Separator)
Expand All @@ -50,8 +50,8 @@ public static IEnumerable<T> GetRecords<T>(this TextReader reader, IVariableLeng
var parallelOptions = options.ParallelismOptions ?? new();

return parallelOptions.Enabled
? GetRecordsParallel(selector, func, options.HasHeader, parallelOptions)
: GetRecordsSequential(selector, func, options.HasHeader);
? ReadRecordsParallel(selector, func, options.HasHeader, parallelOptions)
: ReadRecordsSequential(selector, func, options.HasHeader);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private static Get BuildRaw(int collumnCount, bool hasTransform, bool trim)
/// <returns>
/// Sequence of records.
/// </returns>
public static IEnumerable<T> GetRecordsRaw<T>(this TextReader reader, VariableLengthReaderRawOptions options, Func<Func<int, string>, T> parser)
public static IEnumerable<T> ReadRecordsRaw<T>(this TextReader reader, VariableLengthReaderRawOptions options, Func<Func<int, string>, T> parser)
{
var get = BuildRaw(options.ColumnCount, options.StringPoolFactory != null, options.Trim);
var sep = options.Separator.ToString();
Expand All @@ -124,7 +124,7 @@ IEnumerable<T> GetSequential()
var stringCache = options.StringPoolFactory?.Invoke();
var getField = (int i) => buffer[i];

return GetRecordsSequential(Parser, func, options.HasHeader);
return ReadRecordsSequential(Parser, func, options.HasHeader);

T Parser(ReadOnlyMemory<char> memory, int i)
{
Expand Down Expand Up @@ -163,7 +163,7 @@ IEnumerable<T> GetParallel()
})
.ToArray();

return GetRecordsParallel(Parser, func, options.HasHeader, parallelOptions);
return ReadRecordsParallel(Parser, func, options.HasHeader, parallelOptions);

T Parser(ReadOnlyMemory<char> memory, int i)
{
Expand Down