Skip to content

Commit 851c44b

Browse files
committed
Fix getMap(offset) scan-sharing bug
add null-input NPE guard removed bogus MONTHLY interval changenow() to current_timestamp() Styling changes
1 parent 2d1e50c commit 851c44b

7 files changed

Lines changed: 16 additions & 12 deletions

File tree

src/main/scala/com/amazon/deequ/analyzers/Analyzer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ object Preconditions {
443443
}
444444
}
445445

446-
/** Specified column has string type */
446+
/** Specified column has a date or timestamp type */
447447
def isDateType(column: String): StructType => Unit = { schema =>
448448
val columnDataType = structField(column, schema).dataType
449449
val hasDateType = columnDataType match {

src/main/scala/com/amazon/deequ/analyzers/DateTimeDistribution.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import org.apache.spark.sql.{Column, Row}
2828
import scala.util.{Failure, Success}
2929

3030
object DistributionInterval extends Enumeration {
31-
val QUARTER_HOUR, HOURLY, DAILY, WEEKLY, MONTHLY = Value
31+
val QUARTER_HOUR, HOURLY, DAILY, WEEKLY = Value
3232
}
3333

3434
case class DateTimeDistributionState(distribution: Map[(Instant, Instant), Long])
@@ -90,7 +90,7 @@ case class DateTimeDistribution(
9090
ifNoNullsIn(result, offset) { _ =>
9191
DateTimeDistributionState(
9292
DateTimeDistributionState.computeStateFromResult(
93-
Map.empty[Long, Long] ++ result.getMap(0),
93+
Map.empty[Long, Long] ++ result.getMap(offset),
9494
interval
9595
)
9696
)

src/main/scala/com/amazon/deequ/analyzers/catalyst/DateTimeAggregation.scala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,13 @@ private[sql] class DateTimeAggregation(
2828
override def zero: Map[Long, Long] = Map.empty[Long, Long]
2929

3030
override def reduce(agg: Map[Long, Long], input: Instant): Map[Long, Long] = {
31-
val dateTime = input.toEpochMilli
32-
val batchTime = dateTime - (dateTime % frequency)
33-
agg + (batchTime -> (agg.getOrElse(batchTime, 0L) + 1L))
31+
if (input == null) {
32+
agg
33+
} else {
34+
val dateTime = input.toEpochMilli
35+
val batchTime = dateTime - (dateTime % frequency)
36+
agg + (batchTime -> (agg.getOrElse(batchTime, 0L) + 1L))
37+
}
3438
}
3539

3640
override def merge(b1: Map[Long, Long], b2: Map[Long, Long]): Map[Long, Long] = {
@@ -46,4 +50,4 @@ private[sql] class DateTimeAggregation(
4650

4751
// Define encoder for output
4852
def outputEncoder: Encoder[Map[Long, Long]] = ExpressionEncoder()
49-
}
53+
}

src/main/scala/com/amazon/deequ/checks/Check.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,7 @@ case class Check(
15161516
column: String,
15171517
assertion: Double => Boolean = Check.IsOne,
15181518
hint: Option[String] = None)
1519-
: CheckWithLastConstraintFilterable = satisfies(s"$column < now()",
1519+
: CheckWithLastConstraintFilterable = satisfies(s"$column < current_timestamp()",
15201520
s"$column has all past dates", assertion,
15211521
hint = hint)
15221522

@@ -1534,7 +1534,7 @@ case class Check(
15341534
column: String,
15351535
assertion: Double => Boolean = Check.IsOne,
15361536
hint: Option[String] = None)
1537-
: CheckWithLastConstraintFilterable = satisfies(s"$column > now()",
1537+
: CheckWithLastConstraintFilterable = satisfies(s"$column > current_timestamp()",
15381538
s"$column has all future dates", assertion,
15391539
hint = hint)
15401540

src/main/scala/com/amazon/deequ/examples/DateTimeMetricExample.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ private[examples] object DateTimeMetricExample extends App {
3131
Customer(3, "Thomas Yu", Instant.parse("2023-02-11T08:15:00Z")),
3232
Customer(4, "Steve Powell", Instant.parse("2019-04-11T12:15:00Z")),
3333
Customer(5, "Andrej Kar", Instant.parse("2020-08-11T12:30:00Z")),
34-
Customer(6, "Ji Sung", Instant.parse("2020-08-11T12:30:00Z")),
34+
Customer(6, "Ji Sung", Instant.parse("2020-08-11T12:30:00Z"))
3535
)
3636

3737
val analysisResult: AnalyzerContext = { AnalysisRunner

src/test/scala/com/amazon/deequ/analyzers/AnalyzerTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ class AnalyzerTests extends AnyWordSpec with Matchers with SparkContextSpec with
545545

546546
"success for DateType column" in withSparkSessionJava8APIEnabled { sparkSession =>
547547
val df = getDfWithLocalDateAndInstant(sparkSession)
548-
assert(DateTimeDistribution("signupDate", DistributionInterval.MONTHLY).calculate(df).value.isSuccess)
548+
assert(DateTimeDistribution("signupDate", DistributionInterval.WEEKLY).calculate(df).value.isSuccess)
549549
}
550550

551551
"success for Timestamp column" in withSparkSessionJava8APIEnabled { sparkSession =>

src/test/scala/com/amazon/deequ/utils/FixtureSupport.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ trait FixtureSupport {
155155
(2, "marry jane", Instant.parse("2021-11-11T08:15:00Z"), LocalDate.of(2017, 10, 14)),
156156
(3, "Thomas Yu", Instant.parse("2021-11-11T09:15:00Z"), LocalDate.of(2017, 10, 14)),
157157
(4, "Steve Powell", Instant.parse("2019-04-11T12:15:00Z"), LocalDate.of(2017, 11, 14)),
158-
(5, "Andrej Kar", Instant.parse("2019-04-11T13:15:00Z"), LocalDate.of(2017, 11, 14)),
158+
(5, "Andrej Kar", Instant.parse("2019-04-11T13:15:00Z"), LocalDate.of(2017, 11, 14))
159159
).toDF("id", "name", "dateOfBirth", "signupDate")
160160
}
161161

0 commit comments

Comments
 (0)