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

Column Count Analyzer and Check #555

Merged
merged 4 commits into from
Apr 15, 2024
Merged

Conversation

mentekid
Copy link
Contributor

  • Fix flaky KLL test
  • Move CustomSql state to CustomSql analyzer
  • Implement new Analyzer to count columns

Issue #, if available:

Description of changes:

This adds a dataset-scope analyzer that counts the number of columns in a dataset, and uses the analyzer in a Deequ Check

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

import com.amazon.deequ.metrics.Entity
import org.apache.spark.sql.DataFrame

case class ColumnCount(where: Option[String] = None) extends Analyzer[NumMatches, DoubleMetric] {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we remove where ? Or is that a requirement from Analyzer ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

Comment on lines 53 to 57
if (state.isDefined) {
Analyzers.metricFromValue(state.get.metricValue(), name, instance, entity)
} else {
Analyzers.metricFromEmpty(this, name, instance, entity)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

How about:

val metricValue = if(state.isDefined) state.get.metricValue() else this
Analyzers.metricFromEmpty(metricValue, name, instance, entity)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's Analyzers.metricFromValue if defined and Analyzers.metricFromEmpty otherwise so this won't work. I'll do a map though.

@@ -26,6 +26,17 @@ import scala.util.Failure
import scala.util.Success
import scala.util.Try

case class CustomSqlState(stateOrError: Either[Double, String]) extends DoubleValuedState[CustomSqlState] {
Copy link
Contributor

Choose a reason for hiding this comment

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

Either is right biased in Scala, which means the right sided value is what you would operate on when doing map or flatMap. In the case of storing exceptions or error messages, usually they are stored as the left sided value of the Either.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm just moving this from Size.scala to its own class, I can address that in a different PR

Copy link

@shriyavanvari shriyavanvari left a comment

Choose a reason for hiding this comment

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

LGTM

@mentekid mentekid merged commit b4d0f2c into master Apr 15, 2024
1 check passed
rdsharma26 pushed a commit that referenced this pull request Apr 16, 2024
* Fix flaky KLL test

* Move CustomSql state to CustomSql analyzer

* Implement new Analyzer to count columns

* Improve documentation, remove unused parameter, replace if/else with map

---------

Co-authored-by: Yannis Mentekidis <mentekid@amazon.com>
rdsharma26 pushed a commit that referenced this pull request Apr 16, 2024
* Fix flaky KLL test

* Move CustomSql state to CustomSql analyzer

* Implement new Analyzer to count columns

* Improve documentation, remove unused parameter, replace if/else with map

---------

Co-authored-by: Yannis Mentekidis <mentekid@amazon.com>
rdsharma26 pushed a commit that referenced this pull request Apr 16, 2024
* Fix flaky KLL test

* Move CustomSql state to CustomSql analyzer

* Implement new Analyzer to count columns

* Improve documentation, remove unused parameter, replace if/else with map

---------

Co-authored-by: Yannis Mentekidis <mentekid@amazon.com>
rdsharma26 pushed a commit that referenced this pull request Apr 17, 2024
* Fix flaky KLL test

* Move CustomSql state to CustomSql analyzer

* Implement new Analyzer to count columns

* Improve documentation, remove unused parameter, replace if/else with map

---------

Co-authored-by: Yannis Mentekidis <mentekid@amazon.com>
rdsharma26 pushed a commit that referenced this pull request Apr 17, 2024
* Fix flaky KLL test

* Move CustomSql state to CustomSql analyzer

* Implement new Analyzer to count columns

* Improve documentation, remove unused parameter, replace if/else with map

---------

Co-authored-by: Yannis Mentekidis <mentekid@amazon.com>
shriyavanvari pushed a commit that referenced this pull request May 2, 2024
* Fix flaky KLL test

* Move CustomSql state to CustomSql analyzer

* Implement new Analyzer to count columns

* Improve documentation, remove unused parameter, replace if/else with map

---------

Co-authored-by: Yannis Mentekidis <mentekid@amazon.com>
shriyavanvari pushed a commit that referenced this pull request May 2, 2024
* Fix flaky KLL test

* Move CustomSql state to CustomSql analyzer

* Implement new Analyzer to count columns

* Improve documentation, remove unused parameter, replace if/else with map

---------

Co-authored-by: Yannis Mentekidis <mentekid@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants