pentaho/pentaho-kettle · error · KettleValueException

Function POWER only works with numeric data

Error message

Function POWER only works with numeric data

What it means

Thrown by Value.power() when either the receiving Value is not numeric (or, indirectly, the argument carries no usable number). power() skips null values, computes Math.pow for numerics, and throws KettleValueException for any other type. POWER is only defined for numbers in this compatibility layer.

Solutions

  1. Guard with value.isNumeric() before calling power().
  2. Convert the operand to a number first (e.g. via a 'Select values' metadata change or Value.convertToNumber() if available).
  3. Check for null first: null is silently returned, so ensure the non-null value is numeric.
  4. Catch KettleValueException and route the row to an error handling stream.

Example fix

// before
Value squared = value.power(new Value(2L)); // throws for String-typed value
// after
Value squared = value.isNumeric() ? value.power(new Value(2L)) : new Value(value.getName(), 0.0);
Defensive patterns

Strategy: type-guard

Validate before calling

if (!value.isNumeric() || !exp.isNumeric()) { throw new IllegalArgumentException("POWER requires numeric operands"); }

Type guard

boolean powSafe(Value base, Value exp) { return base.isNumeric() && exp.isNumeric(); }

Try / catch

try { result = value.power(exp); } catch (KettleValueException e) { log.error("POWER on non-numeric: " + e.getMessage()); result = null; }

Prevention

When it happens

Trigger: Calling value.power(exponentValue) where value has a String, Date, Boolean, or Binary type; also when the exponent Value is non-numeric so v.getNumber() yields 0 or garbage on a numeric base is fine but non-numeric base always throws.

Common situations: Formula steps receiving string-typed columns from text inputs; schema drift after changing a database field to VARCHAR; using POWER on boolean flags 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/d6210ac3cde4237d. Report an issue: GitHub.

Appendix: source

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

    return this;
  }

  // implement the POWER function, arguments in args[]
  public Value power( BigDecimal arg ) throws KettleValueException {
    return power( new Value( "tmp", arg ) );
  }

  public Value power( double arg ) throws KettleValueException {
    return power( new Value( "tmp", arg ) );
  }

  public Value power( Value v ) throws KettleValueException {
    if ( isNull() ) {
      return this;
    } else if ( isNumeric() ) {
      setValue( Math.pow( getNumber(), v.getNumber() ) );
    } else {
      throw new KettleValueException( "Function POWER only works with numeric data" );
    }
    return this;
  }

  // implement the REPLACE function, arguments in args[]
  public Value replace( Value repl, Value with ) {
    return replace( repl.getString(), with.getString() );
  }

  public Value replace( String repl, String with ) {
    if ( isNull() ) {
      return this;
    }
    if ( getString() == null ) {
      setNull();
    } else {
      setValue( Const.replace( getString(), repl, with ) );
    }

View on GitHub (pinned to f3058517a1)