{"record":{"id":"7fc1218766591802","repo":"pentaho/pentaho-kettle","slug":"analyticquerymeta-exception-subjectfieldnotfound","errorCode":null,"errorMessage":"AnalyticQueryMeta.Exception.SubjectFieldNotFound","messagePattern":"AnalyticQueryMeta\\.Exception\\.SubjectFieldNotFound","errorType":"exception","errorClass":"KettleStepException","httpStatus":null,"severity":"error","filePath":"plugins/core/impl/src/main/java/org/pentaho/di/trans/steps/analyticquery/AnalyticQueryMeta.java","lineNumber":287,"sourceCode":"    for ( int i = 0; i < number_of_fields; i++ ) {\n\n      int index_of_subject = -1;\n      index_of_subject = r.indexOfValue( subjectField[i] );\n\n      // if we found the subjectField in the RowMetaInterface, and we should....\n      if ( index_of_subject > -1 ) {\n        ValueMetaInterface vmi = r.getValueMeta( index_of_subject ).clone();\n        vmi.setOrigin( origin );\n        vmi.setName( aggregateField[i] );\n        fields.addValueMeta( r.size() + i, vmi );\n      } else {\n        // we have a condition where the subjectField can't be found from the rowMetaInterface\n        StringBuilder sbfieldNames = new StringBuilder();\n        String[] fieldNames = r.getFieldNames();\n        for ( int j = 0; j < fieldNames.length; j++ ) {\n          sbfieldNames.append( \"[\" + fieldNames[j] + \"]\" + ( j < fieldNames.length - 1 ? \", \" : \"\" ) );\n        }\n        throw new KettleStepException( BaseMessages.getString(\n          PKG, \"AnalyticQueryMeta.Exception.SubjectFieldNotFound\", getParentStepMeta().getName(),\n          subjectField[i], sbfieldNames.toString() ) );\n      }\n    }\n\n    r.clear();\n    // Add back to Row Meta\n    r.addRowMeta( fields );\n  }\n\n  public String getXML() {\n    StringBuilder retval = new StringBuilder( 500 );\n\n    retval.append( \"      <group>\" ).append( Const.CR );\n    for ( int i = 0; i < groupField.length; i++ ) {\n      retval.append( \"        <field>\" ).append( Const.CR );\n      retval.append( \"          \" ).append( XMLHandler.addTagValue( \"name\", groupField[i] ) );\n      retval.append( \"        </field>\" ).append( Const.CR );","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/core/impl/src/main/java/org/pentaho/di/trans/steps/analyticquery/AnalyticQueryMeta.java#L269-L305","documentation":"KettleStepException thrown from AnalyticQueryMeta.getFields() during row-layout resolution when one of the configured subject fields (the field each analytic aggregate like LAG/LEAD operates on) is not present in the incoming row metadata. The message lists the step name, the missing subject field, and all available field names to make the mismatch obvious.","triggerScenarios":"getFields() iterates subjectField[i] and rowMetaInterface.searchValueData(subjectField[i]) returns null; thrown only when the subject field does not exist among r.getFieldNames().","commonSituations":"Renaming or deleting an upstream field without updating the Analytic Query step; the step sits on a hop whose stream no longer carries the field; case-sensitive field name mismatch; swapping a source table/CSV with different columns.","solutions":["Add the missing subject field upstream, or edit the Analytic Query step and pick an existing field from the printed list of available fields","Check for field-name case differences and exact spelling between the upstream step and the configured subject field","Run a 'Fields -> Update fields' / refresh field metadata in Spoon to re-sync the hop layout","If a source schema changed, re-map the step configuration to the new column names"],"exampleFix":"// before (field renamed upstream)\nsubjectField[i] = \"salary\";\n// after (match new upstream column)\nsubjectField[i] = \"salary_amount\";","handlingStrategy":"validation","validationCode":"// Before executing, check that all subject fields exist on the hop\nRowMetaInterface rmi = prevStepMeta.getStepMetaInterface().getFields(\n  new RowMeta(), null, null, null, null, null, null);\nfor (String subject : analyticQueryMeta.getSubjectField()) {\n  if (subject != null && rmi.searchValueMeta(subject) == null) {\n    throw new IllegalStateException(\"Missing subject field: \" + subject);\n  }\n}","typeGuard":"boolean fieldExists(RowMetaInterface rmi, String name) { return name != null && rmi.searchValueMeta(name) != null; }","tryCatchPattern":"try {\n  transMeta.prepareExecution(new String[0]);\n} catch (KettleStepException e) {\n  if (e.getMessage().contains(\"SubjectFieldNotFound\") || e.getMessage().contains(\"subject field\")) {\n    log.error(\"Configure the Analytic Query step with an existing field: \" + e.getMessage());\n  }\n  throw e;\n}","preventionTips":["After renaming/deleting any upstream field, refresh fields on downstream steps in Spoon","Use hop-level field propagation to keep step configs in sync","Run TransMeta.getStepFields()/check() programmatically in tests before production runs","Avoid case-sensitive field name drift by standardizing column naming"],"tags":["field-lookup","schema","row-metadata","kettle"],"backgroundTag":"resource-not-found","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"}