【问题标题】:How to check if values of a DateType column are within a range of specified dates?如何检查 DateType 列的值是否在指定日期范围内?
【发布时间】:2021-03-22 09:38:32
【问题描述】:

所以,我在 Spark 中使用 Amazon Deequ,我有一个数据框 df,其中有一列 publish_date,其类型为 DateType。我只是想检查以下内容:

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

其中xy 是整数。

我不知道在这里放什么支票:

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

【问题讨论】:

    标签: scala dataframe apache-spark amazon-deequ


    【解决方案1】:

    您可以使用这个 Spark SQL 表达式:

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

    使用 Check 的satisfies 方法:

    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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-01
      • 1970-01-01
      • 2017-01-28
      • 2019-07-07
      • 1970-01-01
      • 2010-10-04
      • 1970-01-01
      相关资源
      最近更新 更多