Skip to content

Commit

Permalink
#97 PR review chagnes
Browse files Browse the repository at this point in the history
  • Loading branch information
dk1844 committed Aug 6, 2021
1 parent f75a98e commit 6f161f1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
10 changes: 5 additions & 5 deletions atum/src/main/scala/za/co/absa/atum/core/ControlType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ object ControlType {
case object AbsAggregatedTotal extends ControlType("absAggregatedTotal")
case object HashCrc32 extends ControlType("hashCrc32")

val values = Seq(Count, DistinctCount, AggregatedTotal, AbsAggregatedTotal, HashCrc32)
val valueStrings = values.map(_.value)
val values: Seq[ControlType] = Seq(Count, DistinctCount, AggregatedTotal, AbsAggregatedTotal, HashCrc32)
val valueNames: Seq[String] = values.map(_.value)

def getNormalizedStringValue(input: String): String = {
valueStrings.find(value => isControlMeasureTypeEqual(input, value)).getOrElse(input)
def getNormalizedValueName(input: String): String = {
valueNames.find(value => isControlMeasureTypeEqual(input, value)).getOrElse(input)
}

def withValueName(s: String): ControlType = values.find(_.value.toString == s).getOrElse(
throw new NoSuchElementException(s"No value found for '$s'. Allowed values are: $valueStrings"))
throw new NoSuchElementException(s"No value found for '$s'. Allowed values are: $valueNames"))

def isControlMeasureTypeEqual(x: String, y: String): Boolean = {
if (x.toLowerCase == y.toLowerCase) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ object MeasurementProcessor {
*/
private[atum] def getMeasurementFunction(controlCol: String, controlType: ControlType): MeasurementFunction = {
controlType match {
case Count => (ds: Dataset[Row]) => ds.count().toString
case Count => (ds: Dataset[Row]) =>
ds.select(col(controlCol)).count().toString
case DistinctCount => (ds: Dataset[Row]) => {
ds.select(col(controlCol)).distinct().count().toString
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ object ControlMeasureBuilder {
*/
private case class ControlMeasureBuilderImpl(df: DataFrame,
aggregateColumnMappings: Seq[ControlTypeMapping] = Seq.empty,
aggregateControlTypeStrategy: ControlTypeStrategy
= ControlTypeStrategy.Default,
sourceApplication: String = "",
inputPathName: String = "",
reportDate: String = ControlMeasureUtils.getTodayAsString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ object ControlMeasureUtils {
*/
def normalize(controlMeasure: ControlMeasure): ControlMeasure = {
transformMeasurementInControlMeasure(controlMeasure, measurement => {
measurement.copy(controlType = ControlType.getNormalizedStringValue(measurement.controlType))
measurement.copy(controlType = ControlType.getNormalizedValueName(measurement.controlType))
})
}

Expand Down

0 comments on commit 6f161f1

Please sign in to comment.