pentaho/pentaho-kettle · error · KettleValueException

Function SQRT only works with a number

Error message

Function SQRT only works with a number

What it means

Thrown by Value.sqrt() when the value is not numeric. SQRT computes Math.sqrt(getNumber()) after the isNumeric() check; any non-numeric type raises KettleValueException. Null values are returned unchanged before the check.

Solutions

  1. Check value.isNumeric() before calling sqrt().
  2. Convert the field to a numeric type upstream (input step metadata or StringToNumber).
  3. Note negative numbers do not throw here but yield NaN — validate sign separately if that matters.
  4. Catch KettleValueException for non-numeric rows.

Example fix

// before
Value r = value.sqrt(); // throws for String-typed value
// after
Value r = value.isNumeric() ? value.sqrt() : null; // or convert first
Defensive patterns

Strategy: type-guard

Validate before calling

if (!value.isNumeric()) { throw new IllegalArgumentException("SQRT requires a numeric value"); }

Type guard

boolean sqrtSafe(Value v) { return v != null && v.isNumeric() && (v.isNull() || v.getNumber() >= 0); }

Try / catch

try { result = value.sqrt(); } catch (KettleValueException e) { result = null; }

Prevention

When it happens

Trigger: Calling value.sqrt() on a String, Date, Boolean, or Binary typed Value.

Common situations: Square root of a string-typed measurement column; metadata drift after schema changes; applying SQRT to parsed-from-text data that never got converted.

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

Appendix: source

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

    }
    if ( isNumeric() ) {
      setValue( Math.sin( getNumber() ) );
    } else {
      throw new KettleValueException( "Function SIN only works with a number" );
    }

    return this;
  }

  // implement the SQRT function, arguments in args[]
  public Value sqrt() throws KettleValueException {
    if ( isNull() ) {
      return this;
    }
    if ( isNumeric() ) {
      setValue( Math.sqrt( getNumber() ) );
    } else {
      throw new KettleValueException( "Function SQRT only works with a number" );
    }

    return this;
  }

  // implement the SUBSTR function, arguments in args[]
  public Value substr( Value from, Value to ) {
    return substr( (int) from.getNumber(), (int) to.getNumber() );
  }

  public Value substr( Value from ) {
    return substr( (int) from.getNumber(), -1 );
  }

  public Value substr( int from ) {
    return substr( from, -1 );
  }

View on GitHub (pinned to f3058517a1)