{"record":{"id":"35013662ddfe4ae3","repo":"pentaho/pentaho-kettle","slug":"error-arithmetic-value","errorCode":"ERROR_ARITHMETIC_VALUE","errorMessage":"ERROR_ARITHMETIC_VALUE (arithmetic error converting row value)","messagePattern":"ERROR_ARITHMETIC_VALUE \\(arithmetic error converting row value\\)","errorType":"error_code","errorClass":"EvaluationException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/formula/RowForumulaContext.java","lineNumber":97,"sourceCode":"      ValueMetaInterface valueMeta;\n      Integer idx = valueIndexMap.get( name );\n      if ( idx != null ) {\n        valueMeta = rowMeta.getValueMeta( idx.intValue() );\n      } else {\n        int index = rowMeta.indexOfValue( (String) name );\n        if ( index < 0 ) {\n          ErrorValue errorValue = new LibFormulaErrorValue( LibFormulaErrorValue.ERROR_INVALID_ARGUMENT );\n          throw new EvaluationException( errorValue );\n        }\n        valueMeta = rowMeta.getValueMeta( index );\n        idx = new Integer( index );\n        valueIndexMap.put( (String) name, idx );\n      }\n      Object valueData = rowData[idx];\n      try {\n        return getPrimitive( valueMeta, valueData );\n      } catch ( KettleValueException e ) {\n        throw new EvaluationException( LibFormulaErrorValue.ERROR_ARITHMETIC_VALUE );\n      }\n    }\n    return null;\n  }\n\n  public Configuration getConfiguration() {\n    return formulaContext.getConfiguration();\n  }\n\n  public FunctionRegistry getFunctionRegistry() {\n    return formulaContext.getFunctionRegistry();\n  }\n\n  public LocalizationContext getLocalizationContext() {\n    return formulaContext.getLocalizationContext();\n  }\n\n  public OperatorFactory getOperatorFactory() {","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/formula/RowForumulaContext.java#L79-L115","documentation":"In resolveReference, the formula engine reads a row value and converts it to a Java primitive via getPrimitive(). If the ValueMeta conversion fails (KettleValueException), the step wraps it in an EvaluationException carrying ERROR_ARITHMETIC_VALUE, meaning the referenced field's value could not be arithmetically/type converted for formula evaluation. This is the generic 'value conversion failed' signal in the formula (libformula) engine.","triggerScenarios":"A formula references a field whose stored value cannot be converted to the primitive type the formula expects, and ValueMeta.getNativeObject/getPrimitive throws KettleValueException — e.g. reading a non-numeric string as Number, malformed Date, or binary value used in arithmetic.","commonSituations":"Formula step references a column containing 'N/A' or empty-but-not-null strings used in numeric expressions; upstream step changed a field's type (e.g. Integer to String); locale/date format mismatches when converting string values to dates; binary/large-object fields pulled into formulas.","solutions":["Inspect the referenced field's actual data at runtime; clean or coerce invalid values upstream (e.g. with a Calculator/Value Mapper or IF in the formula itself).","Verify the ValueMeta type of the field matches how the formula uses it; add an explicit conversion step before the Formula step.","Wrap formula operand usage defensively, e.g. IF(ISBLANK([field]);0;[field]) or use string-safe functions before numeric operations.","Check upstream steps for type changes after a version migration or step reconfiguration."],"exampleFix":"// before (formula assumes numeric)\n[field] * 2\n// after (guard against non-numeric)\nIF(ISBLANK([field]) OR ISNUMBER([field]) = FALSE; 0; [field] * 2)","handlingStrategy":"validation","validationCode":"// Before the Formula step, verify field type and data:\nValueMetaInterface vm = inputRowMeta.searchValueMeta(fieldName);\nif (vm == null || !(vm.getType() == ValueMetaInterface.TYPE_NUMBER || vm.getType() == ValueMetaInterface.TYPE_INTEGER)) {\n  throw new KettleException(\"Field \" + fieldName + \" is not numeric: \" + vm);\n}","typeGuard":"boolean isNumeric(ValueMetaInterface vm) {\n  return vm != null && (vm.isNumeric());\n}","tryCatchPattern":null,"preventionTips":["Preview upstream data to confirm values are convertible to the expected type.","Keep field types stable across steps; add explicit conversion steps.","Use formula guards like IFERROR/ISNUMBER before arithmetic.","Avoid feeding binary or loosely-typed fields into formulas."],"tags":["formula","type-conversion","kettle"],"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"}