{"record":{"id":"fe1496cde68d3eca","repo":"pentaho/pentaho-kettle","slug":"function-atan2-only-works-with-numbers","errorCode":null,"errorMessage":"Function ATAN2 only works with numbers","messagePattern":"Function ATAN2 only works with numbers","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/compatibility/Value.java","lineNumber":2428,"sourceCode":"      throw new KettleValueException( \"Function ATAN only works with numeric data\" );\n    }\n    return this;\n  }\n\n  // implement the ATAN2 function, arguments in args[]\n  public Value atan2( Value arg0 ) throws KettleValueException {\n    return atan2( arg0.getNumber() );\n  }\n\n  public Value atan2( double arg0 ) throws KettleValueException {\n    if ( isNull() ) {\n      return this;\n    }\n\n    if ( isNumeric() ) {\n      setValue( Math.atan2( getNumber(), arg0 ) );\n    } else {\n      throw new KettleValueException( \"Function ATAN2 only works with numbers\" );\n    }\n    return this;\n  }\n\n  // implement the CEIL function, arguments in args[]\n  public Value ceil() throws KettleValueException {\n    if ( isNull() ) {\n      return this;\n    }\n\n    if ( isNumeric() ) {\n      setValue( Math.ceil( getNumber() ) );\n    } else {\n      throw new KettleValueException( \"Function CEIL only works with a number\" );\n    }\n    return this;\n  }\n","sourceCodeStart":2410,"sourceCodeEnd":2446,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/compatibility/Value.java#L2410-L2446","documentation":"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.","triggerScenarios":"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.","commonSituations":"Cartesian-to-polar conversions in transformations where x/y columns come from CSV as String; unconverted fields after a step-reordering refactor.","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"],"exampleFix":"// before\nValue angle = y.atan2(x); // y and x are Strings\n// after\ny.setType(Value.VALUE_TYPE_NUMBER);\nx.setType(Value.VALUE_TYPE_NUMBER);\nValue angle = y.atan2(x);","handlingStrategy":"type-guard","validationCode":"if (value == null || arg0 == null || !value.isNumeric() || !arg0.isNumeric()) {\n  throw new IllegalArgumentException(\"ATAN2 requires numeric values for both operands\");\n}","typeGuard":"boolean bothNumeric(Value a, Value b) { return a != null && b != null && a.isNumeric() && b.isNumeric(); }","tryCatchPattern":"try {\n  result = value.atan2(arg0);\n} catch (KettleValueException e) {\n  value.setType(Value.VALUE_TYPE_NUMBER);\n  arg0.setType(Value.VALUE_TYPE_NUMBER);\n  result = value.atan2(arg0);\n}","preventionTips":["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"],"tags":["kettle","numeric-type","math-function","runtime-type-check"],"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"}