pentaho/pentaho-kettle · error · KettleValueException
Function LOG only works with a number
Error message
Function LOG only works with a number
What it means
The log() method of Kettle's legacy Value class computes the natural logarithm via Math.log. It throws this KettleValueException when the Value is not numeric, since Math.log requires a double. Additionally, callers should remember Math.log is undefined for values <= 0 (NaN), though the type check itself only rejects non-numeric types.
Solutions
- Convert the Value to Number before calling log() (setType(VALUE_TYPE_NUMBER))
- Fix the input/conversion steps so the field stays numeric
- Guard with isNumeric() (and consider validating value > 0) before the call
Example fix
// before
Value result = value.log(); // value is a String
// after
if (!value.isNumeric()) {
value.setType(Value.VALUE_TYPE_NUMBER);
}
Value result = value.log(); Defensive patterns
Strategy: type-guard
Validate before calling
if (value == null || !value.isNumeric()) {
throw new IllegalArgumentException("LOG requires a numeric value, got type " + (value == null ? "null" : value.getType()));
}
// also consider domain: Math.log is undefined for values <= 0
if (value.getNumber() <= 0) {
throw new IllegalArgumentException("LOG requires a positive value");
} Type guard
boolean isPositiveNumeric(Value v) { return v != null && v.isNumeric() && v.getNumber() > 0; } Try / catch
try {
result = value.log();
} catch (KettleValueException e) {
value.setType(Value.VALUE_TYPE_NUMBER);
result = value.log();
} Prevention
- Convert measurement fields to Number before logarithmic calculations
- Check isNumeric() and value > 0 before calling log()
- Avoid passing formatted/String intermediate fields into log-scale math
- Verify auto-detected column types when input file formats change
When it happens
Trigger: Calling Value.log() on a String/Date/Boolean-typed Value - e.g. taking the log of a measurement field read as text.
Common situations: Log-scale calculations where the input column from CSV/Excel was not detected as numeric; intermediate fields converted to String for formatting and never converted back.
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
- Function ACOS only works with numeric data
- Function ASIN only works with numeric data
- Function ATAN only works with numeric data
- Function ATAN2 only works with numbers
- Function CEIL only works with a number
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/d3246bf2da9524d2.
Report an issue: GitHub.
Appendix: source
Thrown at core/src/main/java/org/pentaho/di/compatibility/Value.java:2528
if ( getType() == VALUE_TYPE_STRING ) {
setValue( (double) getString().length() );
} else {
throw new KettleValueException( "Function LENGTH only works with a string" );
}
return this;
}
// implement the LOG function, arguments in args[]
public Value log() throws KettleValueException {
if ( isNull() ) {
return this;
}
if ( isNumeric() ) {
setValue( Math.log( getNumber() ) );
} else {
throw new KettleValueException( "Function LOG only works with a number" );
}
return this;
}
// implement the LOWER function, arguments in args[]
public Value lower() {
if ( isNull() ) {
setType( VALUE_TYPE_STRING );
} else {
setValue( getString().toLowerCase() );
}
return this;
}
// implement the LPAD function: left pad strings or numbers...
public Value lpad( Value len ) {View on GitHub (pinned to f3058517a1)