From c674be998bcef0eed22855dea0137928980f4a69 Mon Sep 17 00:00:00 2001 From: Ladislav Sulak Date: Wed, 3 Apr 2024 18:19:06 +0200 Subject: [PATCH] #118: majority Win algorithm improved, now it is certain that the first one will be returned if multiple errors were present with the same max count --- .../ByMajorityErrorsStatusAggregator.scala | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/core/src/main/scala/za/co/absa/fadb/status/aggregation/implementations/ByMajorityErrorsStatusAggregator.scala b/core/src/main/scala/za/co/absa/fadb/status/aggregation/implementations/ByMajorityErrorsStatusAggregator.scala index 1056d292..daa465ae 100644 --- a/core/src/main/scala/za/co/absa/fadb/status/aggregation/implementations/ByMajorityErrorsStatusAggregator.scala +++ b/core/src/main/scala/za/co/absa/fadb/status/aggregation/implementations/ByMajorityErrorsStatusAggregator.scala @@ -32,8 +32,15 @@ trait ByMajorityErrorsStatusAggregator extends StatusAggregator { } else { val grouped = inputData.groupBy(identity) val maxCount = grouped.values.map(_.size).max - val mostOccurred = grouped.filter(_._2.size == maxCount).keys.toList - Some(mostOccurred.head) + + // list of most frequent one (or ones if maxCount is the same for multiple records) + val mostOccurredAll = grouped.filter(_._2.size == maxCount).keys.toList + + // find stops on first occurrence - so it returns the first it found from `mostOccurredAll` - in case that there + // are more 'majorityWinners', only the first one from `inputData` will be returned + val mostOccurredFirst = inputData.find(mostOccurredAll.contains(_)) + + mostOccurredFirst } }