pentaho/pentaho-kettle · error · KettleValueException

Function ABS only works with a number

Error message

Function ABS only works with a number

What it means

This KettleValueException is thrown by Value.abs() when the value's type is not BigNumber, Number, or Integer — e.g. String, Boolean, or Date. The ABS function implementation only handles those three numeric types and rejects everything else explicitly.

Solutions

  1. Convert the value to a numeric type first: convertString( VALUE_TYPE_NUMBER ) or setType with the appropriate numeric type.
  2. Add a Calculator/Select Values step to set the field type to Number/Integer before applying ABS.
  3. Validate the field's ValueMetaInterface type before applying the function and skip or convert non-numeric rows.
  4. If abs on a string representation is needed, parse to BigDecimal then apply abs.
  5. Catch KettleValueException and include the value's current type and content in the error report.

Example fix

// before
Value absVal = strAmount.abs(); // throws: STRING
// after
strAmount.convertString( Value.VALUE_TYPE_BIGNUMBER );
Value absVal = strAmount.abs();
Defensive patterns

Strategy: type-guard

Validate before calling

// before abs
if ( !( v.isNumber() || v.isInteger() || v.isBigNumber() ) ) {
  v.convertString( Value.VALUE_TYPE_NUMBER );
}

Type guard

boolean absCapable( Value v ) {
  return v != null && ( v.isNumber() || v.isInteger() || v.isBigNumber() );
}

Try / catch

try {
  Value absVal = v.abs();
} catch ( KettleValueException e ) {
  throw new IllegalStateException( "ABS applied to non-numeric value of type " + v.getType(), e );
}

Prevention

When it happens

Trigger: Calling value.abs() (or the ABS formula/calculator function) on a Value whose VALUE_TYPE is STRING, BOOLEAN, DATE, etc. — typically a numeric-looking string field passed directly to ABS.

Common situations: CSV/text inputs typed as String; a calculated boolean fed into ABS; a Select Values step missing type conversion; metadata changes after upstream refactoring.

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/a5cc7cbe4b7aab49. Report an issue: GitHub.

Appendix: source

Thrown at core/src/main/java/org/pentaho/di/compatibility/Value.java:2368

    return this;
  }

  // FUNCTIONS!!

  // implement the ABS function, arguments in args[]
  public Value abs() throws KettleValueException {
    if ( isNull() ) {
      return this;
    }

    if ( isBigNumber() ) {
      setValue( getBigNumber().abs() );
    } else if ( isNumber() ) {
      setValue( Math.abs( getNumber() ) );
    } else if ( isInteger() ) {
      setValue( Math.abs( getInteger() ) );
    } else {
      throw new KettleValueException( "Function ABS only works with a number" );
    }
    return this;
  }

  // implement the ACOS function, arguments in args[]
  public Value acos() throws KettleValueException {
    if ( isNull() ) {
      return this;
    }

    if ( isNumeric() ) {
      setValue( Math.acos( getNumber() ) );
    } else {
      throw new KettleValueException( "Function ACOS only works with numeric data" );
    }
    return this;
  }

View on GitHub (pinned to f3058517a1)