Skip to content

Commit

Permalink
codeql updates
Browse files Browse the repository at this point in the history
  • Loading branch information
JFriel committed Jan 6, 2025
1 parent 91dcf0d commit 1debdcb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 29 deletions.
29 changes: 7 additions & 22 deletions Rdmp.Core.Tests/DataQualityEngine/DQEPartialUpdateTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using NLog;
using NPOI.POIFS.Properties;
using NPOI.SS.Formula.Functions;
using NPOI.SS.Formula.Functions;
using NUnit.Framework;
using Org.BouncyCastle.Tls;
using Rdmp.Core.Curation;
using Rdmp.Core.Curation.Data;
using Rdmp.Core.Curation.Data.DataLoad;
Expand All @@ -20,33 +17,25 @@
using Rdmp.Core.DataLoad.Triggers;
using Rdmp.Core.DataQualityEngine.Data;
using Rdmp.Core.DataQualityEngine.Reports;
using Rdmp.Core.Logging;
using Rdmp.Core.Repositories;
using Rdmp.Core.ReusableLibraryCode.Checks;
using Rdmp.Core.ReusableLibraryCode.Progress;
using Rdmp.Core.Tests.DataLoad.Engine.Integration;
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Tests.Common;
using static Org.BouncyCastle.Math.EC.ECCurve;

namespace Rdmp.Core.Tests.DataQualityEngine
{
internal class DQEPartialUpdateTests : DataLoadEngineTestsBase
{

string validatorXML = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<Validator xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n <ItemValidators>\r\n <ItemValidator>\r\n <PrimaryConstraint xsi:type=\"Chi\">\r\n <Consequence>Wrong</Consequence>\r\n </PrimaryConstraint>\r\n <TargetProperty>chi</TargetProperty>\r\n <SecondaryConstraints />\r\n </ItemValidator>\r\n <ItemValidator>\r\n <TargetProperty>time</TargetProperty>\r\n <SecondaryConstraints />\r\n </ItemValidator>\r\n </ItemValidators>\r\n</Validator>";
string fileLocation = Path.GetTempPath();
string fileName = "SteppedDQEPartialUpdates.csv";
readonly string validatorXML = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<Validator xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\r\n <ItemValidators>\r\n <ItemValidator>\r\n <PrimaryConstraint xsi:type=\"Chi\">\r\n <Consequence>Wrong</Consequence>\r\n </PrimaryConstraint>\r\n <TargetProperty>chi</TargetProperty>\r\n <SecondaryConstraints />\r\n </ItemValidator>\r\n <ItemValidator>\r\n <TargetProperty>time</TargetProperty>\r\n <SecondaryConstraints />\r\n </ItemValidator>\r\n </ItemValidators>\r\n</Validator>";
readonly string fileLocation = Path.GetTempPath();
readonly string fileName = "SteppedDQEPartialUpdates.csv";

[Test]
public void SteppedDQEPartialUpdates()
Expand All @@ -63,7 +52,7 @@ public void SteppedDQEPartialUpdates()

var table = server.CreateTable("PartialToaDQE", dt);
table.CreatePrimaryKey(table.DiscoverColumns().Where(c => c.GetRuntimeName() == "chi").ToArray());

dt.Dispose();

Check warning

Code scanning / CodeQL

Dispose may not be called if an exception is thrown during execution Warning test

Dispose missed if exception is thrown by
call to method Add
.
Dispose missed if exception is thrown by
call to method Add
.
Dispose missed if exception is thrown by
call to method Add
.
Dispose missed if exception is thrown by
call to method Add
.
Dispose missed if exception is thrown by
call to method Add
.
Dispose missed if exception is thrown by
call to method Add
.
Dispose missed if exception is thrown by
call to method CreateTable
.
Dispose missed if exception is thrown by
call to method CreatePrimaryKey
.
Dispose missed if exception is thrown by
call to method ToArray
.
Dispose missed if exception is thrown by
call to method Where
.
Dispose missed if exception is thrown by
call to method DiscoverColumns
.
var catalogue = new Catalogue(CatalogueRepository, "PartialToaDQE");
var importer = new TableInfoImporter(CatalogueRepository, table);
importer.DoImport(out var _tableInfo, out var _columnInfos);
Expand Down Expand Up @@ -93,7 +82,7 @@ public void SteppedDQEPartialUpdates()

var listener = new ToMemoryDataLoadEventListener(false);
report.GenerateReport(catalogue, listener, source.Token);

source.Dispose();

Check warning

Code scanning / CodeQL

Dispose may not be called if an exception is thrown during execution Warning test

Dispose missed if exception is thrown by
call to method GenerateReport
.
var lmd = new LoadMetadata(CatalogueRepository, "MyLoad");
lmd.LocationOfForLoadingDirectory = Path.GetTempPath();
lmd.LocationOfForArchivingDirectory = Path.GetTempPath();
Expand Down Expand Up @@ -144,7 +133,6 @@ public void SteppedDQEPartialUpdates()
dt.Rows.Add(new string[] { "1111111112", "A", "2024-11-01" });
dt.Rows.Add(new string[] { "1111111113", "B", "2024-10-01" });
SetupFile(dt);

PerformLoad(lmd, logManager);
//end of first load
report = new CatalogueConstraintReport(catalogue, SpecialFieldNames.DataLoadRunID)
Expand Down Expand Up @@ -296,10 +284,6 @@ public void SteppedDQEPartialUpdates()
evaluations = dqeRepository.GetAllObjectsWhere<Evaluation>("CatalogueID", catalogue.ID).ToList();//.Where(e => e.CatalogueID == catalogue.ID).ToList();
Assert.That(evaluations.Count, Is.EqualTo(13));
CompareEvaluations(evaluations[12], evaluations[11]);


Assert.That(true, Is.EqualTo(true));

}

private void SetupFile(DataTable dt)
Expand All @@ -318,6 +302,7 @@ private void SetupFile(DataTable dt)
lines.Add(string.Join(',', row.ItemArray.Select(i => i.ToString())));
}
File.AppendAllLines(Path.Combine(fileLocation, fileName), lines);
dt.Dispose();
}

