{"record":{"id":"e1f2cfa6697f8618","repo":"pentaho/pentaho-kettle","slug":"all-input-files-need-to-have-the-same-number-of-fields-file","errorCode":null,"errorMessage":"All input files need to have the same number of fields. File '{filename}' has {fieldCount} fields while the first file only had {firstFileFieldCount}","messagePattern":"All input files need to have the same number of fields\\. File '(.+?)' has (.+?) fields while the first file only had (.+?)","errorType":"exception","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/sasinput/SasInput.java","lineNumber":110,"sourceCode":"        metaStore );\n    }\n\n    String rawFilename = getInputRowMeta().getString( fileRowData, meta.getAcceptingField(), null );\n    final String filename =\n      KettleVFS.getFilename( KettleVFS.getInstance( getTransMeta().getBowl() ).getFileObject( rawFilename ) );\n\n    data.helper = new SasInputHelper( filename );\n    logBasic( BaseMessages.getString( PKG, \"SASInput.Log.OpenedSASFile\" ) + \" : [\" + data.helper + \"]\" );\n\n    // verify the row layout...\n    //\n    if ( data.fileLayout == null ) {\n      data.fileLayout = data.helper.getRowMeta();\n    } else {\n      // Verify that all files are of the same file format, this is a requirement...\n      //\n      if ( data.fileLayout.size() != data.helper.getRowMeta().size() ) {\n        throw new KettleException( \"All input files need to have the same number of fields. File '\"\n          + filename + \"' has \" + data.helper.getRowMeta().size() + \" fields while the first file only had \"\n          + data.fileLayout.size() );\n      }\n      for ( int i = 0; i < data.fileLayout.size(); i++ ) {\n        ValueMetaInterface first = data.fileLayout.getValueMeta( i );\n        ValueMetaInterface second = data.helper.getRowMeta().getValueMeta( i );\n        if ( !first.getName().equalsIgnoreCase( second.getName() ) ) {\n          throw new KettleException( \"Field nr \"\n            + i + \" in file '\" + filename + \"' is called '\" + second.getName() + \"' while it was called '\"\n            + first.getName() + \"' in the first file\" );\n        }\n        if ( first.getType() != second.getType() ) {\n          throw new KettleException( \"Field nr \"\n            + i + \" in file '\" + filename + \"' is of data type '\" + second.getTypeDesc() + \"' while it was '\"\n            + first.getTypeDesc() + \"' in the first file\" );\n        }\n      }\n    }","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/sasinput/SasInput.java#L92-L128","documentation":"KettleException thrown by the SAS Input step's processRow when a second (or later) SAS file has a different number of fields than the layout captured from the first file. The step requires all input files to share the same layout and also compares individual ValueMeta per field; it throws this message naming the offending file, its field count, and the first file's count.","triggerScenarios":"processRow processes multiple accepted SAS files: data.fileLayout is already set and data.helper.getRowMeta().size() differs from data.fileLayout.size(), so the format-uniformity guard throws before per-field comparison.","commonSituations":"Pointing the step at a directory/wildcard where some SAS files were exported with different schemas (extra or dropped columns); files from different SAS versions or tables mixed in one input; downstream consumers changed one file's export definition.","solutions":["Inspect the named file and compare its columns to the first file; add/remove columns so schemas match.","Split processing into multiple SAS Input steps (or transformations) grouped by schema, then merge downstream.","Use a wildcard/directory filter to exclude files with differing layouts.","Regenerate the outlier file from its SAS source with the same export definition as the others."],"exampleFix":"// before: wildcard mixes schemas\nsfr.setFileMask(\"*.sas7bdat\"); // File B has 12 fields vs File A's 10\n// after: separate by schema\nsfr.setFileMask(\"sales_*.sas7bdat\"); // second step handles returns_*.sas7bdat","handlingStrategy":"validation","validationCode":"// Pre-validate SAS file layouts before the transformation runs\nSasInputHelper helper = new SasInputHelper(new File(\"file.sas7bdat\"));\nint fields = helper.getRowMeta().size();\nif (fields != expectedFieldCount) {\n  throw new IllegalStateException(\"SAS file layout mismatch: \" + fields + \" vs \" + expectedFieldCount);\n}","typeGuard":"RowMetaInterface layout = data.helper.getRowMeta();\nif (layout == null || layout.size() == 0) { throw new IllegalStateException(\"SAS file produced an empty row layout\"); }","tryCatchPattern":"try {\n  step.run();\n} catch (KettleException e) {\n  if (e.getMessage().startsWith(\"All input files need to have the same number of fields\")) {\n    log.error(\"Schema mismatch across SAS files: {}\", e.getMessage());\n    // route offending file to a quarantine folder and re-run\n  }\n}","preventionTips":["Keep all SAS files in one input set exported with the identical column list.","Group files by schema and process each group in its own step.","Validate file layouts in a pre-check transformation before the main run.","Restrict wildcards/directories so only same-schema files are matched."],"tags":["kettle","sas-input","schema-mismatch","runtime"],"backgroundTag":"schema-validation-failed","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"}