From 5087c9f039bb5a9f271f8b40b1836b35f9894d8a Mon Sep 17 00:00:00 2001 From: Andreas Lang Date: Fri, 6 Aug 2021 12:08:35 +0100 Subject: [PATCH 1/2] Display also a success message for verification, seeing the hint and assertOn value makes it easier to see which verification succeeded. --- .../deequ/constraints/AnalysisBasedConstraint.scala | 5 ++++- .../com/amazon/deequ/VerificationResultTest.scala | 11 +++++++---- .../constraints/AnalysisBasedConstraintTest.scala | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/scala/com/amazon/deequ/constraints/AnalysisBasedConstraint.scala b/src/main/scala/com/amazon/deequ/constraints/AnalysisBasedConstraint.scala index e1a530c97..6314e1a5a 100644 --- a/src/main/scala/com/amazon/deequ/constraints/AnalysisBasedConstraint.scala +++ b/src/main/scala/com/amazon/deequ/constraints/AnalysisBasedConstraint.scala @@ -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") diff --git a/src/test/scala/com/amazon/deequ/VerificationResultTest.scala b/src/test/scala/com/amazon/deequ/VerificationResultTest.scala index 43c51e759..a390f47fb 100644 --- a/src/test/scala/com/amazon/deequ/VerificationResultTest.scala +++ b/src/test/scala/com/amazon/deequ/VerificationResultTest.scala @@ -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", "DistinctnessConstraint(Distinctness(List(item),None))", "Failure", "Value: 1.0 does not meet the constraint requirement! " + @@ -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", @@ -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))", diff --git a/src/test/scala/com/amazon/deequ/constraints/AnalysisBasedConstraintTest.scala b/src/test/scala/com/amazon/deequ/constraints/AnalysisBasedConstraintTest.scala index b7657ef29..e5b29ee0c 100644 --- a/src/test/scala/com/amazon/deequ/constraints/AnalysisBasedConstraintTest.scala +++ b/src/test/scala/com/amazon/deequ/constraints/AnalysisBasedConstraintTest.scala @@ -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 From e67d93b8c04a19e838d77da90cc75644cd1fa6bb Mon Sep 17 00:00:00 2001 From: Andreas Lang Date: Thu, 11 Nov 2021 14:38:17 +0000 Subject: [PATCH 2/2] Change constraint success message to be easier to distinguish from error message as discussed in PR. --- .../deequ/constraints/AnalysisBasedConstraint.scala | 2 +- .../scala/com/amazon/deequ/VerificationResultTest.scala | 8 ++++---- .../deequ/constraints/AnalysisBasedConstraintTest.scala | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/scala/com/amazon/deequ/constraints/AnalysisBasedConstraint.scala b/src/main/scala/com/amazon/deequ/constraints/AnalysisBasedConstraint.scala index 6314e1a5a..02f7145ac 100644 --- a/src/main/scala/com/amazon/deequ/constraints/AnalysisBasedConstraint.scala +++ b/src/main/scala/com/amazon/deequ/constraints/AnalysisBasedConstraint.scala @@ -74,7 +74,7 @@ private[deequ] case class AnalysisBasedConstraint[S <: State[S], M, V]( val assertionOk = runAssertion(assertOn) if (assertionOk) { - var successMessage = s"Value: $assertOn does meet the constraint requirement!" + var successMessage = s"Value: $assertOn meets the constraint requirement." hint.foreach(hint => successMessage += s" $hint") ConstraintResult(this, ConstraintStatus.Success, Some(successMessage), Some(metric)) diff --git a/src/test/scala/com/amazon/deequ/VerificationResultTest.scala b/src/test/scala/com/amazon/deequ/VerificationResultTest.scala index a390f47fb..595c9035f 100644 --- a/src/test/scala/com/amazon/deequ/VerificationResultTest.scala +++ b/src/test/scala/com/amazon/deequ/VerificationResultTest.scala @@ -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", "Value: 1.0 does meet the constraint requirement!"), + "Success", "Value: 1.0 meets 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", "Value: 1.0 does meet the constraint requirement! Should equal 1!"), + "Success", "Value: 1.0 meets the constraint requirement. Should equal 1!"), ("group-2-W", "Warning", "Warning", "DistinctnessConstraint(Distinctness(List(item),None))", "Failure", "Value: 1.0 does not meet the constraint requirement! " + @@ -152,7 +152,7 @@ class VerificationResultTest extends WordSpec with Matchers with SparkContextSpe """[{"check":"group-1","check_level":"Error","check_status":"Success", |"constraint":"CompletenessConstraint(Completeness(att1,None))", |"constraint_status":"Success", - |"constraint_message":"Value: 1.0 does meet the constraint requirement!"}, + |"constraint_message":"Value: 1.0 meets the constraint requirement."}, | |{"check":"group-2-E","check_level":"Error","check_status":"Error", |"constraint":"SizeConstraint(Size(None))", "constraint_status":"Failure", @@ -162,7 +162,7 @@ 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":"Value: 1.0 does meet the constraint requirement! + |"constraint_message":"Value: 1.0 meets the constraint requirement. | Should equal 1!"}, | |{"check":"group-2-W","check_level":"Warning","check_status":"Warning", diff --git a/src/test/scala/com/amazon/deequ/constraints/AnalysisBasedConstraintTest.scala b/src/test/scala/com/amazon/deequ/constraints/AnalysisBasedConstraintTest.scala index e5b29ee0c..c3dad91cb 100644 --- a/src/test/scala/com/amazon/deequ/constraints/AnalysisBasedConstraintTest.scala +++ b/src/test/scala/com/amazon/deequ/constraints/AnalysisBasedConstraintTest.scala @@ -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.contains("Value: 1.0 does meet the constraint requirement!")) + assert(resultA.message.contains("Value: 1.0 meets the constraint requirement.")) assert(resultA.metric.isDefined) // Analysis result should equal to 1.0 for an existing column