private void CompareEvaluations(Evaluation e1, Evaluation e2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,8 @@ public void UpdateReport(ICatalogue c, int dataLoadID, int? commandTimeout, IDat
var reportBuilder = new ReportBuilder(c, _validator, _queryBuilder, _dataLoadRunFieldName, _containsDataLoadID, _timePeriodicityField, _pivotCategory, rDT);
reportBuilder.BuildReportInternals(cancellationToken, forker, dqeRepository);
var newByPivotRowStatesOverDataLoadRunId = reportBuilder.GetByPivotRowStatesOverDataLoadRunId();
var newByPivotCategoryCubesOverTime = reportBuilder.GetByPivotCategoryCubesOverTime();

var pivotColumn = c.PivotCategory_ExtractionInformation.ColumnInfo.GetRuntimeName();
var timeColumn = c.TimeCoverage_ExtractionInformation.ColumnInfo.GetRuntimeName();

var incomingPivotCategories = rDT.AsEnumerable().Select(r => r[pivotColumn].ToString()).ToList().Distinct();

Expand Down Expand Up @@ -402,9 +400,9 @@ public void UpdateReport(ICatalogue c, int dataLoadID, int? commandTimeout, IDat
//* Periodicity States *//

//Unchanged
newByPivotCategoryCubesOverTime = [];//reset
Dictionary<string, PeriodicityCubesOverTime> newByPivotCategoryCubesOverTime = [];//reset

var unchangedPivotCategories = previousRowSates.Where(rs => rs.PivotCategory != "ALL" && !existingIncomingPivotCategories.Contains(rs.PivotCategory) && !replacedPivotCategories.Contains(rs.PivotCategory)).Select(rs => rs.PivotCategory).Distinct(); foreach (var previousRowState in previousRowSates.Where(rs => rs.PivotCategory != "ALL" && !existingIncomingPivotCategories.Contains(rs.PivotCategory) && !replacedPivotCategories.Contains(rs.PivotCategory))) ;
var unchangedPivotCategories = previousRowSates.Where(rs => rs.PivotCategory != "ALL" && !existingIncomingPivotCategories.Contains(rs.PivotCategory) && !replacedPivotCategories.Contains(rs.PivotCategory)).Select(rs => rs.PivotCategory).Distinct();
newByPivotCategoryCubesOverTime.TryGetValue("ALL", out var value);
if (value is null)
{
Expand Down
6 changes: 3 additions & 3 deletions Rdmp.Core/DataQualityEngine/Reports/ReportBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public class ReportBuilder
private readonly Validator _validator;
private readonly bool _containsDataLoadID;

public static int MaximumPivotValues = 5000;
private static readonly int MaximumPivotValues = 5000;

private Dictionary<string, DQEStateOverDataLoadRunId> byPivotRowStatesOverDataLoadRunId = new();
private Dictionary<string, PeriodicityCubesOverTime> byPivotCategoryCubesOverTime = new();
private readonly Dictionary<string, DQEStateOverDataLoadRunId> byPivotRowStatesOverDataLoadRunId = [];
private readonly Dictionary<string, PeriodicityCubesOverTime> byPivotCategoryCubesOverTime = [];

private readonly string _timePeriodicityField;
private readonly string _pivotCategory;
Expand Down

0 comments on commit 1debdcb

Please sign in to comment.