-
Notifications
You must be signed in to change notification settings - Fork 545
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: Add Row Level Result Treatment Options for Miminum and Maximum #535
Merged
eycho-am
merged 7 commits into
awslabs:master
from
eycho-am:feature/rowLevelFilterMinMax
Feb 21, 2024
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7f32da6
Address comments on PR #532
eycho-am 7bf9cdb
Add filtered row-level result support for Minimum and Maximum
eycho-am 0a55107
Add filtered row-level result support for Compliance
eycho-am 6a3665e
Add filtered row-level result support for PatternMatch
eycho-am d43b6ce
Add filtered row-level result support for MinLength and MaxLength
eycho-am b5f03b1
Refactored criterion for MinLength and MaxLength analyzers to separat…
eycho-am 13e25a0
Refactor and address comments for PR
eycho-am File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,14 +17,17 @@ | |
package com.amazon.deequ.analyzers | ||
|
||
import com.amazon.deequ.analyzers.Analyzers._ | ||
import com.amazon.deequ.analyzers.FilteredRowOutcome.FilteredRowOutcome | ||
import com.amazon.deequ.analyzers.NullBehavior.NullBehavior | ||
import com.amazon.deequ.analyzers.Preconditions.hasColumn | ||
import com.amazon.deequ.analyzers.Preconditions.isString | ||
import org.apache.spark.sql.Column | ||
import org.apache.spark.sql.Row | ||
import org.apache.spark.sql.functions.col | ||
import org.apache.spark.sql.functions.expr | ||
import org.apache.spark.sql.functions.length | ||
import org.apache.spark.sql.functions.max | ||
import org.apache.spark.sql.functions.not | ||
import org.apache.spark.sql.types.DoubleType | ||
import org.apache.spark.sql.types.StructType | ||
|
||
|
@@ -33,12 +36,12 @@ case class MaxLength(column: String, where: Option[String] = None, analyzerOptio | |
with FilterableAnalyzer { | ||
|
||
override def aggregationFunctions(): Seq[Column] = { | ||
max(criterion(getNullBehavior)) :: Nil | ||
max(criterion) :: Nil | ||
} | ||
|
||
override def fromAggregationResult(result: Row, offset: Int): Option[MaxState] = { | ||
ifNoNullsIn(result, offset) { _ => | ||
MaxState(result.getDouble(offset), Some(criterion(getNullBehavior))) | ||
MaxState(result.getDouble(offset), Some(rowLevelResults)) | ||
} | ||
} | ||
|
||
|
@@ -48,15 +51,35 @@ case class MaxLength(column: String, where: Option[String] = None, analyzerOptio | |
|
||
override def filterCondition: Option[String] = where | ||
|
||
private def criterion(nullBehavior: NullBehavior): Column = { | ||
val isNullCheck = col(column).isNull | ||
private[deequ] def criterion: Column = { | ||
transformColForNullBehavior(col(column), getNullBehavior) | ||
} | ||
|
||
private[deequ] def rowLevelResults: Column = { | ||
val filteredRowOutcome = getRowLevelFilterTreatment(analyzerOptions) | ||
transformColForFilteredRow(criterion, filteredRowOutcome) | ||
} | ||
|
||
private def transformColForFilteredRow(col: Column, rowOutcome: FilteredRowOutcome): Column = { | ||
val whereNotCondition = where.map { expression => not(expr(expression)) } | ||
rowOutcome match { | ||
case FilteredRowOutcome.TRUE => | ||
conditionSelectionGivenColumn(col, whereNotCondition, replaceWith = Double.MinValue) | ||
case _ => | ||
conditionSelectionGivenColumn(col, whereNotCondition, replaceWith = null) | ||
} | ||
} | ||
|
||
private def transformColForNullBehavior(col: Column, nullBehavior: NullBehavior): Column = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use |
||
val isNullCheck = col.isNull | ||
val colLengths: Column = length(conditionalSelection(column, where)).cast(DoubleType) | ||
nullBehavior match { | ||
case NullBehavior.Fail => | ||
val colLengths: Column = length(conditionalSelection(column, where)).cast(DoubleType) | ||
conditionSelectionGivenColumn(colLengths, Option(isNullCheck), replaceWith = Double.MaxValue) | ||
case NullBehavior.EmptyString => | ||
length(conditionSelectionGivenColumn(col(column), Option(isNullCheck), replaceWith = "")).cast(DoubleType) | ||
case _ => length(conditionalSelection(column, where)).cast(DoubleType) | ||
length(conditionSelectionGivenColumn(col, Option(isNullCheck), replaceWith = "")).cast(DoubleType) | ||
case _ => | ||
colLengths | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a comment here that we don't need special treatment for
Null
because that is the default behavior anyway when usingwhere