{"record":{"id":"21717785d83e2d70","repo":"pentaho/pentaho-kettle","slug":"dimensionlookup-exception-errordetectedingettingkey","errorCode":null,"errorMessage":"DimensionLookup.Exception.ErrorDetectedInGettingKey","messagePattern":"DimensionLookup\\.Exception\\.ErrorDetectedInGettingKey","errorType":"exception","errorClass":"KettleStepException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/dimensionlookup/DimensionLookup.java","lineNumber":408,"sourceCode":"      //\n      int index = data.preloadCache.lookupRow( lookupRow );\n      if ( index >= 0 ) {\n        returnRow = data.preloadCache.getRow( index );\n      } else {\n        returnRow = null; // Nothing found!\n      }\n\n    } else {\n      lookupRow = new Object[ data.lookupRowMeta.size() ];\n      lookupRowMeta = data.lookupRowMeta;\n\n      // Construct the lookup row...\n      //\n      for ( int i = 0; i < meta.getKeyStream().length; i++ ) {\n        try {\n          lookupRow[ i ] = row[ data.keynrs[ i ] ];\n        } catch ( Exception e ) { // TODO : remove exception??\n          throw new KettleStepException(\n            BaseMessages\n              .getString(\n                PKG,\n                \"DimensionLookup.Exception.ErrorDetectedInGettingKey\", i + \"\", data.keynrs[ i ] + \"/\" + rowMeta.size(),\n                rowMeta.getString( row ) ) );\n        }\n      }\n\n      lookupRow[ meta.getKeyStream().length ] = valueDate; // ? >= date_from\n      lookupRow[ meta.getKeyStream().length + 1 ] = valueDate; // ? < date_to\n\n      if ( isDebug() ) {\n        logDebug( BaseMessages.getString( PKG, \"DimensionLookup.Log.LookupRow\" )\n          + data.lookupRowMeta.getString( lookupRow ) );\n      }\n\n      // Do the lookup and see if we can find anything in the database.\n      // But before that, let's see if we can find anything in the cache","sourceCodeStart":390,"sourceCodeEnd":426,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/dimensionlookup/DimensionLookup.java#L390-L426","documentation":"While constructing the lookup row, the step tries to copy each key value from the input row using precomputed keynrs indexes. If reading row[data.keynrs[i]] fails (index out of range or value conversion problem), it throws a KettleStepException reporting the key index i, the failing position keynrs[i]/row size, and the whole row as a string.","triggerScenarios":"lookupValues builds lookupRow for every incoming row; a mismatch between the row metadata captured at init and the actual row length (e.g. keynrs points past rowMeta.size()) causes the exception.","commonSituations":"Upstream step changed the number/order of fields after step initialization (dynamic schemas); two hops or modified rows injected mid-transformation; hand-edited transformation XML leaving stale keynrs indexes.","solutions":["Re-save/re-run the transformation so the step re-initializes keynrs against the current row layout","Ensure no upstream step changes the field count/order dynamically between init and execution","Verify the key fields in the Dimension Lookup dialog match the actual incoming fields","Log the incoming row before the step (e.g. with a 'Stream Lookup'/'Write to Log' step) to see the actual row shape"],"exampleFix":"// before: upstream Select Values removes a key field conditionally\n// row has 4 fields, keynrs[2]=5 -> index out of range\n// after: make field layout stable (always emit all fields, use null when absent),\n// or re-map keys in the dialog so indexes resolve within rowMeta.size()","handlingStrategy":"type-guard","validationCode":"// confirm row layout hasn't changed since step init\nif (rowMeta.size() < expectedMinFieldCount) {\n  throw new IllegalStateException(\"Input row narrower than expected; check upstream steps\");\n}","typeGuard":"boolean keyIndexesInBounds(int[] keynrs, int rowSize) {\n  for (int k : keynrs) if (k < 0 || k >= rowSize) return false;\n  return true;\n}","tryCatchPattern":"try {\n  lookupValues(rowMeta, row);\n} catch (KettleStepException e) {\n  if (e.getMessage().contains(\"ErrorDetectedInGettingKey\")) {\n    logError(\"Row layout mismatch: \" + e.getMessage());\n  } else { throw e; }\n}","preventionTips":["Keep the upstream field layout stable; avoid conditionally removing fields","Re-run/save the transformation after any upstream field change so indexes are recomputed","Use Write-to-Log before the step to inspect actual row structure during development"],"tags":["etl","index-out-of-bounds","row-metadata"],"backgroundTag":"index-out-of-range","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"}