pentaho/pentaho-kettle · error · KettleValueException
Function ATAN2 only works with numbers
Error message
Function ATAN2 only works with numbers
What it means
The atan2(Value arg0) method computes the two-argument arc tangent of this Value and arg0. Both operands must be numeric; if this Value is not numeric the method throws this KettleValueException. Note the check is on the receiver Value, so a String receiver (or a non-numeric argument implicitly converted) triggers the throw.
Solutions
- Ensure both the receiver Value and arg0 are numeric (setType(VALUE_TYPE_NUMBER) or stream-level conversion)
- Fix the input step metadata so both columns are Number
- Guard with isNumeric() on both operands before invoking atan2
Example fix
// before Value angle = y.atan2(x); // y and x are Strings // after y.setType(Value.VALUE_TYPE_NUMBER); x.setType(Value.VALUE_TYPE_NUMBER); Value angle = y.atan2(x);
Defensive patterns
Strategy: type-guard
Validate before calling
if (value == null || arg0 == null || !value.isNumeric() || !arg0.isNumeric()) {
throw new IllegalArgumentException("ATAN2 requires numeric values for both operands");
} Type guard
boolean bothNumeric(Value a, Value b) { return a != null && b != null && a.isNumeric() && b.isNumeric(); } Try / catch
try {
result = value.atan2(arg0);
} catch (KettleValueException e) {
value.setType(Value.VALUE_TYPE_NUMBER);
arg0.setType(Value.VALUE_TYPE_NUMBER);
result = value.atan2(arg0);
} Prevention
- Verify both operands (receiver and argument) are numeric, not just one
- Convert x/y coordinate columns to Number before geometric calculations
- Use a two-operand guard helper before calling multi-argument math functions
- Trace field types through the transformation with a preview/sample step
When it happens
Trigger: Calling value.atan2(arg0) where the receiving Value is a non-numeric type (String/Date/Boolean), e.g. computing an angle from two fields read as text.
Common situations: Cartesian-to-polar conversions in transformations where x/y columns come from CSV as String; unconverted fields after a step-reordering refactor.
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 CEIL only works with a number
- Function COS only works with a number
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/fe1496cde68d3eca.
Report an issue: GitHub.
Appendix: source
Thrown at core/src/main/java/org/pentaho/di/compatibility/Value.java:2428
throw new KettleValueException( "Function ATAN only works with numeric data" );
}
return this;
}
// implement the ATAN2 function, arguments in args[]
public Value atan2( Value arg0 ) throws KettleValueException {
return atan2( arg0.getNumber() );
}
public Value atan2( double arg0 ) throws KettleValueException {
if ( isNull() ) {
return this;
}
if ( isNumeric() ) {
setValue( Math.atan2( getNumber(), arg0 ) );
} else {
throw new KettleValueException( "Function ATAN2 only works with numbers" );
}
return this;
}
// implement the CEIL function, arguments in args[]
public Value ceil() throws KettleValueException {
if ( isNull() ) {
return this;
}
if ( isNumeric() ) {
setValue( Math.ceil( getNumber() ) );
} else {
throw new KettleValueException( "Function CEIL only works with a number" );
}
return this;
}
View on GitHub (pinned to f3058517a1)