pentaho/pentaho-kettle · error · KettleValueException

Function SIN only works with a number

Error message

Function SIN only works with a number

What it means

Thrown by Value.sin() when the value is not numeric. SIN computes Math.sin(getNumber()) and the isNumeric() guard rejects String, Date, Boolean, and Binary values with KettleValueException. Nulls return early without error.

Solutions

  1. Guard with value.isNumeric() before calling sin().
  2. Convert the angle field to Number (e.g. StringToNumber step or Value constructor with a double).
  3. Fix the input step's field type metadata.
  4. Catch KettleValueException and handle the non-numeric branch.

Example fix

// before
Value s = value.sin(); // throws for String-typed value
// after
Value s = value.isNumeric() ? value.sin() : new Value(value.getName(), Math.sin(Double.parseDouble(value.getString())));
Defensive patterns

Strategy: type-guard

Validate before calling

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

Type guard

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

Try / catch

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

Prevention

When it happens

Trigger: Calling value.sin() on a non-numeric Value type, typically a String angle value read from a text source.

Common situations: Trigonometry on a column typed as String; degree/angle data ingested as text; field metadata changed upstream.

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

Appendix: source

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

      } else {
        value.setInteger( 0 );
      }
    } else {
      throw new KettleValueException( "Function SIGN only works with a number" );
    }

    return this;
  }

  // implement the SIN function, arguments in args[]
  public Value sin() throws KettleValueException {
    if ( isNull() ) {
      return this;
    }
    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;
  }

View on GitHub (pinned to f3058517a1)