-
Notifications
You must be signed in to change notification settings - Fork 542
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add commits from master branch to release/2.0.8-spark-3.3 (#589)
* Configurable RetainCompletenessRule (#564) * Configurable RetainCompletenessRule * Add doc string * Add default completeness const * Optional specification of instance name in CustomSQL analyzer metric. (#569) Co-authored-by: Tyler Mcdaniel <[email protected]> * Adding Wilson Score Confidence Interval Strategy (#567) * Configurable RetainCompletenessRule * Add doc string * Add default completeness const * Add ConfidenceIntervalStrategy * Add Separate Wilson and Wald Interval Test * Add License information, Fix formatting * Add License information * formatting fix * Update documentation * Make WaldInterval the default strategy for now * Formatting import to per line * Separate group import to per line import * CustomAggregator (#572) * Add support for EntityTypes dqdl rule * Add support for Conditional Aggregation Analyzer --------- Co-authored-by: Joshua Zexter <[email protected]> * fix typo (#574) * Fix performance of building row-level results (#577) * Generate row-level results with withColumns Iteratively using withColumn (singular) causes performance issues when iterating over a large sequence of columns. * Add back UNIQUENESS_ID * Replace 'withColumns' with 'select' (#582) 'withColumns' was introduced in Spark 3.3, so it won't work for Deequ's <3.3 builds. * Replace rdd with dataframe functions in Histogram analyzer (#586) Co-authored-by: Shriya Vanvari <[email protected]> * Match Breeze version with spark 3.3 (#562) * Updated version in pom.xml to 2.0.8-spark-3.3 --------- Co-authored-by: zeotuan <[email protected]> Co-authored-by: tylermcdaniel0 <[email protected]> Co-authored-by: Tyler Mcdaniel <[email protected]> Co-authored-by: Joshua Zexter <[email protected]> Co-authored-by: Joshua Zexter <[email protected]> Co-authored-by: bojackli <[email protected]> Co-authored-by: Josh <[email protected]> Co-authored-by: Shriya Vanvari <[email protected]> Co-authored-by: Shriya Vanvari <[email protected]>
- Loading branch information
1 parent
ed5a164
commit e033c2b
Showing
18 changed files
with
709 additions
and
63 deletions.
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
69 changes: 69 additions & 0 deletions
69
src/main/scala/com/amazon/deequ/analyzers/CustomAggregator.scala
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"). You may not | ||
* use this file except in compliance with the License. A copy of the License | ||
* is located at | ||
* | ||
* http://aws.amazon.com/apache2.0/ | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
* | ||
*/ | ||
package com.amazon.deequ.analyzers | ||
|
||
import com.amazon.deequ.metrics.AttributeDoubleMetric | ||
import com.amazon.deequ.metrics.Entity | ||
import org.apache.spark.sql.DataFrame | ||
|
||
import scala.util.Failure | ||
import scala.util.Success | ||
import scala.util.Try | ||
|
||
// Define a custom state to hold aggregation results | ||
case class AggregatedMetricState(counts: Map[String, Int], total: Int) | ||
extends DoubleValuedState[AggregatedMetricState] { | ||
|
||
override def sum(other: AggregatedMetricState): AggregatedMetricState = { | ||
val combinedCounts = counts ++ other | ||
.counts | ||
.map { case (k, v) => k -> (v + counts.getOrElse(k, 0)) } | ||
AggregatedMetricState(combinedCounts, total + other.total) | ||
} | ||
|
||
override def metricValue(): Double = counts.values.sum.toDouble / total | ||
} | ||
|
||
// Define the analyzer | ||
case class CustomAggregator(aggregatorFunc: DataFrame => AggregatedMetricState, | ||
metricName: String, | ||
instance: String = "Dataset") | ||
extends Analyzer[AggregatedMetricState, AttributeDoubleMetric] { | ||
|
||
override def computeStateFrom(data: DataFrame, filterCondition: Option[String] = None) | ||
: Option[AggregatedMetricState] = { | ||
Try(aggregatorFunc(data)) match { | ||
case Success(state) => Some(state) | ||
case Failure(_) => None | ||
} | ||
} | ||
|
||
override def computeMetricFrom(state: Option[AggregatedMetricState]): AttributeDoubleMetric = { | ||
state match { | ||
case Some(detState) => | ||
val metrics = detState.counts.map { case (key, count) => | ||
key -> (count.toDouble / detState.total) | ||
} | ||
AttributeDoubleMetric(Entity.Column, metricName, instance, Success(metrics)) | ||
case None => | ||
AttributeDoubleMetric(Entity.Column, metricName, instance, | ||
Failure(new RuntimeException("Metric computation failed"))) | ||
} | ||
} | ||
|
||
override private[deequ] def toFailureMetric(failure: Exception): AttributeDoubleMetric = { | ||
AttributeDoubleMetric(Entity.Column, metricName, instance, Failure(failure)) | ||
} | ||
} |
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
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.