How to set dynamic assert conditions for deequ verification checks in scala

268 Views Asked by At

I am using deequ verificationsuite to validate my sql tables but I am unable to implement dynamic assert conditions for checks :

val verificationResult: VerificationResult = { VerificationSuite()
  .onData(dataset)
  .addCheck(
    Check(CheckLevel.Error, "Review Check") 
      .hasSize(_ >= 3000000)
  .run()
}

So if you see the assert condition _ >= 3000000 this need to be made dynamic in such a way so that I can support following assertions too :

_ >= 3000000
_ <= 3000000
_ == 3000000
_ > 3000000
_ < 3000000

So how can I provide dynamic assertions to hasSize check in the example I have highlighted.

1

There are 1 best solutions below

0
vibhor Gupta On BEST ANSWER
def validate(val){

    def gtCondn(): Boolean = {
        _ >= val
    }

    val verificationResult: VerificationResult = { VerificationSuite()
      .onData(dataset)
      .addCheck(Check(CheckLevel.Error, "Review Check").hasSize(gtCondn)).run()
    }
}