Best NBi code snippet using NBi.Core.ResultSet.Alteration.Reshaping.UnstackEngine.Execute
UnstackEngineTest.cs
Source:UnstackEngineTest.cs
...15{16 public class UnstackEngineTest17 {18 [Test]19 public void Execute_SingleKeySingleValue_ExpectedResultSet()20 {21 var resolver = new ObjectsResultSetResolver(22 new ObjectsResultSetResolverArgs(23 new[] {24 new object[] { "alpha", "A", 1 },25 new object[] { "alpha", "B", 2 },26 new object[] { "beta", "A", 3 },27 new object[] { "beta", "B", 4 }28 }29 ));30 var rs = resolver.Execute();31 rs.Columns[0].ColumnName = "keyColumn";32 rs.Columns[1].ColumnName = "headerColumn";33 rs.Columns[2].ColumnName = "valueColumn";34 var args = new UnstackArgs(35 new ColumnNameIdentifier("headerColumn"),36 new List<IColumnDefinitionLight>()37 { Mock.Of<IColumnDefinitionLight>(x => x.Identifier == new ColumnNameIdentifier("keyColumn") && x.Type == ColumnType.Text) }38 );39 var unstack = new UnstackEngine(args);40 var result = unstack.Execute(rs);41 Assert.That(result, Is.Not.Null);42 Assert.That(result.Columns.Count, Is.EqualTo(3));43 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "keyColumn"));44 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "A"));45 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "B"));46 Assert.That(result.Rows.Count, Is.EqualTo(2));47 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "alpha")["A"]) == 1);48 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "alpha")["B"]) == 2);49 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "beta")["A"]) == 3);50 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "beta")["B"]) == 4);51 }52 [Test]53 public void Execute_SingleKeyMultipleValue_ExpectedResultSet()54 {55 var resolver = new ObjectsResultSetResolver(56 new ObjectsResultSetResolverArgs(57 new[] {58 new object[] { "alpha", "A", 1, -1 },59 new object[] { "alpha", "B", 2, -2 },60 new object[] { "beta", "A", 3, -3 },61 new object[] { "beta", "B", 4, -4 }62 }63 ));64 var rs = resolver.Execute();65 rs.Columns[0].ColumnName = "keyColumn";66 rs.Columns[1].ColumnName = "headerColumn";67 rs.Columns[2].ColumnName = "value1Column";68 rs.Columns[3].ColumnName = "value2Column";69 var args = new UnstackArgs(70 new ColumnNameIdentifier("headerColumn"),71 new List<IColumnDefinitionLight>()72 { Mock.Of<IColumnDefinitionLight>(x => x.Identifier == new ColumnNameIdentifier("keyColumn") && x.Type == ColumnType.Text) }73 );74 var unstack = new UnstackEngine(args);75 var result = unstack.Execute(rs);76 Assert.That(result, Is.Not.Null);77 Assert.That(result.Columns.Count, Is.EqualTo(5));78 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "keyColumn"));79 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "A_value1Column"));80 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "B_value1Column"));81 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "A_value2Column"));82 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "B_value2Column"));83 Assert.That(result.Rows.Count, Is.EqualTo(2));84 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "alpha")["A_value1Column"]) == 1);85 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "alpha")["B_value1Column"]) == 2);86 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "beta")["A_value1Column"]) == 3);87 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "beta")["B_value1Column"]) == 4);88 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "alpha")["A_value2Column"]) == -1);89 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "alpha")["B_value2Column"]) == -2);90 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "beta")["A_value2Column"]) == -3);91 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "beta")["B_value2Column"]) == -4);92 }93 [Test]94 public void Execute_MultipleKeysSingleValue_ExpectedResultSet()95 {96 var resolver = new ObjectsResultSetResolver(97 new ObjectsResultSetResolverArgs(98 new[] {99 new object[] { "alpha", "one", "A", 1 },100 new object[] { "alpha", "one", "B", 2 },101 new object[] { "beta", "one", "A", 3 },102 new object[] { "beta", "one", "B", 4 },103 new object[] { "beta", "two", "B", -4 }104 }105 ));106 var rs = resolver.Execute();107 rs.Columns[0].ColumnName = "key1Column";108 rs.Columns[1].ColumnName = "key2Column";109 rs.Columns[2].ColumnName = "headerColumn";110 rs.Columns[3].ColumnName = "valueColumn";111 var args = new UnstackArgs(112 new ColumnNameIdentifier("headerColumn"),113 new List<IColumnDefinitionLight>()114 {115 Mock.Of<IColumnDefinitionLight>(x => x.Identifier == new ColumnNameIdentifier("key1Column") && x.Type == ColumnType.Text),116 Mock.Of<IColumnDefinitionLight>(x => x.Identifier == new ColumnNameIdentifier("key2Column") && x.Type == ColumnType.Text),117 }118 );119 var unstack = new UnstackEngine(args);120 var result = unstack.Execute(rs);121 Assert.That(result, Is.Not.Null);122 Assert.That(result.Columns.Count, Is.EqualTo(4));123 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "key1Column"));124 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "key2Column"));125 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "A"));126 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "B"));127 Assert.That(result.Rows.Count, Is.EqualTo(3));128 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["key1Column"] as string == "alpha" && x["key2Column"] as string == "one")["A"]) == 1);129 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["key1Column"] as string == "alpha" && x["key2Column"] as string == "one")["B"]) == 2);130 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["key1Column"] as string == "beta" && x["key2Column"] as string == "one")["A"]) == 3);131 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["key1Column"] as string == "beta" && x["key2Column"] as string == "one")["B"]) == 4);132 Assert.That(Convert.ToInt32(result.Rows.Cast<DataRow>().Single(x => x["key1Column"] as string == "beta" && x["key2Column"] as string == "two")["B"]) == -4);133 Assert.That(result.Rows.Cast<DataRow>().Single(x => x["key1Column"] as string == "beta" && x["key2Column"] as string == "two")["A"] == DBNull.Value);134 }135 [Test]136 public void Execute_EnforcedColumnsThatWasNotExpected_ExpectedResultSet()137 {138 var resolver = new ObjectsResultSetResolver(139 new ObjectsResultSetResolverArgs(140 new[] {141 new object[] { "alpha", "A", 1 },142 new object[] { "alpha", "B", 2 },143 new object[] { "beta", "A", 3 },144 new object[] { "beta", "B", 4 }145 }146 ));147 var rs = resolver.Execute();148 rs.Columns[0].ColumnName = "keyColumn";149 rs.Columns[1].ColumnName = "headerColumn";150 rs.Columns[2].ColumnName = "valueColumn";151 var args = new UnstackArgs(152 new ColumnNameIdentifier("headerColumn"),153 new List<IColumnDefinitionLight>()154 { Mock.Of<IColumnDefinitionLight>(x => x.Identifier == new ColumnNameIdentifier("keyColumn") && x.Type == ColumnType.Text) },155 new List<ColumnNameIdentifier>() { new ColumnNameIdentifier("C") }156 );157 var unstack = new UnstackEngine(args);158 var result = unstack.Execute(rs);159 Assert.That(result, Is.Not.Null);160 Assert.That(result.Columns.Count, Is.EqualTo(4));161 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "keyColumn"));162 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "A"));163 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "B"));164 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "C"));165 Assert.That(result.Rows.Count, Is.EqualTo(2));166 Assert.That(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "alpha")["C"] == DBNull.Value);167 Assert.That(result.Rows.Cast<DataRow>().Single(x => x["keyColumn"] as string == "alpha")["C"] == DBNull.Value);168 }169 [Test]170 public void Execute_EnforcedColumnsThatWasAlreadyExpected_ExpectedResultSet()171 {172 var resolver = new ObjectsResultSetResolver(173 new ObjectsResultSetResolverArgs(174 new[] {175 new object[] { "alpha", "A", 1 },176 new object[] { "alpha", "B", 2 },177 new object[] { "beta", "A", 3 },178 new object[] { "beta", "B", 4 }179 }180 ));181 var rs = resolver.Execute();182 rs.Columns[0].ColumnName = "keyColumn";183 rs.Columns[1].ColumnName = "headerColumn";184 rs.Columns[2].ColumnName = "valueColumn";185 var args = new UnstackArgs(186 new ColumnNameIdentifier("headerColumn"),187 new List<IColumnDefinitionLight>()188 { Mock.Of<IColumnDefinitionLight>(x => x.Identifier == new ColumnNameIdentifier("keyColumn") && x.Type == ColumnType.Text) },189 new List<ColumnNameIdentifier>() { new ColumnNameIdentifier("A"), new ColumnNameIdentifier("B") }190 );191 var unstack = new UnstackEngine(args);192 var result = unstack.Execute(rs);193 Assert.That(result, Is.Not.Null);194 Assert.That(result.Columns.Count, Is.EqualTo(3));195 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "keyColumn"));196 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "A"));197 Assert.That(result.Columns.Cast<DataColumn>().Any(x => x.ColumnName == "B"));198 Assert.That(result.Columns.Cast<DataColumn>().Count(x => x.ColumnName == "A") == 1);199 Assert.That(result.Columns.Cast<DataColumn>().Count(x => x.ColumnName == "B") == 1);200 }201 [Test]202 [TestCase(100)]203 [TestCase(1000)]204 [TestCase(10000)]205 [TestCase(40000)]206 [Retry(3)]207 [Parallelizable(ParallelScope.Self)]208 public void Execute_LargeResultSet_ExpectedPerformance(int count)209 {210 var values = new List<object>();211 for (int i = 0; i < count; i++)212 values.Add(new object[] { i % 2 == 0 ? "alpha" : "beta", (i/2) % (count/2), 1 });213 var resolver = new ObjectsResultSetResolver(new ObjectsResultSetResolverArgs(values));214 var rs = resolver.Execute();215 rs.Columns[0].ColumnName = "keyColumn";216 rs.Columns[1].ColumnName = "headerColumn";217 rs.Columns[2].ColumnName = "valueColumn";218 var args = new UnstackArgs(219 new ColumnNameIdentifier("headerColumn"),220 new List<IColumnDefinitionLight>()221 { Mock.Of<IColumnDefinitionLight>(x => x.Identifier == new ColumnNameIdentifier("keyColumn") && x.Type == ColumnType.Text) }222 );223 var unstack = new UnstackEngine(args);224 var stopWatch = new Stopwatch();225 stopWatch.Start();226 var result = unstack.Execute(rs);227 stopWatch.Stop();228 Assert.That(stopWatch.Elapsed.TotalSeconds, Is.LessThan(15));229 }230 }231}...
UnstackEngine.cs
Source:UnstackEngine.cs
...14 {15 private UnstackArgs Args { get; }16 public UnstackEngine(UnstackArgs args)17 => Args = args;18 public IResultSet Execute(IResultSet rs)19 {20 //Build structre of the resulting table21 var valueColumns = rs.Columns.Cast<DataColumn>().Where(22 x => x != Args.Header.GetColumn(rs.Table)23 && !Args.GroupBys.Select(y => y.Identifier.GetColumn(rs.Table)).Contains(x)24 );25 26 var headerValues = Args.EnforcedColumns.Select(x => x.Name).ToList();27 rs.Rows.Cast<DataRow>().ToList().ForEach(x => headerValues.Add(Args.Header.GetValue(x).ToString()));28 headerValues = headerValues.Distinct().ToList();29 using (var dataTable = new DataTable())30 {31 foreach (var groupBy in Args.GroupBys)32 {33 var column = groupBy.Identifier.GetColumn(rs.Table);34 dataTable.Columns.Add(new DataColumn(column.ColumnName, column.DataType));35 }36 var namingStrategy = (valueColumns.Count() == 1)37 ? new UniqueValueNamingStrategy() as INamingStrategy38 : new MultipleValuesNamingStrategy();39 foreach (var valueColumn in valueColumns)40 foreach (var headerValue in headerValues)41 dataTable.Columns.Add(new DataColumn(namingStrategy.Execute(headerValue, valueColumn.ColumnName), typeof(object)));42 var groupbyFactory = new GroupByFactory();43 var groupbyEngine = groupbyFactory.Instantiate(new ColumnGroupByArgs(Args.GroupBys, Context.None));44 var groups = groupbyEngine.Execute(rs);45 foreach (var group in groups)46 {47 var newRow = dataTable.NewRow();48 var itemArray = newRow.ItemArray;49 new List<object>(group.Key.Members).CopyTo(0, itemArray, 0, group.Key.Members.Count());50 var alreadyValued = new List<string>();51 foreach (DataRow groupRow in group.Value.Rows)52 foreach (var valueColumn in valueColumns)53 {54 var nameValueColumn = namingStrategy.Execute(groupRow.GetValue(Args.Header).ToString(), valueColumn.ColumnName);55 if (!alreadyValued.Contains(nameValueColumn))56 {57 alreadyValued.Add(nameValueColumn);58 var identifier = new ColumnNameIdentifier(nameValueColumn);59 itemArray[dataTable.GetColumn(identifier).Ordinal] = groupRow[valueColumn.ColumnName];60 }61 else62 throw new ArgumentException();63 }64 newRow.ItemArray = itemArray;65 dataTable.Rows.Add(newRow);66 }67 dataTable.AcceptChanges();68 rs.Load(dataTable);69 }70 return rs;71 }72 private interface INamingStrategy73 {74 string Execute(string header, string value);75 }76 private class UniqueValueNamingStrategy : INamingStrategy77 {78 public string Execute(string header, string value) => header;79 }80 private class MultipleValuesNamingStrategy : INamingStrategy81 {82 public string Execute(string header, string value) => $"{header}_{value}";83 }84 }85}...
Execute
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Data;4using System.Linq;5using System.Text;6using System.Threading.Tasks;7using NBi.Core.ResultSet.Alteration.Reshaping;8{9 {10 static void Main(string[] args)11 {12 DataTable dt = new DataTable("Test");13 dt.Columns.Add("ID", typeof(int));14 dt.Columns.Add("Name", typeof(string));15 dt.Columns.Add("Age", typeof(int));16 dt.Rows.Add(1, "A", 10);17 dt.Rows.Add(1, "B", 20);18 dt.Rows.Add(2, "C", 30);19 dt.Rows.Add(2, "D", 40);20 dt.Rows.Add(3, "E", 50);21 dt.Rows.Add(3, "F", 60);22 UnstackEngine unstackEngine = new UnstackEngine(dt, "ID", "Name", "Age");23 DataTable result = unstackEngine.Execute();24 }25 }26}27using System;28using System.Collections.Generic;29using System.Data;30using System.Linq;31using System.Text;32using System.Threading.Tasks;33using NBi.Core.ResultSet.Alteration.Reshaping;34{35 {36 static void Main(string[] args)37 {38 DataTable dt = new DataTable("Test");39 dt.Columns.Add("ID", typeof(int));40 dt.Columns.Add("Name", typeof(string));41 dt.Columns.Add("Age", typeof(int));42 dt.Rows.Add(1, "A", 10);43 dt.Rows.Add(1, "B", 20);44 dt.Rows.Add(2, "C", 30);45 dt.Rows.Add(2, "D", 40);46 dt.Rows.Add(3, "E", 50);47 dt.Rows.Add(3, "F", 60);48 UnpivotEngine unpivotEngine = new UnpivotEngine(dt, "ID", "Name", "Age");49 DataTable result = unpivotEngine.Execute();50 }51 }52}53using System;54using System.Collections.Generic;55using System.Data;56using System.Linq;
Execute
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Data;4using System.Linq;5using System.Text;6using System.Threading.Tasks;7using NBi.Core.ResultSet.Alteration.Reshaping;8using NBi.Core.ResultSet.Alteration.Reshaping.Unstack;9using NBi.Core.ResultSet.Resolver;10using NBi.Core.Variable;11using NBi.Core.Calculation;12using NBi.Core.Calculation.Predicate;13using NBi.Core.Calculation.Function;14using NBi.Core.Calculation.Ranking;15using NBi.Core.ResultSet;16using NBi.Core.ResultSet.Resolver;17using NBi.Core.ResultSet.Resolver.File;18using NBi.Core.ResultSet.Resolver.Csv;19using NBi.Core.ResultSet.Resolver.Xml;20using NBi.Core.ResultSet.Resolver.Json;21using NBi.Core.ResultSet.Resolver.ODBC;22using NBi.Core.ResultSet.Resolver.Oracle;23using NBi.Core.ResultSet.Resolver.DbCommand;24using NBi.Core.ResultSet.Resolver.Fake;
Execute
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using NBi.Core.ResultSet.Alteration.Reshaping;7using NBi.Core.ResultSet;8using NBi.Core.Calculation.Grouping;9{10 {11 public ResultSet Execute(ResultSet rs, string columnName, string separator)12 {13 var unstacker = new Unstacker(rs, columnName, separator);14 return unstacker.Execute();15 }16 }17}18using System;19using System.Collections.Generic;20using System.Linq;21using System.Text;22using System.Threading.Tasks;23using NBi.Core.ResultSet.Alteration.Reshaping;24using NBi.Core.ResultSet;25using NBi.Core.Calculation.Grouping;26{27 {28 protected ResultSet ResultSet { get; }29 protected string ColumnName { get; }30 protected string Separator { get; }31 public Unstacker(ResultSet resultSet, string columnName, string separator)32 {33 ResultSet = resultSet;34 ColumnName = columnName;35 Separator = separator;36 }37 public ResultSet Execute()38 {39 var columnOrdinal = ResultSet.Columns.IndexOf(ColumnName);40 var newColumns = ResultSet.Columns.Where((x, i) => i != columnOrdinal).ToList();41 var newRows = new List<IRow>();42 foreach (var row in ResultSet.Rows)43 {44 var values = row[columnOrdinal].ToString().Split(new string[] { Separator }, StringSplitOptions.None);45 foreach (var value in values)46 {47 var newRow = new List<object>();48 var index = 0;49 foreach (var column in ResultSet.Columns)50 {51 if (index == columnOrdinal)52 newRow.Add(value);53 newRow.Add(row[index]);54 index++;55 }56 newRows.Add(new Row(newRow));57 }58 }59 return new ResultSet(newColumns, newRows);60 }61 }62}63using System;64using System.Collections.Generic;65using System.Linq;66using System.Text;67using System.Threading.Tasks;
Execute
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using NBi.Core.ResultSet.Alteration.Reshaping;7using NBi.Core.ResultSet;8using NBi.Core.ResultSet.Resolver;9{10 {11 static void Main(string[] args)12 {13 var engine = new UnstackEngine(new ResultSetResolverArgs("select * from [Sheet2$]"), "Column1", "Column2", "Column3");14 var result = engine.Execute();15 Console.WriteLine(result.ResultSet.GetXml());16 Console.ReadLine();17 }18 }19}20using System;21using System.Collections.Generic;22using System.Linq;23using System.Text;24using System.Threading.Tasks;25using NBi.Core.ResultSet.Alteration.Reshaping;26using NBi.Core.ResultSet;27using NBi.Core.ResultSet.Resolver;28{29 {30 static void Main(string[] args)31 {32 var engine = new UnstackEngine(new ResultSetResolverArgs("select * from [Sheet2$]"), "Column1", "Column2", "Column3");33 var result = engine.Execute();34 Console.WriteLine(result.ResultSet.GetXml());35 Console.ReadLine();36 }37 }38}39using System;40using System.Collections.Generic;41using System.Linq;42using System.Text;43using System.Threading.Tasks;44using NBi.Core.ResultSet.Alteration.Reshaping;45using NBi.Core.ResultSet;46using NBi.Core.ResultSet.Resolver;47{48 {49 static void Main(string[] args)50 {51 var engine = new UnstackEngine(new ResultSetResolverArgs("select * from [Sheet2$]"), "Column1", "Column2", "Column3");52 var result = engine.Execute();53 Console.WriteLine(result.ResultSet.GetXml());54 Console.ReadLine();55 }56 }57}58using System;59using System.Collections.Generic;60using System.Linq;61using System.Text;62using System.Threading.Tasks;63using NBi.Core.ResultSet.Alteration.Reshaping;
Execute
Using AI Code Generation
1using System;2using System.Data;3using NBi.Core.ResultSet;4using NBi.Core.ResultSet.Alteration.Reshaping;5{6 {7 static void Main(string[] args)8 {9 DataTable dt = new DataTable();10 dt.Columns.Add("id", typeof(int));11 dt.Columns.Add("name", typeof(string));12 dt.Columns.Add("value", typeof(int));13 dt.Rows.Add(1, "A", 10);14 dt.Rows.Add(1, "B", 20);15 dt.Rows.Add(2, "A", 30);16 dt.Rows.Add(2, "B", 40);17 dt.Rows.Add(2, "C", 50);18 dt.Rows.Add(3, "A", 60);19 dt.Rows.Add(3, "B", 70);20 dt.Rows.Add(3, "C", 80);21 dt.Rows.Add(3, "D", 90);22 UnstackEngine unstackEngine = new UnstackEngine();23 UnstackArgs unstackArgs = new UnstackArgs("id", "name", "value");24 var result = unstackEngine.Execute(dt, unstackArgs);25 foreach (DataRow row in result.Rows)26 {27 Console.WriteLine("{0}, {1}, {2}, {3}", row[0], row[1], row[2], row[3]);28 }29 Console.ReadKey();30 }31 }32}
Execute
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using NBi.Core.ResultSet.Alteration.Reshaping;7using NBi.Core.ResultSet;8using NBi.Core.Calculation.Grouping;9{10 {11 public ResultSet Execute(ResultSet rs, string columnName, string separator)12 {13 var unstacker = new Unstacker(rs, columnName, separator);14 return unstacker.Execute();15 }16 }17}18using System;19using System.Collections.Generic;20using System.Linq;21using System.Text;22using System.Threading.Tasks;23using NBi.Core.ResultSet.Alteration.Reshaping;24using NBi.Core.ResultSet;25using NBi.Core.Calculation.Grouping;26{27 {28 protected ResultSet ResultSet { get; }29 protected string ColumnName { get; }30 protected string Separator { get; }31 public Unstacker(ResultSet resultSet, string columnName, string separator)32 {33 ResultSet = resultSet;34 ColumnName = columnName;35 Separator = separator;36 }37 public ResultSet Execute()38 {39 var columnOrdinal = ResultSet.Columns.IndexOf(ColumnName);40 var newColumns = ResultSet.Columns.Where((x, i) => i != columnOrdinal).ToList();41 var newRows = new List<IRow>();42 foreach (var row in ResultSet.Rows)43 {44 var values = row[columnOrdinal].ToString().Split(new string[] { Separator }, StringSplitOptions.None);45 foreach (var value in values)46 {47 var newRow = new List<object>();48 var index = 0;49 foreach (var column in ResultSet.Columns)50 {51 if (index == columnOrdinal)52 newRow.Add(value);53 newRow.Add(row[index]);54 index++;55 }56 newRows.Add(new Row(newRow));57 }58 }59 return new ResultSet(newColumns, newRows);60 }61 }62}63using System;64using System.Collections.Generic;65using System.Linq;66using System.Text;67using System.Threading.Tasks;
Execute
Using AI Code Generation
1using System;2using System.Data;3using NBi.Core.ResultSet;4using NBi.Core.ResultSet.Alteration.Reshaping;5{6 {7 static void Main(string[] args)8 {9 DataTable dt = new DataTable();10 dt.Columns.Add("id", typeof(int));11 dt.Columns.Add("name", typeof(string));12 dt.Columns.Add("value", typeof(int));13 dt.Rows.Add(1, "A", 10);14 dt.Rows.Add(1, "B", 20);15 dt.Rows.Add(2, "A", 30);16 dt.Rows.Add(2, "B", 40);17 dt.Rows.Add(2, "C", 50);18 dt.Rows.Add(3, "A", 60);19 dt.Rows.Add(3, "B", 70);20 dt.Rows.Add(3, "C", 80);21 dt.Rows.Add(3, "D", 90);22 UnstackEngine unstackEngine = new UnstackEngine();23 UnstackArgs unstackArgs = new UnstackArgs("id", "name", "value");24 var result = unstackEngine.Execute(dt, unstackArgs);25 foreach (DataRow row in result.Rows)26 {27 Console.WriteLine("{0}, {1}, {2}, {3}", row[0], row[1], row[2], row[3]);28 }29 Console.ReadKey();30 }31 }32}
Execute
Using AI Code Generation
1using System;2using System.Data;3using NBi.Core.ResultSet.Alteration.Reshaping;4using NBi.Core.ResultSet;5{6 {7 static void Main(string[] args)8 {9 DataTable dt = new DataTable();10 dt.Columns.Add("id", typeof(int));11 dt.Columns.Add("value", typeof(int));12 dt.Columns.Add("type", typeof(string));13 dt.Rows.Add(1, 10, "A");14 dt.Rows.Add(1, 20, "B");15 dt.Rows.Add(2, 30, "C");16 dt.Rows.Add(2, 40, "D");17 dt.Rows.Add(2, 50, "E");18 var columnsToUnstack = new string[] { "value", "type" };19 var unstackEngine = new UnstackEngine(columnsToUnstack);20 var unstackedDt = unstackEngine.Execute(dt);21 }22 }23}24using System;25using System.Data;26using NBi.Core.ResultSet.Alteration.Reshaping;27using NBi.Core.ResultSet;28{29 {30 static void Main(string[] args)31 {32 DataTable dt = new DataTable();33 dt.Columns.Add("id", typeof(int));34 dt.Columns.Add("valueA", typeof(int));35 dt.Columns.Add("valueB", typeof(int));36 dt.Columns.Add("valueC", typeof(int));37 dt.Columns.Add("valueD", typeof(int));38 dt.Columns.Add("valueE", typeof(int));39 dt.Rows.Add(1, 10, 20, DBNull.Value, DBNull.Value, DBNull.Value);40 dt.Rows.Add(2, DBNull.Value, DBNull.Value, 30, 40, 50);41 var columnsToStack = new string[] { "valueA", "valueB", "valueC", "valueD", "valueE" };42 var stackEngine = new StackEngine(columnsToStack, "type");43 var stackedDt = stackEngine.Execute(dt);44 }45 }46}47using System;48using System.Data;49using NBi.Core.ResultSet.Alteration.Reshaping;50using NBi.Core.ResultSet;
Execute
Using AI Code Generation
1var engine = new UnstackEngine();2engine.Execute(resultSet, new UnstackArgs("column1", "column2", "column3"));3var engine = new UnstackEngine();4engine.Execute(resultSet, new UnstackArgs("column1", "column2", "column3"));5var engine = new UnstackEngine();6engine.Execute(resultSet, new UnstackArgs("column1", "column2", "column3"));7var engine = new UnstackEngine();8engine.Execute(resultSet, new UnstackArgs("column1", "column2", "column3"));9var engine = new UnstackEngine();10engine.Execute(resultSet, new UnstackArgs("column1", "column2", "column3"));11var engine = new UnstackEngine();12engine.Execute(resultSet, new UnstackArgs("column1", "column2", "column3"));13var engine = new UnstackEngine();14engine.Execute(resultSet, new UnstackArgs("column1", "column2", "column3"));15var engine = new UnstackEngine();16engine.Execute(resultSet, new UnstackArgs("column1", "column2", "column3"));17var engine = new UnstackEngine();18engine.Execute(resultSet, new UnstackArgs("column1", "column2", "column3"));
Execute
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using System.Data;7using NBi.Core.ResultSet;8using NBi.Core.ResultSet.Alteration.Reshaping;9{10 {11 static void Main(string[] args)12 {13 DataTable dt = new DataTable("Test");14 dt.Columns.Add("A", typeof(string));15 dt.Columns.Add("B", typeof(string));16 dt.Columns.Add("C", typeof(string));17 dt.Columns.Add("D", typeof(string));18 dt.Columns.Add("E", typeof(string));19 dt.Columns.Add("F", typeof(string));20 dt.Columns.Add("G", typeof(string));21 dt.Columns.Add("H", typeof(string));22 dt.Columns.Add("I", typeof(string));23 dt.Columns.Add("J", typeof(string));24 dt.Columns.Add("K", typeof(string));25 dt.Columns.Add("L", typeof(string));26 dt.Columns.Add("M", typeof(string));27 dt.Columns.Add("N", typeof(string));28 dt.Columns.Add("O", typeof(string));29 dt.Columns.Add("P", typeof(string));30 dt.Columns.Add("Q", typeof(string));31 dt.Columns.Add("R", typeof(string));32 dt.Columns.Add("S", typeof(string));33 dt.Columns.Add("T", typeof(string));34 dt.Columns.Add("U", typeof(stri
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!