{"record":{"id":"5ac77c3b5414b610","repo":"pentaho/pentaho-kettle","slug":"the-abs-function-only-works-on-numeric-data","errorCode":null,"errorMessage":"The 'abs' function only works on numeric data","messagePattern":"The 'abs' function only works on numeric data","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/row/ValueDataUtil.java","lineNumber":1385,"sourceCode":"        throw new KettleValueException( \"The 'floor' function only works on numeric data\" );\n    }\n  }\n\n  public static Object abs( ValueMetaInterface metaA, Object dataA ) throws KettleValueException {\n    if ( dataA == null ) {\n      return null;\n    }\n\n    switch ( metaA.getType() ) {\n      case ValueMetaInterface.TYPE_NUMBER:\n        return new Double( Math.abs( metaA.getNumber( dataA ).doubleValue() ) );\n      case ValueMetaInterface.TYPE_INTEGER:\n        return metaA.getInteger( Math.abs( metaA.getNumber( dataA ).longValue() ) );\n      case ValueMetaInterface.TYPE_BIGNUMBER:\n        return metaA.getBigNumber( dataA ).abs();\n\n      default:\n        throw new KettleValueException( \"The 'abs' function only works on numeric data\" );\n    }\n  }\n\n  /**\n   * Returns the remainder (modulus) of A / B.\n   *\n   * @param metaA\n   * @param dataA\n   *          The dividend\n   * @param metaB\n   * @param dataB\n   *          The divisor\n   * @return The remainder\n   * @throws KettleValueException\n   */\n  public static Object remainder( ValueMetaInterface metaA, Object dataA, ValueMetaInterface metaB, Object dataB ) throws KettleValueException {\n    if ( dataA == null || dataB == null ) {\n      return null;","sourceCodeStart":1367,"sourceCodeEnd":1403,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/row/ValueDataUtil.java#L1367-L1403","documentation":"Guard in ValueDataUtil.abs(): the input data is non-null but its ValueMeta type is none of Number, Integer or BigNumber, so absolute-value computation is refused. The input at fault is dataA whose metadata type is a non-numeric type (String, Date, Boolean, etc.).","triggerScenarios":"Calling ValueDataUtil.abs(metaA, dataA) (Calculator 'ABS( A )') where metaA.getType() is not TYPE_NUMBER, TYPE_INTEGER, or TYPE_BIGNUMBER — e.g. a negative number stored as String \"-5\".","commonSituations":"ABS applied to string deltas from log parsing; ABS on a boolean or date field by mistake; source system exports numbers as strings.","solutions":["Type the field as numeric before the Calculator step (Select Values metadata).","Add a string-to-number conversion step for the signed value.","Validate the field type in a UDJC step before calling abs."],"exampleFix":"// before: ABS(fieldS:String = \"-5\") -> throws\n// after: convert fieldS to Number; ABS(fieldS) -> 5","handlingStrategy":"type-guard","validationCode":"int t = metaA.getType();\nif (t != ValueMetaInterface.TYPE_NUMBER && t != ValueMetaInterface.TYPE_INTEGER && t != ValueMetaInterface.TYPE_BIGNUMBER) {\n  throw new KettleValueException(\"abs(A) requires numeric field, got type \" + t);\n}","typeGuard":"public static boolean isNumericMeta(ValueMetaInterface m) {\n  int t = m.getType();\n  return t == ValueMetaInterface.TYPE_NUMBER || t == ValueMetaInterface.TYPE_INTEGER || t == ValueMetaInterface.TYPE_BIGNUMBER;\n}","tryCatchPattern":"try {\n  a = ValueDataUtil.abs(metaA, dataA);\n} catch (KettleValueException e) {\n  logError(\"abs on non-numeric field: \" + e.getMessage());\n  a = null;\n}","preventionTips":["Type signed numeric fields as Number before ABS.","Validate upstream exports actually emit numbers, not strings.","Use row error handling to divert malformed rows instead of failing the transformation."],"tags":["kettle","pdi","calculator","numeric-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"}