How to call Amazon Deequ hasDataType from java

589 Views Asked by At

I am trying to implement Amazon Deequ functionality from Java.

I am trying to add datatype constains but not able to pass 3rd parameter (assertion) from java

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

Method declation in scala is as below

 * @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 = {
1

There are 1 best solutions below

2
On

From Java you should be able to call dataTypeConstraint by implementing AbstractFunction1 and passing it as an argument:

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"));