pentaho/pentaho-kettle · error · KettleValueException

Function FLOOR only works with a number

Error message

Function FLOOR only works with a number

What it means

The floor() method of Kettle's legacy Value class rounds the value down using Math.floor. It throws this KettleValueException when the Value is not numeric, because Math.floor requires a double. The legacy compatibility Value class validates operand type at runtime for each math function.

Solutions

  1. Convert the Value to Number before calling floor() (setType(VALUE_TYPE_NUMBER) or a Select values type conversion)
  2. Fix the source step so the field is numeric end to end
  3. Guard with isNumeric() and convert or branch explicitly

Example fix

// before
Value rounded = value.floor(); // value is a String
// after
if (!value.isNumeric()) {
  value.setType(Value.VALUE_TYPE_NUMBER);
}
Value rounded = value.floor();
Defensive patterns

Strategy: type-guard

Validate before calling

if (value == null || !value.isNumeric()) {
  throw new IllegalArgumentException("FLOOR requires a numeric value, got type " + (value == null ? "null" : value.getType()));
}

Type guard

boolean isNumericValue(Value v) { return v != null && v.isNumeric(); }

Try / catch

try {
  result = value.floor();
} catch (KettleValueException e) {
  value.setType(Value.VALUE_TYPE_NUMBER);
  result = value.floor();
}

Prevention

When it happens

Trigger: Calling Value.floor() on a Value typed as String, Date or Boolean - e.g. flooring a value taken from a text column without conversion.

Common situations: Integer partitioning of String-typed measurements from CSV/Excel; Boolean fields accidentally routed into numeric rounding logic.

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

Appendix: source

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

    if ( isNumeric() ) {
      setValue( Math.exp( getNumber() ) );
    } else {
      throw new KettleValueException( "Function EXP only works with a number" );
    }
    return this;
  }

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

    if ( isNumeric() ) {
      setValue( Math.floor( getNumber() ) );
    } else {
      throw new KettleValueException( "Function FLOOR only works with a number" );
    }
    return this;
  }

  // implement the INITCAP function, arguments in args[]
  public Value initcap() {
    if ( isNull() ) {
      return this;
    }

    if ( getString() == null ) {
      setNull();
    } else {
      setValue( Const.initCap( getString() ) );
    }
    return this;
  }

View on GitHub (pinned to f3058517a1)