pentaho/pentaho-kettle · error · KettleException

Unknown field specified to replace with a formula result: [

Error message

Unknown field specified to replace with a formula result: [

What it means

Thrown by the Janino (Formula) step's processRow during initialization when a formula is configured with a 'Replace value' field that does not exist in the incoming row. The step cannot locate the column whose value should be replaced by the formula result.

Solutions

  1. Open the Formula step and correct the 'Replace value' field name to match an incoming field exactly (case-sensitive).
  2. Clear the 'Replace value' box if you want a new field instead of replacing one.
  3. Re-run 'Get Fields' / re-verify hop metadata after changing upstream steps.
  4. Check any upstream Select/Filter steps that may remove or rename the field.

Example fix

// before
fn.setReplaceField("cust_name"); // field was renamed upstream
// after
fn.setReplaceField("customer_name");
Defensive patterns

Strategy: validation

Validate before calling

// Before running, confirm the replace field exists in the stream
String[] fields = inputRowMeta.getFieldNames();
boolean found = Arrays.stream(fields).anyMatch(f -> f.equals(fn.getReplaceField()));
if (fn.getReplaceField() != null && !found) {
  throw new IllegalStateException("Replace field not in stream: " + fn.getReplaceField());
}

Prevention

When it happens

Trigger: A JaninoMetaFunction has a non-empty replaceField, but getInputRowMeta().indexOfValue(replaceField) returns -1 — the upstream row layout differs from what the step was configured against.

Common situations: Renaming or removing an upstream field after configuring the formula; inserting a Select Values step that drops the field; the transformation runs with different incoming field order/case sensitivity.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13). Data as JSON: /api/errors/8689bcd0744f80ce. Report an issue: GitHub.

Appendix: source

Thrown at engine/src/main/java/org/pentaho/di/trans/steps/janino/Janino.java:83

    if ( first ) {
      first = false;

      data.outputRowMeta = getInputRowMeta().clone();
      meta.getFields( getTransMeta().getBowl(), data.outputRowMeta, getStepname(), null, null, this, repository,
        metaStore );

      // Calculate replace indexes...
      //
      data.replaceIndex = new int[meta.getFormula().length];
      data.returnType = new ValueMetaInterface[meta.getFormula().length];
      for ( int i = 0; i < meta.getFormula().length; i++ ) {
        JaninoMetaFunction fn = meta.getFormula()[i];
        data.returnType[i] = ValueMetaFactory.createValueMeta( fn.getValueType() );
        if ( !Utils.isEmpty( fn.getReplaceField() ) ) {
          data.replaceIndex[i] = getInputRowMeta().indexOfValue( fn.getReplaceField() );
          if ( data.replaceIndex[i] < 0 ) {
            throw new KettleException( "Unknown field specified to replace with a formula result: ["
              + fn.getReplaceField() + "]" );
          }
        } else {
          data.replaceIndex[i] = -1;
        }
      }
    }

    if ( log.isRowLevel() ) {
      logRowlevel( "Read row #" + getLinesRead() + " : " + getInputRowMeta().getString( r ) );
    }

    try {
      Object[] outputRowData = calcFields( getInputRowMeta(), r );
      putRow( data.outputRowMeta, outputRowData ); // copy row to possible alternate rowset(s).
      if ( log.isRowLevel() ) {
        logRowlevel( "Wrote row #" + getLinesWritten() + " : " + data.outputRowMeta.getString( outputRowData ) );
      }

View on GitHub (pinned to f3058517a1)