{"record":{"id":"8d538ce1cb252e81","repo":"apache/flink","slug":"number-of-input-splits-has-to-be-at-least-1","errorCode":null,"errorMessage":"Number of input splits has to be at least 1.","messagePattern":"Number of input splits has to be at least 1\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/io/FileInputFormat.java","lineNumber":536,"sourceCode":"\n    @Override\n    public LocatableInputSplitAssigner getInputSplitAssigner(FileInputSplit[] splits) {\n        return new LocatableInputSplitAssigner(splits);\n    }\n\n    /**\n     * Computes the input splits for the file. By default, one file block is one split. If more\n     * splits are requested than blocks are available, then a split may be a fraction of a block and\n     * splits may cross block boundaries.\n     *\n     * @param minNumSplits The minimum desired number of file splits.\n     * @return The computed file splits.\n     * @see org.apache.flink.api.common.io.InputFormat#createInputSplits(int)\n     */\n    @Override\n    public FileInputSplit[] createInputSplits(int minNumSplits) throws IOException {\n        if (minNumSplits < 1) {\n            throw new IllegalArgumentException(\"Number of input splits has to be at least 1.\");\n        }\n\n        // take the desired number of splits into account\n        minNumSplits = Math.max(minNumSplits, this.numSplits);\n\n        final List<FileInputSplit> inputSplits = new ArrayList<FileInputSplit>(minNumSplits);\n\n        // get all the files that are involved in the splits\n        List<FileStatus> files = new ArrayList<>();\n        long totalLength = 0;\n\n        for (Path path : getFilePaths()) {\n            final FileSystem fs = path.getFileSystem();\n            final FileStatus pathFile = fs.getFileStatus(path);\n\n            if (pathFile.isDir()) {\n                totalLength += addFilesInDir(path, files, true);\n            } else {","sourceCodeStart":518,"sourceCodeEnd":554,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/io/FileInputFormat.java#L518-L554","documentation":"Thrown by FileInputFormat.createInputSplits(int minNumSplits) when the requested minimum number of file splits is less than 1. The method computes splits by dividing file blocks; at least one split is always required to process data. This is an input contract violation: a job with zero or negative effective parallelism cannot read its input.","triggerScenarios":"Calling createInputSplits(0) or with a negative value. In practice the framework derives minNumSplits from the source operator's parallelism, so this fires when job parallelism resolves to less than 1, when an InputFormatSourceFunction is wired with parallelism 0, or when a custom InputFormat implementation forwards a bad split count.","commonSituations":"Setting execution environment parallelism to 0 via env.setParallelism(0); a DataSource with a degenerate parallelism config; unit tests that invoke createInputSplits directly with a placeholder value of 0; programmatic graph builders that miscompute subtask counts.","solutions":["Ensure the source operator and environment parallelism are >= 1; check env.getParallelism() and any setParallelism(...) calls on the data source.","If you call createInputSplits directly (rare, custom execution), pass a positive int such as Math.max(1, desiredSplits).","Audit the job graph / ExecutionConfig to confirm no component overrides parallelism to 0 for this operator."],"exampleFix":"// before\nenv.setParallelism(0);\nDataSet<String> data = env.readFile(format, path);\n\n// after\nenv.setParallelism(4);\nDataSet<String> data = env.readFile(format, path);","handlingStrategy":"validation","validationCode":"// Validate parallelism/split count before the job runs\nint parallelism = env.getParallelism();\nif (parallelism < 1) {\n    throw new IllegalStateException(\"Job parallelism must be >= 1 for file sources, got \" + parallelism);\n}\n// If invoking createInputSplits directly:\nint minSplits = Math.max(1, desiredSplits);\nFileInputSplit[] splits = format.createInputSplits(minSplits);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never set env or source parallelism to 0.","Assert env.getParallelism() >= 1 in a pre-submit hook.","When calling createInputSplits directly, clamp the value with Math.max(1, n)."],"tags":["flink","file-input","input-splits","parallelism","configuration"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}