pentaho/pentaho-kettle · error · KettleValueException

Division can only be done with numeric data!

Error message

Division can only be done with numeric data!

What it means

This KettleValueException is thrown by Value.divide() when division is attempted with a non-numeric operand type (Boolean, String, or unhandled default). The compatibility Value class supports division only for Number, Integer, and BigNumber types and rejects all others explicitly to avoid silent misbehavior.

Solutions

  1. Convert both operands to numeric types before dividing (convertString( VALUE_TYPE_NUMBER ) or new Value with a numeric value).
  2. Add a Select Values step to force the field type to Number/Integer upstream of the division.
  3. Check the divisor for zero before dividing to also avoid infinite/NaN results.
  4. Validate ValueMetaInterface types in the step before performing the operation.
  5. Catch KettleValueException and report the offending field name and type to the user.

Example fix

// before
Value ratio = countValue.divide( strTotal ); // throws: strTotal is STRING
// after
strTotal.convertString( Value.VALUE_TYPE_BIGNUMBER );
Value ratio = countValue.divide( strTotal );
Defensive patterns

Strategy: type-guard

Validate before calling

// before division
if ( !( num.isNumber() || num.isInteger() || num.isBigNumber() ) ) num.convertString( Value.VALUE_TYPE_NUMBER );
if ( den.isBigNumber() && den.getBigNumber().signum() == 0 ) throw new ArithmeticException( "Divide by zero" );

Type guard

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

Try / catch

try {
  Value ratio = a.divide( b );
} catch ( KettleValueException e ) {
  throw new IllegalStateException( "Non-numeric operand for divide(): check field types", e );
}

Prevention

When it happens

Trigger: value.divide(other) where either operand is VALUE_TYPE_STRING, VALUE_TYPE_BOOLEAN, or another unsupported type — commonly a String field from parsed text used directly as a divisor, or a zero/invalid divisor path guarded only by type checks.

Common situations: CSV/Excel inputs inferred as String; calculator step receiving text fields; upstream steps changed a field's metadata type; forgot type conversion before division in a scripted mapping.

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

Appendix: source

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

  public Value divide( Value v ) throws KettleValueException {
    if ( isNull() || v.isNull() ) {
      setNull();
    } else {
      switch ( getType() ) {
        case VALUE_TYPE_BIGNUMBER:
          setValue( getBigNumber().divide( v.getBigNumber(), BigDecimal.ROUND_HALF_UP ) );
          break;
        case VALUE_TYPE_NUMBER:
          setValue( getNumber() / v.getNumber() );
          break;
        case VALUE_TYPE_INTEGER:
          setValue( getInteger() / v.getInteger() );
          break;
        case VALUE_TYPE_BOOLEAN:
        case VALUE_TYPE_STRING:
        default:
          throw new KettleValueException( "Division can only be done with numeric data!" );
      }
    }
    return this;
  }

  public Value multiply( BigDecimal v ) throws KettleValueException {
    return multiply( new Value( "tmp", v ) );
  }

  public Value multiply( double v ) throws KettleValueException {
    return multiply( new Value( "tmp", v ) );
  }

  public Value multiply( long v ) throws KettleValueException {
    return multiply( new Value( "tmp", v ) );
  }

  public Value multiply( int v ) throws KettleValueException {

View on GitHub (pinned to f3058517a1)