pentaho/pentaho-kettle · error · KettleValueException

The 'abs' function only works on numeric data

Error message

The 'abs' function only works on numeric data

What it means

Guard in ValueDataUtil.abs(): the input data is non-null but its ValueMeta type is none of Number, Integer or BigNumber, so absolute-value computation is refused. The input at fault is dataA whose metadata type is a non-numeric type (String, Date, Boolean, etc.).

Solutions

  1. Type the field as numeric before the Calculator step (Select Values metadata).
  2. Add a string-to-number conversion step for the signed value.
  3. Validate the field type in a UDJC step before calling abs.

Example fix

// before: ABS(fieldS:String = "-5") -> throws
// after: convert fieldS to Number; ABS(fieldS) -> 5
Defensive patterns

Strategy: type-guard

Validate before calling

int t = metaA.getType();
if (t != ValueMetaInterface.TYPE_NUMBER && t != ValueMetaInterface.TYPE_INTEGER && t != ValueMetaInterface.TYPE_BIGNUMBER) {
  throw new KettleValueException("abs(A) requires numeric field, got type " + t);
}

Type guard

public static boolean isNumericMeta(ValueMetaInterface m) {
  int t = m.getType();
  return t == ValueMetaInterface.TYPE_NUMBER || t == ValueMetaInterface.TYPE_INTEGER || t == ValueMetaInterface.TYPE_BIGNUMBER;
}

Try / catch

try {
  a = ValueDataUtil.abs(metaA, dataA);
} catch (KettleValueException e) {
  logError("abs on non-numeric field: " + e.getMessage());
  a = null;
}

Prevention

When it happens

Trigger: Calling ValueDataUtil.abs(metaA, dataA) (Calculator 'ABS( A )') where metaA.getType() is not TYPE_NUMBER, TYPE_INTEGER, or TYPE_BIGNUMBER — e.g. a negative number stored as String "-5".

Common situations: ABS applied to string deltas from log parsing; ABS on a boolean or date field by mistake; source system exports numbers as strings.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13). Data as JSON: /api/errors/5ac77c3b5414b610. Report an issue: GitHub.

Appendix: source

Thrown at core/src/main/java/org/pentaho/di/core/row/ValueDataUtil.java:1385

        throw new KettleValueException( "The 'floor' function only works on numeric data" );
    }
  }

  public static Object abs( ValueMetaInterface metaA, Object dataA ) throws KettleValueException {
    if ( dataA == null ) {
      return null;
    }

    switch ( metaA.getType() ) {
      case ValueMetaInterface.TYPE_NUMBER:
        return new Double( Math.abs( metaA.getNumber( dataA ).doubleValue() ) );
      case ValueMetaInterface.TYPE_INTEGER:
        return metaA.getInteger( Math.abs( metaA.getNumber( dataA ).longValue() ) );
      case ValueMetaInterface.TYPE_BIGNUMBER:
        return metaA.getBigNumber( dataA ).abs();

      default:
        throw new KettleValueException( "The 'abs' function only works on numeric data" );
    }
  }

  /**
   * Returns the remainder (modulus) of A / B.
   *
   * @param metaA
   * @param dataA
   *          The dividend
   * @param metaB
   * @param dataB
   *          The divisor
   * @return The remainder
   * @throws KettleValueException
   */
  public static Object remainder( ValueMetaInterface metaA, Object dataA, ValueMetaInterface metaB, Object dataB ) throws KettleValueException {
    if ( dataA == null || dataB == null ) {
      return null;

View on GitHub (pinned to f3058517a1)