{"record":{"id":"350f98d6deb927a1","repo":"pentaho/pentaho-kettle","slug":"function-acos-only-works-with-numeric-data","errorCode":null,"errorMessage":"Function ACOS only works with numeric data","messagePattern":"Function ACOS only works with numeric data","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/compatibility/Value.java","lineNumber":2382,"sourceCode":"      setValue( Math.abs( getNumber() ) );\n    } else if ( isInteger() ) {\n      setValue( Math.abs( getInteger() ) );\n    } else {\n      throw new KettleValueException( \"Function ABS only works with a number\" );\n    }\n    return this;\n  }\n\n  // implement the ACOS function, arguments in args[]\n  public Value acos() throws KettleValueException {\n    if ( isNull() ) {\n      return this;\n    }\n\n    if ( isNumeric() ) {\n      setValue( Math.acos( getNumber() ) );\n    } else {\n      throw new KettleValueException( \"Function ACOS only works with numeric data\" );\n    }\n    return this;\n  }\n\n  // implement the ASIN function, arguments in args[]\n  public Value asin() throws KettleValueException {\n    if ( isNull() ) {\n      return this;\n    }\n\n    if ( isNumeric() ) {\n      setValue( Math.asin( getNumber() ) );\n    } else {\n      throw new KettleValueException( \"Function ASIN only works with numeric data\" );\n    }\n    return this;\n  }\n","sourceCodeStart":2364,"sourceCodeEnd":2400,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/compatibility/Value.java#L2364-L2400","documentation":"In Pentaho Kettle's legacy org.pentaho.di.compatibility.Value class, the acos() method computes the arc cosine of the value. Before doing so it checks isNumeric(); if the Value holds a non-numeric type (string, date, boolean, etc.) it throws this KettleValueException because Math.acos requires a double. The legacy Value class performs these explicit runtime type checks instead of relying on the compiler.","triggerScenarios":"Calling Value.acos() on a Value whose type is not VALUE_TYPE_NUMBER/INTEGER/BIGNUMBER - e.g. a field read from a text file column that stayed a String, or a null-typed Value that was not converted first.","commonSituations":"JavaScript/formula-like transform steps that call mathematical functions on fields typed as String; CSV/Excel inputs where a numeric column was inferred as String due to formatting characters; migrating old Kettle transformations where Value type conversion steps were removed.","solutions":["Convert the Value to a number before calling acos(), e.g. value.setType(Value.VALUE_TYPE_NUMBER) or use the appropriate conversion method","Fix upstream field metadata so the column arrives as Number (Numeric type in Select values / Text file input)","Guard the call with if (value.isNumeric()) and handle the non-numeric branch explicitly"],"exampleFix":"// before\nValue result = value.acos();\n// after\nif (!value.isNumeric()) {\n  value.setType(Value.VALUE_TYPE_NUMBER); // convert string/other to number\n}\nValue result = value.acos();","handlingStrategy":"type-guard","validationCode":"if (value == null || !value.isNumeric()) {\n  throw new IllegalArgumentException(\"ACOS requires a numeric value, got type \" + (value == null ? \"null\" : value.getType()));\n}","typeGuard":"boolean isNumericValue(Value v) { return v != null && v.isNumeric(); }","tryCatchPattern":"try {\n  result = value.acos();\n} catch (KettleValueException e) {\n  // value was non-numeric: convert and retry or fail the row\n  value.setType(Value.VALUE_TYPE_NUMBER);\n  result = value.acos();\n}","preventionTips":["Always declare numeric columns as Number in input steps (Text file input, Excel input, Table input)","Insert a 'Select values' type-conversion step before mathematical calculations","Call isNumeric() as a precondition before any legacy Value math function","Avoid letting intermediate results pass through String fields in calculation chains"],"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"}