pentaho/pentaho-kettle · error · KettleValueException
Function COS only works with a number
Error message
Function COS only works with a number
What it means
The cos() method of Kettle's legacy Value class computes the cosine of the value (in radians) via Math.cos. If the Value is not numeric it throws this KettleValueException, because the underlying Java Math call requires a double. Type enforcement is done at runtime by the legacy compatibility Value class.
Solutions
- Convert the Value to Number before calling cos() (setType(VALUE_TYPE_NUMBER))
- Fix the input step so the field is declared numeric
- Guard with isNumeric() and convert or skip non-numeric rows
Example fix
// before Value result = angle.cos(); // angle is a String // after angle.setType(Value.VALUE_TYPE_NUMBER); Value result = angle.cos();
Defensive patterns
Strategy: type-guard
Validate before calling
if (value == null || !value.isNumeric()) {
throw new IllegalArgumentException("COS requires a numeric value, got type " + (value == null ? "null" : value.getType()));
} Type guard
boolean isNumericValue(Value v) { return v != null && v.isNumeric(); } Try / catch
try {
result = value.cos();
} catch (KettleValueException e) {
value.setType(Value.VALUE_TYPE_NUMBER);
result = value.cos();
} Prevention
- Ensure angle fields are declared numeric at read time
- Convert String-typed angles to Number before trigonometry
- Precondition-check with isNumeric() before calling cos()
- Re-check field types after modifying or reordering transformation steps
When it happens
Trigger: Calling Value.cos() when the Value holds a String, Date, Boolean or other non-numeric type - typically an angle value read as text and not converted.
Common situations: Trigonometric calculations in legacy JavaScript/Formula steps; angle columns from Excel/CSV inputs typed as String; transformations where a type-conversion step was deleted.
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/4ff4e9d62fb4c899.
Report an issue: GitHub.
Appendix: source
Thrown at core/src/main/java/org/pentaho/di/compatibility/Value.java:2456
if ( isNumeric() ) {
setValue( Math.ceil( getNumber() ) );
} else {
throw new KettleValueException( "Function CEIL only works with a number" );
}
return this;
}
// implement the COS function, arguments in args[]
public Value cos() throws KettleValueException {
if ( isNull() ) {
return this;
}
if ( isNumeric() ) {
setValue( Math.cos( getNumber() ) );
} else {
throw new KettleValueException( "Function COS only works with a number" );
}
return this;
}
// implement the EXP function, arguments in args[]
public Value exp() throws KettleValueException {
if ( isNull() ) {
return this;
}
if ( isNumeric() ) {
setValue( Math.exp( getNumber() ) );
} else {
throw new KettleValueException( "Function EXP only works with a number" );
}
return this;
}
View on GitHub (pinned to f3058517a1)