{"record":{"id":"d6210ac3cde4237d","repo":"pentaho/pentaho-kettle","slug":"function-power-only-works-with-numeric-data","errorCode":null,"errorMessage":"Function POWER only works with numeric data","messagePattern":"Function POWER only works with numeric data","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/compatibility/Value.java","lineNumber":2677,"sourceCode":"    return this;\n  }\n\n  // implement the POWER function, arguments in args[]\n  public Value power( BigDecimal arg ) throws KettleValueException {\n    return power( new Value( \"tmp\", arg ) );\n  }\n\n  public Value power( double arg ) throws KettleValueException {\n    return power( new Value( \"tmp\", arg ) );\n  }\n\n  public Value power( Value v ) throws KettleValueException {\n    if ( isNull() ) {\n      return this;\n    } else if ( isNumeric() ) {\n      setValue( Math.pow( getNumber(), v.getNumber() ) );\n    } else {\n      throw new KettleValueException( \"Function POWER only works with numeric data\" );\n    }\n    return this;\n  }\n\n  // implement the REPLACE function, arguments in args[]\n  public Value replace( Value repl, Value with ) {\n    return replace( repl.getString(), with.getString() );\n  }\n\n  public Value replace( String repl, String with ) {\n    if ( isNull() ) {\n      return this;\n    }\n    if ( getString() == null ) {\n      setNull();\n    } else {\n      setValue( Const.replace( getString(), repl, with ) );\n    }","sourceCodeStart":2659,"sourceCodeEnd":2695,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/compatibility/Value.java#L2659-L2695","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Guard with value.isNumeric() before calling power().","Convert the operand to a number first (e.g. via a 'Select values' metadata change or Value.convertToNumber() if available).","Check for null first: null is silently returned, so ensure the non-null value is numeric.","Catch KettleValueException and route the row to an error handling stream."],"exampleFix":"// before\nValue squared = value.power(new Value(2L)); // throws for String-typed value\n// after\nValue squared = value.isNumeric() ? value.power(new Value(2L)) : new Value(value.getName(), 0.0);","handlingStrategy":"type-guard","validationCode":"if (!value.isNumeric() || !exp.isNumeric()) { throw new IllegalArgumentException(\"POWER requires numeric operands\"); }","typeGuard":"boolean powSafe(Value base, Value exp) { return base.isNumeric() && exp.isNumeric(); }","tryCatchPattern":"try { result = value.power(exp); } catch (KettleValueException e) { log.error(\"POWER on non-numeric: \" + e.getMessage()); result = null; }","preventionTips":["Guard both base and exponent with isNumeric()","Convert string inputs via StringToNumber before math steps","Remember null values pass through silently — check isNull separately"],"tags":["kettle","type-mismatch","math"],"backgroundTag":"type-mismatch","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}