scala—如何检查datetype列的值是否在指定日期的范围内?

ctrmrzij  于 2021-07-09  发布在  Spark
关注(0)|答案(1)|浏览(356)

所以,我在spark中使用amazon deequ,我有一个Dataframe df 有一列 publish_date 哪种类型的 DateType . 我只想检查一下:

publish_date <= current_date(minus)x AND publish_date >= current_date(minus)y

哪里 x 以及 y 是整数。
我不知道在这里放什么支票:

val verificationResult: VerificationResult = { VerificationSuite()
      .onData(df)
      .addCheck(
        Check(CheckLevel.Error, "Review Check")
          //function to check this
      )
      .run()
}
w8rqjzmb

w8rqjzmb1#

可以使用以下spark sql表达式:

publish_date <= date_sub(current_date(), x) AND publish_date >= date_sub(current_date(), y)

用check的方法:

val verificationResult: VerificationResult = { VerificationSuite()
      .onData(df)
      .addCheck(
        Check(CheckLevel.Error, "Review Check")
          .satisfies(
            s"publish_date <= date_sub(current_date(), $x) AND publish_date >= date_sub(current_date(), $y)",
            "check constraint name/description"
        )
      )
      .run()
}

或使用 between :

publish_date between date_sub(current_date(), y) and date_sub(current_date(), x)

相关问题