pentaho/pentaho-kettle · error · KettleStepException

SETVARIABLE0007

SETVARIABLE0007

Error message

Only 1 input row was expected to set the variables and at least 2 were received.

What it means

The Set Variables step can only receive exactly one input row per execution because it sets environment variables once. If a second row arrives, processRow throws KettleStepException with code SETVARIABLE0007, since setting the same variables again (possibly with different values) would be ambiguous and non-deterministic.

Solutions

  1. Ensure exactly one row reaches the step: add 'Sample rows' (range 0–0) or a 'Group by'/'Memory group by' aggregation before Set Variables.
  2. Use a 'Filter rows' step so only one row (or none, if you configured a default value) passes through.
  3. If you need per-row variable logic, don't use Set Variables — restructure to pass values as fields instead.
  4. Preview the incoming stream to confirm how many rows the upstream step emits.

Example fix

// before: Table input -> Set Variables (N rows)
// after: Table input -> Sample rows (range 0..0) -> Set Variables
// or: Table input -> Memory Group By (MAX(value)) -> Set Variables
Defensive patterns

Strategy: validation

Validate before calling

// Ensure upstream emits at most one row before Set Variables
// Table input -> Sample rows (range 0..0) -> Set Variables
// or verify programmatically:
Object[] row = rowSet.getRow(); // first row
if (rowSet.getRowWait(1, TimeUnit.MILLISECONDS) != null) {
  throw new IllegalStateException("More than one row would reach Set Variables");
}

Try / catch

try {
  trans.execute(null);
  trans.waitUntilFinished();
} catch (KettleException e) {
  if (e.getMessage().contains("MoreThanOneRowReceived")) {
    log.error("Add Sample rows / Group by before Set Variables");
  }
}

Prevention

When it happens

Trigger: processRow: after handling the first row it calls putRow and returns; any subsequent invocation (a second row from the previous step) falls through to the throw. This happens whenever the upstream stream emits more than one row, e.g. a table lookup returning multiple rows or a stream without aggregation.

Common situations: Feeding Set Variables from a table where the query returns multiple rows; forgetting a 'Sample rows' (limit=1) or 'Aggregate' step before Set Variables; a join producing duplicates; accidentally leaving the step in the main stream when it should run once.

Related errors


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

Appendix: source

Thrown at engine/src/main/java/org/pentaho/di/trans/steps/setvariable/SetVariable.java:88

      return false;
    }

    if ( first ) {
      first = false;

      data.outputMeta = getInputRowMeta().clone();

      logBasic( BaseMessages.getString( PKG, "SetVariable.Log.SettingVar" ) );

      for ( int i = 0; i < meta.getFieldName().length; i++ ) {
        setValue( rowData, i, false );
      }

      putRow( data.outputMeta, rowData );
      return true;
    }

    throw new KettleStepException( BaseMessages.getString(
      PKG, "SetVariable.RuntimeError.MoreThanOneRowReceived.SETVARIABLE0007" ) );
  }

  private void setValue( Object[] rowData, int i, boolean usedefault ) throws KettleException {
    // Set the appropriate environment variable
    //
    String value = null;
    if ( usedefault ) {
      value = environmentSubstitute( meta.getDefaultValue()[i] );
    } else {
      int index = data.outputMeta.indexOfValue( meta.getFieldName()[i] );
      if ( index < 0 ) {
        throw new KettleException( "Unable to find field [" + meta.getFieldName()[i] + "] in input row" );
      }
      ValueMetaInterface valueMeta = data.outputMeta.getValueMeta( index );
      Object valueData = rowData[index];

      // Get variable value

View on GitHub (pinned to f3058517a1)