Example #1
0
        /// <summary>
        /// Thread safe group by function, should be called from Pre-validate only. Returns max(count()) group by column names
        /// </summary>
        /// <param name="commaSeparatedColumnNames">Comma separated column names</param>
        /// <returns>count</returns>
        public int PreValidateGroupByMaxCount(string commaSeparatedColumnNames)
        {
            List <string> columns = new List <string>(commaSeparatedColumnNames.Split(",".ToCharArray()));

            lock (_lock)
            {
                var result = from row in InputData.AsEnumerable()
                             group row by columns into grp
                             select new
                {
                    Id    = grp.Key,
                    Count = grp.Count()
                };

                int max = 0;
                foreach (var r in result)
                {
                    if (r.Count > max)
                    {
                        max = r.Count;
                    }
                }

                return(max);
            }
        }
Example #2
0
        /// <summary>
        /// Thread safe group by function, should be called from Pre-validate only. Returns max(count()) group by column names
        /// </summary>
        /// <param name="commaSeparatedColumnNames">Comma separated column names</param>
        /// <param name="isSytemColumn">True if the system columns to be searched</param>
        /// <returns>count</returns>
        public int PostValidateGroupByMaxCount(string commaSeparatedColumnNames, bool isSytemColumn = false)
        {
            List <string> columns = new List <string>(commaSeparatedColumnNames.Split(",".ToCharArray()));
            DataTable     table   = new DataTable();

            foreach (string column in columns)
            {
                table.Columns.Add(column);
            }

            lock (_lock)
            {
                foreach (Row row in Rows)
                {
                    DataRow dtRow = table.NewRow();
                    foreach (string column in columns)
                    {
                        if (isSytemColumn)
                        {
                            dtRow[column] = row.ColumnsSystem[column];
                        }
                        else
                        {
                            dtRow[column] = row.Columns[column];
                        }
                    }
                    table.Rows.Add(dtRow);
                }

                var result = from row in InputData.AsEnumerable()
                             group row by columns into grp
                             select new
                {
                    Id    = grp.Key,
                    Count = grp.Count()
                };

                int max = 0;
                foreach (var r in result)
                {
                    if (r.Count > max)
                    {
                        max = r.Count;
                    }
                }

                return(max);
            }
        }