{"record":{"id":"8b2c294df4aefdb1","repo":"pentaho/pentaho-kettle","slug":"the-input-field-for-stats-calc-0-is-not-numeric","errorCode":null,"errorMessage":"The input field for stats calc #{0}is not numeric.","messagePattern":"The input field for stats calc #(.+?)is not numeric\\.","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/univariatestats/UnivariateStats.java","lineNumber":145,"sourceCode":"        // check that this univariate stats computation has been\n        // defined on an input field\n        if ( !Utils.isEmpty( usmf.getSourceFieldName() ) ) {\n          int fieldIndex = m_data.getInputRowMeta().indexOfValue( usmf.getSourceFieldName() );\n\n          if ( fieldIndex < 0 ) {\n            throw new KettleStepException( \"Unable to find the specified fieldname '\"\n              + usmf.getSourceFieldName() + \"' for stats calc #\" + ( i + 1 ) );\n          }\n\n          FieldIndex tempData = m_data.getFieldIndexes()[ i ];\n\n          tempData.m_columnIndex = fieldIndex;\n\n          ValueMetaInterface inputFieldMeta = m_data.getInputRowMeta().getValueMeta( fieldIndex );\n\n          // check the type of the input field\n          if ( !inputFieldMeta.isNumeric() ) {\n            throw new KettleException( \"The input field for stats calc #\" + ( i + 1 ) + \"is not numeric.\" );\n          }\n\n          // finish initializing\n          tempData.m_min = Double.MAX_VALUE;\n          tempData.m_max = Double.MIN_VALUE;\n\n          // set up caches if median/percentiles have been\n          // requested\n\n          if ( usmf.getCalcMedian() || usmf.getCalcPercentile() >= 0 ) {\n            m_dataCache[ i ] = new ArrayList<Number>();\n          }\n        } else {\n          throw new KettleException( \"There is no input field specified for stats calc #\" + ( i + 1 ) );\n        }\n      }\n    } // end (if first)\n","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/univariatestats/UnivariateStats.java#L127-L163","documentation":"UnivariateStats only supports numeric input. In processRow, after locating the source field's index, it checks inputFieldMeta.isNumeric(); if the field's ValueMetaInterface is not numeric (String, Date, Boolean, etc.) it throws this KettleException naming the calc index.","triggerScenarios":"processRow's first-pass initialization encounters a configured stats field whose incoming row metadata reports a non-numeric type.","commonSituations":"Feeding a String-typed column (e.g. from CSV without conversion) into UnivariateStats; an upstream type change; forgetting a 'Select values'/'String to number' conversion step.","solutions":["Convert the field to a numeric type upstream (e.g. Select values step with type Integer/Number, or String Operations/Value Mapper as appropriate)","Check the incoming row's field type in Spoon (right-click > Show input fields)","Fix the source step so it emits a numeric type","If parsing strings, use a 'Calculator' or 'If field value is null'/conversion step to produce a Number"],"exampleFix":"// before: feeding String field directly\nString amount -> UnivariateStats\n// after: convert first\nSelect values step: amount String -> Number\nNumber amount -> UnivariateStats","handlingStrategy":"validation","validationCode":"// Java: assert numeric input fields before execution\nRowMetaInterface input = transMeta.getPrevStepFields( univariateStatsStepMeta );\nfor ( UnivariateStatsMetaFunction f : meta.getFieldDefs() ) {\n  int idx = input.indexOfValue( f.getSourceFieldName() );\n  if ( idx >= 0 && !input.getValueMeta( idx ).isNumeric() ) {\n    throw new IllegalStateException( f.getSourceFieldName() + \" must be numeric\" );\n  }\n}","typeGuard":"boolean isNumericField(RowMetaInterface rowMeta, String name) {\n  int idx = rowMeta.indexOfValue( name );\n  return idx >= 0 && rowMeta.getValueMeta( idx ).isNumeric();\n}","tryCatchPattern":"try {\n  trans.execute( null );\n} catch ( KettleException e ) {\n  if ( e.getMessage().contains( \"is not numeric\" ) ) {\n    // add an upstream type-conversion step\n  }\n  throw e;\n}","preventionTips":["Insert a Select values step to enforce numeric types before UnivariateStats","Inspect incoming field types in Spoon before configuring stats","Convert CSV/string sources explicitly to Number early in the flow"],"tags":["kettle","type-mismatch","numeric","univariate-stats"],"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"}