Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display success message in Verification Suite Result #375

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ private[deequ] case class AnalysisBasedConstraint[S <: State[S], M, V](
val assertionOk = runAssertion(assertOn)

if (assertionOk) {
ConstraintResult(this, ConstraintStatus.Success, metric = Some(metric))
var successMessage = s"Value: $assertOn does meet the constraint requirement!"
hint.foreach(hint => successMessage += s" $hint")

ConstraintResult(this, ConstraintStatus.Success, Some(successMessage), Some(metric))
} else {
var errorMessage = s"Value: $assertOn does not meet the constraint requirement!"
hint.foreach(hint => errorMessage += s" $hint")
Expand Down
11 changes: 7 additions & 4 deletions src/test/scala/com/amazon/deequ/VerificationResultTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ class VerificationResultTest extends WordSpec with Matchers with SparkContextSpe
import session.implicits._
val expected = Seq(
("group-1", "Error", "Success", "CompletenessConstraint(Completeness(att1,None))",
"Success", ""),
"Success", "Value: 1.0 does meet the constraint requirement!"),
("group-2-E", "Error", "Error", "SizeConstraint(Size(None))", "Failure",
"Value: 4 does not meet the constraint requirement! Should be greater than 5!"),
("group-2-E", "Error", "Error", "CompletenessConstraint(Completeness(att2,None))",
"Success", ""),
"Success", "Value: 1.0 does meet the constraint requirement! Should equal 1!"),
("group-2-W", "Warning", "Warning",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify why the message contains the hint ("Should ...!") in one case, but not in the other?

Copy link
Author

@andreaslang andreaslang Sep 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, the reason is that the first check does not actually have a hint. In that case only the standard message is shown.

The checks are in the same test suite from line 201:

private[this] def getChecks(): Seq[Check] = {
    val checkToSucceed = Check(CheckLevel.Error, "group-1")
      .isComplete("att1")

    val checkToErrorOut = Check(CheckLevel.Error, "group-2-E")
      .hasSize(_ > 5, Some("Should be greater than 5!"))
      .hasCompleteness("att2", _ == 1.0, Some("Should equal 1!"))

    val checkToWarn = Check(CheckLevel.Warning, "group-2-W")
      .hasDistinctness(Seq("item"), _ < 0.8, Some("Should be smaller than 0.8!"))

    checkToSucceed :: checkToErrorOut :: checkToWarn :: Nil
}

The change allows the message and hint to be passed through even if the evaluation was a success, before that the message and the hint was not displayed. Passing it through makes it a bit easier if the verification result is saved, because they can be used to know what the threshold at a given time was.

"DistinctnessConstraint(Distinctness(List(item),None))",
"Failure", "Value: 1.0 does not meet the constraint requirement! " +
Expand All @@ -151,7 +151,8 @@ class VerificationResultTest extends WordSpec with Matchers with SparkContextSpe
val expectedJson =
"""[{"check":"group-1","check_level":"Error","check_status":"Success",
|"constraint":"CompletenessConstraint(Completeness(att1,None))",
|"constraint_status":"Success","constraint_message":""},
|"constraint_status":"Success",
|"constraint_message":"Value: 1.0 does meet the constraint requirement!"},
|
|{"check":"group-2-E","check_level":"Error","check_status":"Error",
|"constraint":"SizeConstraint(Size(None))", "constraint_status":"Failure",
Expand All @@ -160,7 +161,9 @@ class VerificationResultTest extends WordSpec with Matchers with SparkContextSpe
|
|{"check":"group-2-E","check_level":"Error","check_status":"Error",
|"constraint":"CompletenessConstraint(Completeness(att2,None))",
|"constraint_status":"Success","constraint_message":""},
|"constraint_status":"Success",
|"constraint_message":"Value: 1.0 does meet the constraint requirement!
| Should equal 1!"},
|
|{"check":"group-2-W","check_level":"Warning","check_status":"Warning",
|"constraint":"DistinctnessConstraint(Distinctness(List(item),None))",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class AnalysisBasedConstraintTest extends WordSpec with Matchers with SparkConte
SampleAnalyzer("att1"), _ == 1.0), df)

assert(resultA.status == ConstraintStatus.Success)
assert(resultA.message.isEmpty)
assert(resultA.message.contains("Value: 1.0 does meet the constraint requirement!"))
assert(resultA.metric.isDefined)

// Analysis result should equal to 1.0 for an existing column
Expand Down