public override void Execute(DataTable table, IIssueCollector issueCollector, IProviderCollection providers) { var columns = table.QueryableColumns.Where(c => DataTypesLists.TextTypes().Contains(c.DataType)); var candidates = columns.ToList().Select(c => new Candidate(c)).ToList(); using (var rowEnumerable = table.GetTableRowEnumerable()) foreach (var row in rowEnumerable) { foreach (var candidate in candidates) { Object value = row[candidate.Column.ColumnName]; if (value is String) { String valueStr = (String)value; if (valueStr == String.Empty) { continue; } ValueType type = Classifier.Classify(valueStr); candidate.AddValue(valueStr, type); } } if (candidates.Count() == 0) { break; } } foreach (var candidate in candidates) { if (candidate.Values.Count <= 1) { continue; } System.Data.DataTable valuesTable = new System.Data.DataTable(); valuesTable.Columns.Add("Value Examples", typeof(String)); valuesTable.Columns.Add("Data Type", typeof(String)); foreach (var dicEntry in candidate.Values) { foreach (var val in dicEntry.Value) { var row = valuesTable.NewRow(); row[0] = val; row[1] = dicEntry.Key.ToString(); valuesTable.Rows.Add(row); } } Issue issue = new Issue(this, this.Severity); issue.Name = "Mixture of Data Types in a Column"; issue.Description = new Description("The column '{0}' contains a mixture of data types", candidate.Column); issue.ExtendedDescription = new Description("Examples:\n\n{0}", valuesTable); issue.Context = new ColumnContext(candidate.Column); issueCollector.ReportIssue(issue); } }
public override void Execute(DataTable table, IIssueCollector issueCollector, IProviderCollection providers) { if (table.Cardinality < MinValues.Value) { return; } var columns = table.QueryableColumns.Where(c => DataTypesLists.TextTypes().Contains(c.DataType)); if (columns.Count() == 0) { return; } var testColumns = columns.Select(c => new TestColumn(c)).ToList(); using (var rowEnumerable = table.GetTableRowEnumerable()) foreach (var row in rowEnumerable) { foreach (var testColumn in testColumns) { Object val = row[testColumn.Column.ColumnName]; if (val is String) { String str = val as String; if (str.Length < 1) { continue; } testColumn.ValueCount += 1; if (str[0] == char.ToLower(str[0])) { testColumn.LowercaseStart += 1; } else { testColumn.UppercaseStart += 1; } } } } foreach (var testColumn in testColumns) { if (testColumn.ValueCount <= this.MinValues.Value) { continue; } float lowerPercent = ((float)testColumn.LowercaseStart / testColumn.ValueCount) * 100; float upperPercent = ((float)testColumn.UppercaseStart / testColumn.ValueCount) * 100; float lowest = Math.Min(lowerPercent, upperPercent); if (lowest < Threshold.Value && lowest != 0) { Issue issue = new Issue(this, this.Severity); issue.Name = "Inconsistent Casing of First Character in Text Column"; issue.Context = new ColumnContext(testColumn.Column); issue.Description = new Description("Inconsistent casing of first character in column '{0}'", testColumn.Column); issue.ExtendedDescription = new Description("{0}% starts with lowercase\n{1}% starts with uppercase", lowerPercent, upperPercent); issueCollector.ReportIssue(issue); } } }