Iam using 3 datatable and comparing 3 columns which are != (NotEqual) with both Datatable and getting the desired Output but Query taking 45 mins to execute due to huge data.Kindly help to tune the Query to execute faster.
DT1 - dt_calero_final_iphone with 180000 records
DT2 - DT_MatchedDelta with 40000 records
DT3 - DT_UnMatchedDelta with 80000 records
QUERY:
(From row In dt_calero_final_iphone.AsEnumerable()
Where Not DT_MatchedDelta.AsEnumerable().Any(Function (r1) r1(“Calero Phone #”).ToString.Trim = row(“Mobile Number”).tostring.Trim) _
AndAlso Not DT_UnMatchedDelta.AsEnumerable().Any(Function (r2) r2(“Calero Phone #”).ToString.trim = row(“Mobile Number”).tostring.Trim)
Select dt_calero_final_iphone.Clone().LoadDataRow({row(“Serial Number -Device”),row(“Mobile Number”),row(“Employee number”)}, False)).CopyToDataTable()
Hello @ppr I know you’re busy, but if you could spare a few minutes, it would mean a lot but I feel I’m missing something your experience would help me a lot to tune this Query to execute faster
Firstly we see 3 datatables instead of two..are those two datatables have same columns? If yes then you can first use merge datatable and then do linq..which reduces a lot
Yes 3 datables only if we merge we cant get the unmatching columns the above qiery is working but taking more time due to more records I have sort the datables before passing to linq some what time reduced and tring to tune the query
You can merge the matched and unmatched dt and then use join datatable with full join on first table and filter with empty values in the resultant table to get matched..non empty are matched rows
Iam using 2 datatable and compare 3 not equal columns with 2 table and getting the desired Output but Query taking 45 mins to execute..Kindly help to tune the Query.
DT1 - dt_calero_final_iphone with 180000 records
DT2 - DT_MatchedDelta with 400000 records
QUERY:
(From row In dt_calero_final_iphone.AsEnumerable()
Where Not DT_MatchedDelta.AsEnumerable().Any(Function (r1) r1(“Calero Phone #”).ToString.Trim = row(“Mobile Number”).tostring.Trim) _
AndAlso Not DT_UnMatchedDelta.AsEnumerable().Any(Function (r2) r2(“Calero Phone #”).ToString.trim = row(“Mobile Number”).tostring.Trim)
Select dt_calero_final_iphone.Clone().LoadDataRow({row(“Serial Number -Device”),row(“Mobile Number”),row(“Employee number”)}, False)).CopyToDataTable()
' Build exclusion set once'
Dim excludePhones As New HashSet(Of String)(
DT_MatchedDelta.AsEnumerable().Select(Function(r) r("Calero Phone #").ToString().Trim).
Union(DT_UnMatchedDelta.AsEnumerable().Select(Function(r) r("Calero Phone #").ToString().Trim))
)
' Filter rows efficiently'
Dim result As DataTable = dt_calero_final_iphone.Clone()
For Each row In dt_calero_final_iphone.AsEnumerable()
Dim phone As String = row("Mobile Number").ToString().Trim
If Not excludePhones.Contains(phone) Then
result.ImportRow(row)
End If
Next
files = (
From f In System.IO.Directory.GetFiles(folderPath, “abc_*.xlsx”, System.IO.SearchOption.TopDirectoryOnly)
Let fileName = System.IO.Path.GetFileName(f)
Where Not fileName.StartsWith(“~$”)
Let name = System.IO.Path.GetFileNameWithoutExtension(f)
Let parts = name.Split("_"c)
Where parts.Length = 3 AndAlso System.Text.RegularExpressions.Regex.IsMatch(parts(2), “^\d+$”)
Let numPart = Integer.Parse(parts(2))
Order By numPart Ascending
Select f
).ToArray()