{"record":{"id":"ca6b0091165425f8","repo":"pentaho/pentaho-kettle","slug":"setvariable0007","errorCode":"SETVARIABLE0007","errorMessage":"Only 1 input row was expected to set the variables and at least 2 were received.","messagePattern":"Only 1 input row was expected to set the variables and at least 2 were received\\.","errorType":"exception","errorClass":"KettleStepException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/setvariable/SetVariable.java","lineNumber":88,"sourceCode":"      return false;\n    }\n\n    if ( first ) {\n      first = false;\n\n      data.outputMeta = getInputRowMeta().clone();\n\n      logBasic( BaseMessages.getString( PKG, \"SetVariable.Log.SettingVar\" ) );\n\n      for ( int i = 0; i < meta.getFieldName().length; i++ ) {\n        setValue( rowData, i, false );\n      }\n\n      putRow( data.outputMeta, rowData );\n      return true;\n    }\n\n    throw new KettleStepException( BaseMessages.getString(\n      PKG, \"SetVariable.RuntimeError.MoreThanOneRowReceived.SETVARIABLE0007\" ) );\n  }\n\n  private void setValue( Object[] rowData, int i, boolean usedefault ) throws KettleException {\n    // Set the appropriate environment variable\n    //\n    String value = null;\n    if ( usedefault ) {\n      value = environmentSubstitute( meta.getDefaultValue()[i] );\n    } else {\n      int index = data.outputMeta.indexOfValue( meta.getFieldName()[i] );\n      if ( index < 0 ) {\n        throw new KettleException( \"Unable to find field [\" + meta.getFieldName()[i] + \"] in input row\" );\n      }\n      ValueMetaInterface valueMeta = data.outputMeta.getValueMeta( index );\n      Object valueData = rowData[index];\n\n      // Get variable value","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/setvariable/SetVariable.java#L70-L106","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure exactly one row reaches the step: add 'Sample rows' (range 0–0) or a 'Group by'/'Memory group by' aggregation before Set Variables.","Use a 'Filter rows' step so only one row (or none, if you configured a default value) passes through.","If you need per-row variable logic, don't use Set Variables — restructure to pass values as fields instead.","Preview the incoming stream to confirm how many rows the upstream step emits."],"exampleFix":"// before: Table input -> Set Variables (N rows)\n// after: Table input -> Sample rows (range 0..0) -> Set Variables\n// or: Table input -> Memory Group By (MAX(value)) -> Set Variables","handlingStrategy":"validation","validationCode":"// Ensure upstream emits at most one row before Set Variables\n// Table input -> Sample rows (range 0..0) -> Set Variables\n// or verify programmatically:\nObject[] row = rowSet.getRow(); // first row\nif (rowSet.getRowWait(1, TimeUnit.MILLISECONDS) != null) {\n  throw new IllegalStateException(\"More than one row would reach Set Variables\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  trans.execute(null);\n  trans.waitUntilFinished();\n} catch (KettleException e) {\n  if (e.getMessage().contains(\"MoreThanOneRowReceived\")) {\n    log.error(\"Add Sample rows / Group by before Set Variables\");\n  }\n}","preventionTips":["Always place 'Sample rows' (0..0) or an aggregation before Set Variables","Preview the feeder step to confirm single-row output","Use 'Abort if more than one row' logic upstream when the row count is uncertain","Don't route multi-row streams through Set Variables as a side effect"],"tags":["kettle","set-variables","row-count","transformation"],"backgroundTag":"invalid-row-count","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"}