pentaho/pentaho-kettle · error · KettleValueException
Function TAN only works on a number
Error message
Function TAN only works on a number
What it means
Thrown by Value.tan() when the value is not numeric. TAN computes Math.tan(getNumber()) behind an isNumeric() guard; String, Date, Boolean, and Binary values raise KettleValueException. Nulls return early with no error.
Solutions
- Guard with value.isNumeric() before calling tan().
- Convert the angle field to Number before applying TAN.
- Correct the field type in the input step or a 'Select values' step.
- Catch KettleValueException and route bad rows to error handling.
Example fix
// before Value t = value.tan(); // throws for String-typed value // after Value t = value.isNumeric() ? value.tan() : new Value(value.getName(), Math.tan(Double.parseDouble(value.getString())));
Defensive patterns
Strategy: type-guard
Validate before calling
if (!value.isNumeric()) { throw new IllegalArgumentException("TAN requires a numeric angle"); } Type guard
boolean tanSafe(Value v) { return v != null && v.isNumeric(); } Try / catch
try { result = value.tan(); } catch (KettleValueException e) { result = null; } Prevention
- Convert angle text to Number before TAN
- Maintain numeric metadata across steps
- Handle isNull() separately — nulls return unchanged
When it happens
Trigger: Calling value.tan() on a non-numeric Value, most often an angle stored as String.
Common situations: Trigonometric transformations on text-file columns; angle data ingested as strings; using TAN on mis-typed field metadata.
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 SIN only works with a number
- BaseStep.SafeMode.Exception.MixingTypes
- DynamicSQLRow.Exception.TemplateReturnDataTypeError
- ElasticSearchBulk.Error.NoJsonFieldFormat
- Function MOD only works with numeric data
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/131afaacdcd02af3.
Report an issue: GitHub.
Appendix: source
Thrown at core/src/main/java/org/pentaho/di/compatibility/Value.java:3022
}
// implement the SYSDATE function, arguments in args[]
public Value sysdate() {
setValue( Calendar.getInstance().getTime() );
return this;
}
// implement the TAN function, arguments in args[]
public Value tan() throws KettleValueException {
if ( isNull() ) {
return this;
}
if ( isNumeric() ) {
setValue( Math.tan( getNumber() ) );
} else {
throw new KettleValueException( "Function TAN only works on a number" );
}
return this;
}
// implement the TO_CHAR function, arguments in args[]
// number: NUM2STR( 123.456 ) : default format
// number: NUM2STR( 123.456, '###,##0.000') : format
// number: NUM2STR( 123.456, '###,##0.000', '.') : grouping
// number: NUM2STR( 123.456, '###,##0.000', '.', ',') : decimal
// number: NUM2STR( 123.456, '###,##0.000', '.', ',', '?') : currency
public Value num2str() throws KettleValueException {
return num2str( null, null, null, null );
}
public Value num2str( String format ) throws KettleValueException {
return num2str( format, null, null, null );View on GitHub (pinned to f3058517a1)