{"record":{"id":"a5cc7cbe4b7aab49","repo":"pentaho/pentaho-kettle","slug":"function-abs-only-works-with-a-number","errorCode":null,"errorMessage":"Function ABS only works with a number","messagePattern":"Function ABS only works with a number","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/compatibility/Value.java","lineNumber":2368,"sourceCode":"    return this;\n  }\n\n  // FUNCTIONS!!\n\n  // implement the ABS function, arguments in args[]\n  public Value abs() throws KettleValueException {\n    if ( isNull() ) {\n      return this;\n    }\n\n    if ( isBigNumber() ) {\n      setValue( getBigNumber().abs() );\n    } else if ( isNumber() ) {\n      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","sourceCodeStart":2350,"sourceCodeEnd":2386,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/compatibility/Value.java#L2350-L2386","documentation":"This KettleValueException is thrown by Value.abs() when the value's type is not BigNumber, Number, or Integer — e.g. String, Boolean, or Date. The ABS function implementation only handles those three numeric types and rejects everything else explicitly.","triggerScenarios":"Calling value.abs() (or the ABS formula/calculator function) on a Value whose VALUE_TYPE is STRING, BOOLEAN, DATE, etc. — typically a numeric-looking string field passed directly to ABS.","commonSituations":"CSV/text inputs typed as String; a calculated boolean fed into ABS; a Select Values step missing type conversion; metadata changes after upstream refactoring.","solutions":["Convert the value to a numeric type first: convertString( VALUE_TYPE_NUMBER ) or setType with the appropriate numeric type.","Add a Calculator/Select Values step to set the field type to Number/Integer before applying ABS.","Validate the field's ValueMetaInterface type before applying the function and skip or convert non-numeric rows.","If abs on a string representation is needed, parse to BigDecimal then apply abs.","Catch KettleValueException and include the value's current type and content in the error report."],"exampleFix":"// before\nValue absVal = strAmount.abs(); // throws: STRING\n// after\nstrAmount.convertString( Value.VALUE_TYPE_BIGNUMBER );\nValue absVal = strAmount.abs();","handlingStrategy":"type-guard","validationCode":"// before abs\nif ( !( v.isNumber() || v.isInteger() || v.isBigNumber() ) ) {\n  v.convertString( Value.VALUE_TYPE_NUMBER );\n}","typeGuard":"boolean absCapable( Value v ) {\n  return v != null && ( v.isNumber() || v.isInteger() || v.isBigNumber() );\n}","tryCatchPattern":"try {\n  Value absVal = v.abs();\n} catch ( KettleValueException e ) {\n  throw new IllegalStateException( \"ABS applied to non-numeric value of type \" + v.getType(), e );\n}","preventionTips":["Apply numeric type conversion before math functions (ABS, ACOS, etc.).","Reject or convert String/Boolean fields early in the pipeline.","Check ValueMetaInterface type before invoking functions.","Cover function steps with type-aware unit tests.","Guard against upstream metadata type changes with assertions."],"tags":["math","type-mismatch","abs","value-types"],"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"}