pentaho/pentaho-kettle · error · KettleValueException

The 'round' function only works on numeric data

Error message

The 'round' function only works on numeric data

What it means

The single-argument round helper rounds a value to 0 decimal places using the default rounding method, handling only Number, Integer, and BigNumber types. A non-numeric metadata type falls to the default branch and throws this KettleValueException.

Solutions

  1. Type the field as Number/Integer/BigNumber before the Calculator step (Select Values metadata tab).
  2. Add an explicit string-to-number conversion step before rounding.
  3. Null-check/type-check inputs in a UDJC step before calling round.

Example fix

// before: Round(fieldX) where fieldX is String
// after: Select Values: fieldX Type=Number, then Round(fieldX)
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("round(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 {
  rounded = ValueDataUtil.round(metaA, dataA);
} catch (KettleValueException e) {
  logError("round() on non-numeric field: " + e.getMessage());
  rounded = null;
}

Prevention

When it happens

Trigger: Calling ValueDataUtil.round(metaA, dataA) (Calculator 'Round( A )') when metaA.getType() is not TYPE_NUMBER, TYPE_INTEGER, or TYPE_BIGNUMBER — e.g. a String or Date field.

Common situations: Rounding a field that was read from a delimited file as String; a prior type conversion changed Number to String; passing a Boolean flag field into Round by mistake.

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

Appendix: source

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

   *          Value to round
   * @return The rounded value
   * @throws KettleValueException
   */
  public static Object round( ValueMetaInterface metaA, Object dataA ) throws KettleValueException {
    if ( dataA == null ) {
      return null;
    }

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

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

  /**
   * Rounding with no decimal places with a given rounding method
   *
   * @param metaA
   *          Metadata of value to round
   * @param dataA
   *          Value to round
   * @param roundingMode
   *          The mode for rounding, e.g. java.math.BigDecimal.ROUND_HALF_EVEN
   * @return The rounded value
   * @throws KettleValueException
   */
  public static Object round( ValueMetaInterface metaA, Object dataA, int roundingMode ) throws KettleValueException {
    if ( dataA == null ) {
      return null;

View on GitHub (pinned to f3058517a1)