public void OneStreamWithErrorOnCrossApplyTest() { var task = StreamProcessRunner.CreateAndExecuteAsync(0, configStream => { configStream .CrossApplyEnumerable("lst1", config => new[] { 1 }) .Select("with error", i => { // throw new Exception(); return(i); }) .ThroughAction("res1", Console.WriteLine); configStream .CrossApplyEnumerable("lst2", config => new[] { 1 }) .Select("with no error", i => { throw new Exception(); return(i); }) .ThroughAction("res2", Console.WriteLine); }, traceStream => traceStream.ThroughAction("trace", i => System.Diagnostics.Debug.WriteLine(i))); try { System.Diagnostics.Debug.WriteLine("before"); task.Wait(2000); System.Diagnostics.Debug.WriteLine("after"); } catch (Exception ex) { var jex = ex.InnerException as Paillave.Etl.Core.JobExecutionException; var te = jex.TraceEvent; } }
public void OneStreamWithErrorTest() { var task = StreamProcessRunner.CreateAndExecuteAsync(0, configStream => { configStream .Select("with error", i => { throw new Exception(); return(i); }) .ThroughAction("res1", Console.WriteLine); configStream .Select("with no error", i => { // throw new Exception(); return(i); }) .ThroughAction("res2", Console.WriteLine); }); try { task.Wait(5000); } catch (Exception ex) { var jex = ex.InnerException as Paillave.Etl.Core.JobExecutionException; var te = jex.TraceEvent; } }
public void SimplePivot() { var inputList = Enumerable.Range(0, 10).Select(i => new { Key = i / 5, Value = i }).OrderBy(i => i.Key).ToList(); var outputList = new List <string>(); #region simple pivot StreamProcessRunner.CreateAndExecuteAsync(inputList, rootStream => { rootStream .CrossApplyEnumerable("list elements", config => config) .EnsureSorted("ensure sorted", i => i.Key) .Pivot("simple count", i => new { Id = i.Key, Count = AggregationOperators.Count() }) .Select("transform into string", SimpleSerializeToString) .ThroughAction("collect values", outputList.Add); }).Wait(); var expectedList = new[] { "FirstValue:{ Key = 0, Value = 0 },Key:0,Aggregation:{ Id = 0, Count = 5 }", "FirstValue:{ Key = 1, Value = 5 },Key:1,Aggregation:{ Id = 0, Count = 5 }" }.ToList(); CollectionAssert.AreEquivalent(expectedList, outputList); #endregion }
public void MultiComputationsPivot() { #region multicomputations pivot var inputList = Enumerable.Range(0, 10).Select(i => new { Key = i / 5, Value = i }).ToList(); var outputList = new List <string>(); StreamProcessRunner.CreateAndExecuteAsync(inputList, rootStream => { rootStream .CrossApplyEnumerable("list elements", config => config) .Pivot("simple count", i => i.Key, i => new { Id = i.Key, Count = AggregationOperators.Count(), Sum = AggregationOperators.Sum(i.Value), First = AggregationOperators.First(i.Value), Last = AggregationOperators.Last(i.Value), Max = AggregationOperators.Max(i.Value), Min = AggregationOperators.Min(i.Value), Avg = AggregationOperators.Avg(i.Value), }) .Select("transform into string", SimpleSerializeToString) .ThroughAction("collect values", outputList.Add); }).Wait(); var expectedList = new[] { "FirstValue:{ Key = 0, Value = 0 },Key:0,Aggregation:{ Id = 0, Count = 5, Sum = 10, First = 0, Last = 4, Max = 4, Min = 0, Avg = 2 }", "FirstValue:{ Key = 1, Value = 5 },Key:1,Aggregation:{ Id = 0, Count = 5, Sum = 35, First = 5, Last = 9, Max = 9, Min = 5, Avg = 7 }" }.ToList(); CollectionAssert.AreEquivalent(expectedList, outputList); #endregion }
public void MultiColumnsPivot() { #region multicolumns pivot var inputList = Enumerable.Range(0, 10).Select(i => new { Key = i / 5, Value = i, Col = i % 2 }).ToList(); var outputList = new List <string>(); StreamProcessRunner.CreateAndExecuteAsync(inputList, rootStream => { rootStream .CrossApplyEnumerable("list elements", config => config) .Pivot("simple count", i => i.Key, i => new { Id = i.Key, EvensCount = AggregationOperators.Count().For(i.Col == 0), OddsCount = AggregationOperators.Count().For(i.Col == 1), }) .Select("transform into string", SimpleSerializeToString) .ThroughAction("collect values", outputList.Add); }).Wait(); var expectedList = new[] { "FirstValue:{ Key = 0, Value = 0, Col = 0 },Key:0,Aggregation:{ Id = 0, EvensCount = 3, OddsCount = 2 }", "FirstValue:{ Key = 1, Value = 5, Col = 1 },Key:1,Aggregation:{ Id = 0, EvensCount = 2, OddsCount = 3 }" }.ToList(); CollectionAssert.AreEquivalent(expectedList, outputList); #endregion }
public void LeftJoinWithNoMatch() { #region left join with no matches var inputLeftList = Enumerable.Range(0, 100).Select(i => new { Id = i, ForeignId = i / 10 }).ToList(); var inputRightList = Enumerable.Range(1000, 10).Select(i => new { Id = i, Label = $"Label{i}" }).ToList(); var outputList = new List <string>(); StreamProcessRunner.CreateAndExecuteAsync(new { InputLeftList = inputLeftList, InputRightList = inputRightList }, rootStream => { var leftStream = rootStream .CrossApplyEnumerable("input left elements", config => config.InputLeftList) .EnsureSorted("ensure left is sorted", i => i.ForeignId); var rightStream = rootStream .CrossApplyEnumerable("input right elements", config => config.InputRightList) .EnsureKeyed("ensure right is keyed", i => i.Id); leftStream .LeftJoin("join left and right", rightStream, (left, right) => $"{left.Id}-{right?.Label}") .ThroughAction("collect values", outputList.Add); }).Wait(); var expected = Enumerable.Range(0, 100).Select(i => $"{i}-").ToList(); CollectionAssert.AreEquivalent(expected, outputList); #endregion }
public void LookupWithSomeMatches() { #region lookup with couple of no match var inputLeftList = Enumerable.Range(0, 100).Select(i => new { Id = i, ForeignId = i / 10 }).ToList(); var inputRightList = new[] { 2, 5 }.Select(i => new { Id = i, Label = $"Label{i}" }).ToList(); var outputList = new List <string>(); //TODO: Ensure there is an actual failure if the result expression fails StreamProcessRunner.CreateAndExecuteAsync(new { InputLeftList = inputLeftList, InputRightList = inputRightList }, rootStream => { var leftStream = rootStream.CrossApplyEnumerable("input left elements", config => config.InputLeftList); var rightStream = rootStream.CrossApplyEnumerable("input right elements", config => config.InputRightList); leftStream .Lookup("join left and right", rightStream, i => i.ForeignId, i => i.Id, (left, right) => $"{left.Id}-{right?.Label}") .ThroughAction("collect values", outputList.Add); }).Wait(); var expected = Enumerable.Range(0, 100).Select(i => { if (new[] { 2, 5 }.Contains(i / 10)) { return($"{i}-Label{i / 10}"); } else { return($"{i}-"); } }).ToList(); CollectionAssert.AreEquivalent(expected, outputList); #endregion }
public void InlineMethodWay() { var config = new SimpleConfigStreamType { Divider = 10 }; var task = StreamProcessRunner.CreateAndExecuteAsync(config, SimpleJob.Job1); task.Wait(); CollectionAssert.AreEquivalent(new[] { $"{100 / 10} times hello world!" }, config.Messages.ToArray()); }
static void Main(string[] args) { StreamProcessRunner.CreateAndExecuteAsync( new { InputFilePath = Path.Combine(args[0], "simpleinputfile.csv"), OutputFilePath = Path.Combine(args[0], "simpleoutputfile.csv") }, rootStream => { var outputFileS = rootStream.Select("open output file", i => (Stream)File.OpenWrite(i.OutputFilePath)); rootStream .CrossApplyTextFile("read input file", FlatFileDefinition.Create(i => new { Id = i.ToColumn <int>("#"), Name = i.ToColumn <string>("Label"), ValueType = i.ToColumn <string>("Value"), CategoryCode = i.ToColumn <string>("Category") }).IsColumnSeparated('\t'), i => i.InputFilePath) .ThroughAction("Write input file to console", i => Console.WriteLine($"{i.Id}->{i.Name}->{i.CategoryCode}->{i.ValueType}")) .Pivot("group and count", i => i.CategoryCode, i => new { Count = AggregationOperators.Count(), CountA = AggregationOperators.Count().For(i.ValueType == "a"), CountB = AggregationOperators.Count().For(i.ValueType == "b"), }) .Select("create output row", i => new { CategoryCode = i.Key, i.Aggregation.Count, i.Aggregation.CountA, i.Aggregation.CountB }) .Sort("sort output values", i => new { i.CategoryCode }) .ThroughTextFile("write to text file", outputFileS, FlatFileDefinition.Create(i => new { CategoryCode = i.ToColumn <string>("MyCategoryCode"), Count = i.ToColumn <int>("Count"), CountA = i.ToColumn <int>("CountA"), CountB = i.ToColumn <int>("CountB") })); }).Wait(); Console.WriteLine("Press a key..."); Console.ReadKey(); }
public void FailEnsureSingleNotSorted() { #region ensure single not sorted var inputList = new[] { 1, 2 }.ToList(); var outputList = new List <int>(); StreamProcessRunner.CreateAndExecuteAsync(inputList, rootStream => { rootStream .CrossApplyEnumerable("list elements", config => config) .EnsureSingle("ensure single") .ThroughAction("collect values", outputList.Add); }).Wait(); #endregion }
public void ProduceList() { #region produce list var inputList = Enumerable.Range(0, 100).ToList(); var outputList = new List <int>(); StreamProcessRunner.CreateAndExecuteAsync(inputList, rootStream => { rootStream .CrossApplyEnumerable("list elements", config => config) .ThroughAction("collect values", outputList.Add); }).Wait(); CollectionAssert.AreEquivalent(inputList, outputList); #endregion }
public void FailEnsureKeyedWithDuplicate() { #region ensure keyed with duplicate var inputList = new[] { 1, 2, 2, 3, 4, 5 }.ToList(); var outputList = new List <int>(); var task = StreamProcessRunner.CreateAndExecuteAsync(inputList, rootStream => { rootStream .CrossApplyEnumerable("list elements", config => config) .EnsureKeyed("ensure keyed", i => i) .ThroughAction("collect values", outputList.Add); }); task.Wait(); #endregion }
public void SimpleSelectWithIndex() { #region simple select var inputList = Enumerable.Range(0, 10); var outputList = new List <string>(); StreamProcessRunner.CreateAndExecuteAsync(inputList, rootStream => { rootStream .CrossApplyEnumerable("list elements", config => config) .Select("issue new value", (i, idx) => $"{i}-{idx}") .ThroughAction("collect values", outputList.Add); }).Wait(); var expectedList = inputList.Select((i, idx) => $"{i}-{idx}").ToList(); CollectionAssert.AreEquivalent(expectedList, outputList); #endregion }
public void SuccessfulEnsureKeyed() { #region ensure keyed without pb var inputList = new[] { 1, 2, 3, 4, 5 }.ToList(); var outputList = new List <int>(); StreamProcessRunner.CreateAndExecuteAsync(inputList, rootStream => { rootStream .CrossApplyEnumerable("list elements", config => config) .EnsureKeyed("ensure keyed", i => i) .ThroughAction("collect values", outputList.Add); }).Wait(); CollectionAssert.AreEquivalent(inputList, outputList); #endregion }
public void GetFilesFromFolderRecursive() { var tmpPath = Path.GetTempPath(); var testPath = Path.Combine(tmpPath, TestFolder); var outputList = new List <LocalFilesValue>(); StreamProcessRunner.CreateAndExecuteAsync(testPath, rootStream => { rootStream .CrossApplyFolderFiles("get all files", "*", true) .ThroughAction("collect values", outputList.Add); }).Wait(); var expected = Enumerable.Range(0, 2).Select(i => Path.Combine(testPath, $"file{i}")).Union(Enumerable.Range(0, 2).SelectMany(i => Enumerable.Range(0, 4).Select(j => Path.Combine(testPath, $"{i}", $"{i}-{j}")))).ToList(); var actual = outputList.Select(i => i.Name).ToList(); CollectionAssert.AreEquivalent(expected, actual); }
public void SimpleDistinct() { #region simple distinct var inputList = Enumerable.Range(0, 100).Select(i => i).ToList(); var outputList = new List <int>(); StreamProcessRunner.CreateAndExecuteAsync(inputList, rootStream => { rootStream .CrossApplyEnumerable("list elements", config => config) .Distinct("distinct", i => i % 10) .ThroughAction("collect values", outputList.Add); }).Wait(); var expected = Enumerable.Range(0, 10).Select(i => i).ToList(); CollectionAssert.AreEquivalent(expected, outputList); #endregion }
public void ProduceSubValues() { #region produce sub values without pre/post process var inputList = Enumerable.Range(10, 10).Select(i => $"{i}").ToList(); var outputList = new List <string>(); StreamProcessRunner.CreateAndExecuteAsync(inputList, rootStream => { rootStream .CrossApplyEnumerable("list elements", i => i, true) .CrossApply <string, string>("produce sub values", (input, pushValue) => input.Select(i => $"{i}").ToList().ForEach(pushValue)) .ThroughAction("collect values", outputList.Add); }).Wait(); var expected = inputList.SelectMany(i => i.Select(j => $"{j}")).ToList(); var actual = outputList; CollectionAssert.AreEquivalent(expected, actual); #endregion }
public void ProduceSubValuesParallelized() { #region parallel produce sub values without pre/post process var inputList = Enumerable.Range(10, 10).Select(i => Enumerable.Range(i, 4).Select(j => $"{j}").ToList()).ToList(); var outputList = new List <string>(); StreamProcessRunner.CreateAndExecuteAsync(inputList, rootStream => { rootStream .CrossApplyEnumerable <List <List <string> >, List <string> >("list elements", config => config) .CrossApply <List <string>, string>("produce sub values", (input, pushValue) => input.ForEach(pushValue)) .ThroughAction("collect values", outputList.Add); }).Wait(); var expected = inputList.SelectMany(i => i).OrderBy(i => i).ToList(); var actual = outputList.OrderBy(i => i).ToList(); CollectionAssert.AreEquivalent(expected, actual); #endregion }
static void Main(string[] args) { var task = StreamProcessRunner.CreateAndExecuteAsync( // new ImportFilesConfig { InputFilesRootFolderPath = @"C:\Users\sroyer\Downloads\RBC" }, new ImportFilesConfig { InputFilesRootFolderPath = @"C:\Users\paill\Documents\GitHub\Etl.Net\src\Samples\TestFiles\RBC" } , ImportFiles.DefineProcess , traceStream => traceStream.ThroughAction("trace", i => System.Diagnostics.Debug.WriteLine(i)) ); try { task.Wait(); } catch (Exception ex) { var jex = ex.InnerException as Paillave.Etl.Core.JobExecutionException; var te = jex.TraceEvent; } }
public void MultiColumnsMultiComputationsPivot() { var inputList = Enumerable.Range(0, 10).Select(i => new { Key = i / 5, Value = i, Col = i % 2 }).OrderBy(i => i.Key).ToList(); var outputList = new List <string>(); #region multicolumns multicomputations pivot StreamProcessRunner.CreateAndExecuteAsync(inputList, rootStream => { rootStream .CrossApplyEnumerable("list elements", config => config) .EnsureSorted("ensure sorted", i => i.Key) .Pivot("simple count", i => new { Id = i.Key, EvensCount = AggregationOperators.Count().For(i.Col == 0), EvensSum = AggregationOperators.Sum(i.Value).For(i.Col == 0), EvensFirst = AggregationOperators.First(i.Value).For(i.Col == 0), EvensLast = AggregationOperators.Last(i.Value).For(i.Col == 0), EvensMax = AggregationOperators.Max(i.Value).For(i.Col == 0), EvensMin = AggregationOperators.Min(i.Value).For(i.Col == 0), EvensAvg = AggregationOperators.Avg(i.Value).For(i.Col == 0), OddsCount = AggregationOperators.Count().For(i.Col == 1), OddsSum = AggregationOperators.Sum(i.Value).For(i.Col == 1), OddsFirst = AggregationOperators.First(i.Value).For(i.Col == 1), OddsLast = AggregationOperators.Last(i.Value).For(i.Col == 1), OddsMax = AggregationOperators.Max(i.Value).For(i.Col == 1), OddsMin = AggregationOperators.Min(i.Value).For(i.Col == 1), OddsAvg = AggregationOperators.Avg(i.Value).For(i.Col == 1), }) .Select("transform into string", SimpleSerializeToString) .ThroughAction("collect values", outputList.Add); }).Wait(); var expectedList = new[] { "FirstValue:{ Key = 0, Value = 0, Col = 0 },Key:0,Aggregation:{ Id = 0, EvensCount = 3, EvensSum = 6, EvensFirst = 0, EvensLast = 4, EvensMax = 4, EvensMin = 0, EvensAvg = 2, OddsCount = 2, OddsSum = 4, OddsFirst = 1, OddsLast = 3, OddsMax = 3, OddsMin = 1, OddsAvg = 2 }", "FirstValue:{ Key = 1, Value = 5, Col = 1 },Key:1,Aggregation:{ Id = 0, EvensCount = 2, EvensSum = 14, EvensFirst = 6, EvensLast = 8, EvensMax = 8, EvensMin = 6, EvensAvg = 7, OddsCount = 3, OddsSum = 21, OddsFirst = 5, OddsLast = 9, OddsMax = 9, OddsMin = 5, OddsAvg = 7 }" }.ToList(); CollectionAssert.AreEquivalent(expectedList, outputList); #endregion }
public void ComputeAverage() { #region compute average var inputList = Enumerable.Range(0, 10).ToList(); var outputList = new List <string>(); StreamProcessRunner.CreateAndExecuteAsync(inputList, rootStream => { rootStream .CrossApplyEnumerable("list elements", config => config) .Select("produce business object", i => new { Value = i, Category = $"CAT{i % 2}" }) .Aggregate("compute sum per category", i => new { Nb = 0, Sum = 0 }, i => i.Category, (agg, elt) => new { Nb = agg.Nb + 1, Sum = agg.Sum + elt.Value }) .Select("format and compute result", i => $"{i.Key}:{i.Aggregation.Sum / i.Aggregation.Nb}") .ThroughAction("collect values", outputList.Add); }).Wait(); CollectionAssert.AreEquivalent(new[] { "CAT0:4", "CAT1:5" }.ToList(), outputList); #endregion }
public void ProduceListWithOneItem() { #region produce list with one "resource" item var inputList = Enumerable.Range(0, 100).ToList(); var inputResource = 1; var outputList = new List <int>(); StreamProcessRunner.CreateAndExecuteAsync(new { InputResource = inputResource, InputList = inputList }, rootStream => { var resourceStream = rootStream.Select("get another resource", config => config.InputResource); rootStream .CrossApplyEnumerable("list elements", resourceStream, (config, res) => config.InputList.Select(i => i + res).ToList()) .ThroughAction("collect values", outputList.Add); }).Wait(); CollectionAssert.AreEquivalent(inputList.Select(i => i + inputResource).ToList(), outputList); #endregion }
public void GroupElements() { #region group elements var inputList = Enumerable.Range(0, 10).ToList(); var outputList = new List <string>(); StreamProcessRunner.CreateAndExecuteAsync(inputList, rootStream => { rootStream .CrossApplyEnumerable("list elements", config => config) .Select("produce business object", i => new { Value = i, Category = $"CAT{i % 2}" }) .Aggregate("compute sum per category", i => "", i => i.Category, (agg, elt) => $"{agg}{elt.Value}") .Select("format result", i => $"{i.Key}:{i.Aggregation}") .ThroughAction("collect values", outputList.Add); }).Wait(); CollectionAssert.AreEquivalent(new[] { "CAT0:02468", "CAT1:13579" }.ToList(), outputList); #endregion }
public void EmptyPivot() { #region simple pivot var inputList = new int[] { }.Select(i => new { Key = i / 5, Value = i }).ToList(); var outputList = new List <string>(); StreamProcessRunner.CreateAndExecuteAsync(inputList, rootStream => { rootStream .CrossApplyEnumerable("list elements", config => config) .Pivot("simple count", i => i.Key, i => new { Id = i.Key, Count = AggregationOperators.Count() }) .Select("transform into string", SimpleSerializeToString) .ThroughAction("collect values", outputList.Add); }).Wait(); var expectedList = new string[] { }.ToList(); CollectionAssert.AreEquivalent(expectedList, outputList); #endregion }
public void InlineMethodWay() { var config = new SimpleConfigStreamType { Divider = 0 }; var task = StreamProcessRunner.CreateAndExecuteAsync(config, SimpleJob.Job1); try { task.Wait(); Assert.Fail("the execution should not be successfull"); } catch (AggregateException ex) { JobExecutionException jobExecutionException = ex.InnerException as JobExecutionException; if (jobExecutionException == null) { throw; } Assert.IsInstanceOfType(jobExecutionException.InnerException, typeof(DivideByZeroException)); Assert.IsInstanceOfType((jobExecutionException.TraceEvent?.Content as UnhandledExceptionStreamTraceContent)?.Exception, typeof(DivideByZeroException)); } }
public void ProduceSubValuesWithToApplyParallelized() { #region produce sub values without pre/post process with to apply parallelized var inputList = Enumerable.Range(10, 100).Select(i => $"{i}").ToList(); var outputList = new List <string>(); StreamProcessRunner.CreateAndExecuteAsync(new { InputList = inputList, Multiplier = 2 }, rootStream => { var toApplyStream = rootStream.Select("get multiplier", config => config.Multiplier); rootStream .CrossApplyEnumerable("list elements", config => config.InputList) .CrossApply <string, int, string>("produce sub values", toApplyStream, (input, toApply, pushValue) => input.Select(i => $"{i}*{toApply}").ToList().ForEach(pushValue)) .ThroughAction("collect values", outputList.Add); }).Wait(); var expected = inputList.SelectMany(i => i.Select(j => $"{j}*2")).OrderBy(i => i).ToList(); var actual = outputList.OrderBy(i => i).ToList(); CollectionAssert.AreEquivalent(expected, actual); #endregion }
public void SimpleLookup() { #region simple lookup var inputLeftList = Enumerable.Range(0, 100).Select(i => new { Id = i, ForeignId = i / 10 }).ToList(); var inputRightList = Enumerable.Range(0, 10).Select(i => new { Id = i, Label = $"Label{i}" }).ToList(); var outputList = new List <string>(); StreamProcessRunner.CreateAndExecuteAsync(new { InputLeftList = inputLeftList, InputRightList = inputRightList }, rootStream => { var leftStream = rootStream.CrossApplyEnumerable("input left elements", config => config.InputLeftList); var rightStream = rootStream.CrossApplyEnumerable("input right elements", config => config.InputRightList); leftStream .Lookup("join left and right", rightStream, i => i.ForeignId, i => i.Id, (left, right) => $"{left.Id}-{right.Label}") .ThroughAction("collect values", outputList.Add); }).Wait(); var expected = Enumerable.Range(0, 100).Select(i => $"{i}-Label{i / 10}").ToList(); CollectionAssert.AreEquivalent(expected, outputList); #endregion }
public void ProduceSubValuesWithToApplyPrePost() { #region produce sub values without pre/post process with to apply PrePost var inputList = Enumerable.Range(10, 100).Select(i => $"{i}").ToList(); var outputList = new List <string>(); StreamProcessRunner.CreateAndExecuteAsync(new { InputList = inputList, Multiplier = 2 }, rootStream => { var toApplyStream = rootStream.Select("get multiplier", config => config.Multiplier); rootStream .CrossApplyEnumerable("list elements", config => config.InputList, true) .CrossApply <string, int, int, int, string>("produce sub values", toApplyStream, (input, toApply, pushValue) => input.ToString().Select(i => int.Parse(i.ToString()) * toApply).ToList().ForEach(pushValue), (i, j) => int.Parse(i) + 2, (val, initVal, toApply) => $"{val / toApply}-{initVal}") .ThroughAction("collect values", outputList.Add); }).Wait(); var expected = inputList.SelectMany(i => (int.Parse(i) + 2).ToString().Select(j => int.Parse(j.ToString()) * 2).Select(j => $"{j / 2}-{i}").ToList()).ToList(); var actual = outputList; CollectionAssert.AreEquivalent(expected, actual); #endregion }
static async Task Main3(string[] args) { var anyArrayOfByte = new byte[] { }; var res = await StreamProcessRunner.CreateAndExecuteAsync <Stream>(new MemoryStream(anyArrayOfByte), DefineProcess20); }