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

[FEATURE] Filter condition is ignored when filtering records based on row-level checks #530

Open
eapframework opened this issue Jan 16, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@eapframework
Copy link

eapframework commented Jan 16, 2024

I tried the filtering data based on row-level checks and it is working fine. New column is added with true or false based on the row-level checks. But if rules has where filter condition, filter condition is ignored.

It is marking all the records as false ignoring the filter applied to the rule. Is it possible to extract bad records after applying where filter in row-level checks.

@eapframework eapframework added the enhancement New feature or request label Jan 16, 2024
@eycho-am
Copy link
Contributor

Hi @eapframework, thank you for raising this issue. Could you provide an example of the behavior you're seeing and the behavior you expect/want instead?

We're actually looking into a similar issue - here's an example unit test using the Completeness analyzer:

For the dataframe:

  def getDfCompleteAndInCompleteColumns(sparkSession: SparkSession): DataFrame = {
    import sparkSession.implicits._

    Seq(
      ("1", "a", "f"),
      ("2", "b", "d"),
      ("3", "a", null),
      ("4", "a", "f"),
      ("5", "b", null),
      ("6", "a", "f")
    ).toDF("item", "att1", "att2")
  }

This test checks the row-level results

    "return row-level results for columns filtered" in withSparkSession { session =>

      val data = getDfCompleteAndInCompleteColumns(session)

      val completenessAtt2 = Completeness("att2", Option("att1 = \"a\""))
      val state = completenessAtt2.computeStateFrom(data)
      val metric: DoubleMetric with FullColumn = completenessAtt2.computeMetricFrom(state)

      data.withColumn("new", metric.fullColumn.get).collect().map(_.getAs[Boolean]("new")) shouldBe
        Seq(true, false, false, true, false, true)
    }

Using the verification suite on a similar test:

+----+----+----+-----+
|item|att1|att2|rule1|
+----+----+----+-----+
|   1|   a|   f| true|
|   2|   b|   d|false|
|   3|   a|null|false|
|   4|   a|   f| true|
|   5|   b|null|false|
|   6|   a|   f| true|
+----+----+----+-----+

Here we can see that the rows that EITHER are filtered out (rows 2,5 att1 is not a) or fail the check (row 3 is null) are marked as false.
Would you expect rows 2,5 to show true/None in this case?

@eapframework
Copy link
Author

eapframework commented Jan 17, 2024

Thanks for your response. This is the same issue I am facing.
I am expecting rows 2,5 to show true because those are not failed records

Expected result:

     +----+----+----+-----+
     |item|att1|att2|rule1|
     +----+----+----+-----+
     |   1|   a|   f| true|
     |   2|   b|   d| true|
     |   3|   a|null|false|
     |   4|   a|   f| true|
     |   5|   b|null| true|
     |   6|   a|   f| true|
     +----+----+----+-----+

@eycho-am
Copy link
Contributor

eycho-am commented Feb 6, 2024

Thanks for your feedback @eapframework,

We're working through different use cases for different users and I'm planning a PR for this soon. We're planning on providing a configuration so users can set filtered rules as Null or True - so setting this configuration to True should meet your use-case. I'll tag you on the PR once we have that out as well.

@eycho-am
Copy link
Contributor

Hi @eapframework, we've merged PR #532 addressing this issue for Uniqueness and Completeness analyzers and another one open for other analyzers: #535

Please let us know if you have any feedback on these PRs and add comments or open a PR if this doesn't quite meet your use-case.

@eapframework
Copy link
Author

eapframework commented Apr 9, 2024

Hi @eycho-am , Thanks for merging the PR to address the use-case. Sorry for the delayed response.
It is working fine except when values are null in the column.

For example:

  1. Rule: containsCreditCardNumber("credit_no", _ == 1.0).where("indicator == 'b'")
    Values:
    credit_no             indicator
4012888888881881          null     

For above values, status is marked as false but expected true

  1. hasPattern("account_no", "[0-9]{7}".r).where("indicator == 'b'")
    Values:
account_no               indicator
1288888                    null    

For above values, status is marked as false but expected true

  1. hasCompleteness("num_hist", _ => 0.8).where("indicator == 'b'")
    Values:
 num_hist              indicator
 18                          null 

For above values, status is marked as blank but expected true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants