Search code examples
scalaamazon-deequpydeequ

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


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.


Solution

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