0

我正在尝试从 Java 实现 Amazon Deequ 功能。

我正在尝试添加数据类型包含但无法从 java 传递第三个参数(断言)

 com.amazon.deequ.constraints.Constraint constrains = Constraint.dataTypeConstraint("test", ConstrainableDataTypes.Numeric(), ?,x);

scala中的方法声明如下

 * @param column Column to compute the data type distribution for.
    * @param dataType The data type that should be checked in the assertion.
    * @param assertion Function from the ratio of the data type in the specified column to boolean.
    * @param hint A hint to provide additional context why a constraint could have failed
    * @return
    */
  def dataTypeConstraint(
      column: String,
      dataType: ConstrainableDataTypes.Value,
      assertion: Double => Boolean,
      hint: Option[String] = None)
    : Constraint = {
4

1 回答 1

0

从 Java 中,您应该能够dataTypeConstraint通过实现AbstractFunction1并将其作为参数传递来调用:

scala.Function1<Double, Boolean> function = new scala.runtime.AbstractFunction1<Double, Boolean>() {
    public Boolean apply(Double value) {
        // implement the actual assertion here
        return value >= 0;
    }
};

Constraint.dataTypeConstraint("column", dataType, function, scala.Option.apply("a hint"));
于 2020-04-06T07:45:44.983 回答