Using the LineRecord Class to Query a Text-Based File Set
To read any input that is formatted as text, use the FromDsc method and the LineRecord as the type parameter. This query produces a collection of LineRecord instances where each member of the collection represents an individual line of the file. You can use the ToString method to retrieve the line of text. The LineRecord type gets special support from the L2H compiler such that FromDsc<LineRecord> will parse text files whereas FromDsc<string> will parse binary-encoded strings. LineRecord is the only record type that gets the special treatment.
Here is a LINQ to HPC query that computes the total number of characters in a DSC file set.
var config = new HpcLinqConfiguration("MyHpcClusterHeadNode");
var context = new HpcLinqContext(config);
string textData = ...
var characterCount = context.FromDsc<LineRecord>(textData)
.Select(r => r.Line.Length)
.Sum();
Console.WriteLine("The number of characters is {0}", characterCount);
Note |
|---|
| The Sum method causes the query to execute. You can use the SumAsQuery method to delay the query's execution. |
Show:
Note