private IRecordFilter _GetFilter(string inputTypeString, Hashtable assemblyLocations) { CSharpRecordFilterBuilder builder = new CSharpRecordFilterBuilder(inputTypeString, assemblyLocations); if (_whereClause != null) { builder.WhereClause = _whereClause; } else if (_cSharpSnippetFile != null) { builder.SetCSharpSnippetFile(_cSharpSnippetFile); } else throw new Exception("must provide whereClause or snippet file"); IRecordFilter filter = builder.GetFilter(out _filterDllLocation); if (filter is ISetRecordSource) { // if this filter implements IRecordSourceAccess then // we use it to set the RecordSource so the filter // itself will have access to it. RecordSource wrapper = new RecordSource(_processor); wrapper.InternalSource = _input; ((ISetRecordSource)filter).Source = wrapper; } return filter; }
// if inner==true, does inner Join else does leftOuter Join private RecordSource _Join(RecordSource left, RecordSource right, bool inner) { bool requiresSorting = true; bool ascending = true; PairFilter filter = null; if (inner) filter = new InnerJoin(TableColumnSeparator); else filter = new LeftOuterJoin(TableColumnSeparator); // T = TypeSort asked for, either Ascending or Descending // Right // !T T // l !T sbT slT // e // f T srT X // t if (requiresSorting) { if (!left.InternalSource.Sorting.IsSorted || left.InternalSource.Sorting.IsSortedAscending != ascending) { left.SortReduce(ascending, false); } if (!right.InternalSource.Sorting.IsSorted || right.InternalSource.Sorting.IsSortedAscending != ascending) { right.SortReduce(ascending, false); } } RecordSource source2BoperatedOn = new RecordSource(this); source2BoperatedOn.InternalSource = filter; filter.AddInput(left.InternalSource); filter.AddInput(right.InternalSource); return source2BoperatedOn; }
public void Push(RecordSource source) { _stack.Add(source); }
/// <summary> /// Pass through only those records with key matching the query expression. /// The expression can be either a literal string or end with a * to denote /// prefix matching. /// </summary> /// <param name="input">The input source to be queried.</param> /// <param name="query">The query to be matched.</param> /// <returns></returns> public RecordSource QueryKey(RecordSource input, string query) { QuerySource querier = new QuerySource(query); querier.AddInput(input.InternalSource); RecordSource source2Bqueried = new RecordSource(this); source2Bqueried.InternalSource = querier; return source2Bqueried; }
/// <summary> /// Selects records from a RecordSource using a user provided whereClause. The user /// is assumed to know the record type. For example with a text file input the record /// type is the generic DataRecord so a filter might be "record.Key[0] == 'A'" to filter /// all records except those that begin with 'A'. /// </summary> /// <param name="input">The input RecordSource.</param> /// <param name="whereClause">The select clause</param> /// <returns>A RecordSource for further processing</returns> public RecordSource SelectFilter(RecordSource input, string whereClause) { whereClause = whereClause.Replace("^", "\""); DynamicRecordFilter filter = new DynamicRecordFilter(this, whereClause); filter.AddInput(input.InternalSource); RecordSource source2Bfiltered = new RecordSource(this); source2Bfiltered.InternalSource = filter; return source2Bfiltered; }
/// <summary> /// JoinInner /// </summary> /// <param name="left">One of two RecordSources</param> /// <param name="right">One of two RecordSources</param> /// <returns>A RecordSource for further processing</returns> public RecordSource LeftOuterJoin(RecordSource left, RecordSource right) { return _Join(left, right, false); }
/// <summary> /// Pair performs operations two input RecordSources, left and right. These are, for /// example, CatLeftThenRight, SortedMerge, FilterLeftByRightKey. /// </summary> /// <param name="left">One of two RecordSources</param> /// <param name="right">One of two RecordSources</param> /// <param name="pairOperation">The operation to perform on the input sources</param> /// <returns>A RecordSource for further processing</returns> public RecordSource Pair(RecordSource left, RecordSource right, PairOperation pairOperation) { PairFilter filter = null; bool requiresSorting = false; // not all pair operations require inputs sorted bool ascending = true; switch (pairOperation) { case PairOperation.FilterLeftInRight: filter = new FilterLeftByRightKey(true); requiresSorting = true; break; case PairOperation.FilterLeftNotInRight: filter = new FilterLeftByRightKey(false); requiresSorting = true; break; case PairOperation.MergeAscend: filter = new SortedMerge(true); requiresSorting = true; ascending = true; break; case PairOperation.MergeDescend: filter = new SortedMerge(false); requiresSorting = true; ascending = false; break; case PairOperation.CatLeftThenRight: filter = new CatLeftThenRight(); requiresSorting = false; break; } // T = TypeSort asked for, either Ascending or Descending // Right // !T T // l !T sbT slT // e // f T srT X // t if (requiresSorting) { if (!left.InternalSource.Sorting.IsSorted || left.InternalSource.Sorting.IsSortedAscending != ascending) { left.SortReduce(ascending, false); } if (!right.InternalSource.Sorting.IsSorted || right.InternalSource.Sorting.IsSortedAscending != ascending) { right.SortReduce(ascending, false); } } RecordSource source2BoperatedOn = new RecordSource(this); source2BoperatedOn.InternalSource = filter; filter.AddInput(left.InternalSource); filter.AddInput(right.InternalSource); return source2BoperatedOn; }
/// <summary> /// Allows user to define programmatic source using SourceDelegate. /// </summary> /// <param name="sourceDelegate">SourceDelegate returning DataRecords and null and end of source.</param> /// <returns>RecordSource</returns> public RecordSource Input(SourceDelegate sourceDelegate) { RecordSource source2Bmapped = new RecordSource(this); InternalRecordSource source = new InternalUserSource(sourceDelegate); source2Bmapped.InternalSource = _AddLogging(source); return source2Bmapped; }
/// <summary> /// Creates a record source out of 3 possible input types: /// 1) A searchable TStore /// 2) A streamable RecordsFile /// 3) A streamable FlatFile /// </summary> /// <param name="inputType">The type of input</param> /// <param name="pathInfo">The path to the input</param> /// <returns>A RecordSource for further processing</returns> public RecordSource Input(TStoreInputType inputType, string pathInfo) { InternalRecordSource source = null; switch (inputType) { case TStoreInputType.RecordFile: source = new InternalRecordFileReader(pathInfo); break; case TStoreInputType.TStore: TMSNStoreReader reader = new TMSNStoreReader(pathInfo, true); source = reader.RecordSource; break; case TStoreInputType.FlatFile: source = new FlatFileMapper(pathInfo); break; case TStoreInputType.Directory: source = new DirectoryMapper(pathInfo); break; } source.ProcessTreeComment = "[" + pathInfo + "]"; RecordSource source2Bmapped = new RecordSource(this); source2Bmapped.InternalSource = _AddLogging(source); return source2Bmapped; }
/// <summary> /// JoinInner /// </summary> /// <param name="left">One of two RecordSources</param> /// <param name="right">One of two RecordSources</param> /// <returns>A RecordSource for further processing</returns> public RecordSource InnerJoin(RecordSource left, RecordSource right) { return _Join(left, right, true); }
/// <summary> /// This operation on a record source converts it to a source containing /// DataRecords with information about the source itself. The records of /// the input source are ignored completely and information like source name, /// estimated size, sorted-ness, etc. flow from the source. /// </summary> /// <param name="input">Input record source.</param> /// <returns>Output Records source.</returns> public RecordSource GetStatistics(RecordSource input) { // this is implemented like a filter. StatisticsPseudoFilter filter = new StatisticsPseudoFilter(input.InternalSource); RecordFilterDriver filterDriver = new RecordFilterDriver(filter); filterDriver.AddInput(input.InternalSource); RecordSource source2Bfiltered = new RecordSource(this); source2Bfiltered.InternalSource = filterDriver; return source2Bfiltered; }
/// <summary> /// Filters the RecordSource by using a user proviced CSharpFilterFile. The IRecordsFilter /// within the file is compiled on the fly and inserted after the input RecordSource. If /// a non-existant file is provided the method will print template file which can be modified /// by the user. /// </summary> /// <param name="input">The input RecordSource.</param> /// <param name="cSharpFilterFile">The csharp file containing a IRecordFilter definition.</param> /// <returns>A RecordSource for further processing</returns> public RecordSource FilterByCSharpSnippet(RecordSource input, string cSharpFilterFile) { DynamicRecordFilter filter = new DynamicRecordFilter(cSharpFilterFile, this); filter.AddInput(input.InternalSource); RecordSource source2Bfiltered = new RecordSource(this); source2Bfiltered.InternalSource = filter; return source2Bfiltered; }
/// <summary> /// Filters a RecordSource using a user provided filter /// </summary> /// <param name="input">The input record source</param> /// <param name="filter">The user provided recordFilter</param> /// <returns>A RecordSource for further processing</returns> public RecordSource Filter(RecordSource input, IRecordFilter filter) { if (filter is ISetRecordSource) { // if this filter implements IRecordSourceAccess then // we use it to set the RecordSource so the filter // itself will have access to it. ((ISetRecordSource)filter).Source = input; } RecordFilterDriver filterDriver = new RecordFilterDriver(filter); filterDriver.AddInput(input.InternalSource); RecordSource source2Bfiltered = new RecordSource(this); source2Bfiltered.InternalSource = filterDriver; return source2Bfiltered; }
/// <summary> /// A RecordSource with zero records. /// </summary> /// <returns>A RecordSource for further processing</returns> public RecordSource EmptySource(bool isSorted, bool isSortedAscending) { RecordSource emptySource = new RecordSource(this); emptySource.InternalSource = new EmptyInternalSource(); emptySource.InternalSource.Sorting.IsSorted = isSorted; emptySource.InternalSource.Sorting.IsSortedAscending = isSortedAscending; return emptySource; }