{"record":{"id":"971b09d9272c5500","repo":"apache/beam","slug":"cannot-create-reader-as-source-is-not-split-yet","errorCode":null,"errorMessage":"Cannot create reader as source is not split yet.","messagePattern":"Cannot create reader as source is not split yet\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/hadoop-format/src/main/java/org/apache/beam/sdk/io/hadoop/format/HadoopFormatIO.java","lineNumber":867,"sourceCode":"    InputFormat<?, ?> getInputFormat() {\n      return inputFormatObj;\n    }\n\n    @VisibleForTesting\n    void setInputFormatObj(InputFormat<?, ?> inputFormatObj) {\n      this.inputFormatObj = inputFormatObj;\n    }\n\n    @Override\n    public Coder<KV<K, V>> getOutputCoder() {\n      return KvCoder.of(keyCoder, valueCoder);\n    }\n\n    @Override\n    public BoundedReader<KV<K, V>> createReader(PipelineOptions options) throws IOException {\n      this.validate();\n      if (inputSplit == null) {\n        throw new IOException(\"Cannot create reader as source is not split yet.\");\n      } else {\n        createInputFormatInstance();\n        return new HadoopInputFormatReader<>(\n            this,\n            keyTranslationFunction,\n            valueTranslationFunction,\n            inputSplit,\n            inputFormatObj,\n            taskAttemptContext);\n      }\n    }\n\n    /**\n     * BoundedReader for Hadoop InputFormat source.\n     *\n     * @param <T1> Type of keys RecordReader emits.\n     * @param <T2> Type of values RecordReader emits.\n     */","sourceCodeStart":849,"sourceCodeEnd":885,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/hadoop-format/src/main/java/org/apache/beam/sdk/io/hadoop/format/HadoopFormatIO.java#L849-L885","documentation":"For a HadoopInputFormatBoundedSource created by split(), createReader() requires the inputSplit field to be set. Reading from the un-split root source is not supported, so it throws this IOException when inputSplit is null.","triggerScenarios":"Calling createReader() directly on the source produced by HadoopFormatIO.read() without first calling split() (or using a source that skipped computeSplitsIfNecessary).","commonSituations":"Custom runner code or tests that construct a BoundedSource and call createReader() without the split step; pipelines executed on runners that bypass Beam's split protocol.","solutions":["Always let Beam's runner split the source; do not call createReader() on the root source yourself","If testing manually, call source.split(desiredBundleSizeBytes, options) first and create a reader from a sub-source","Call computeSplitsIfNecessary() via split() before reader creation"],"exampleFix":"// before\nBoundedReader<KV<K,V>> r = source.createReader(options);\n// after\nfor (BoundedSource<KV<K,V>> s : source.split(64L<<20, options)) {\n  BoundedReader<KV<K,V>> r = s.createReader(options);\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static <T> boolean isSplitted(BoundedSource<T> src) {\n  return src instanceof HadoopFormatIO.HadoopInputFormatBoundedSource<?, ?>\n      && ((HadoopFormatIO.HadoopInputFormatBoundedSource<?, ?>) src).getClass();\n}\n// Prefer: only create readers from sources returned by split().","tryCatchPattern":"try {\n  BoundedReader<KV<K,V>> r = subSource.createReader(options);\n} catch (IOException e) {\n  if (e.getMessage().contains(\"source is not split yet\")) {\n    throw new IllegalStateException(\"Must call split() before createReader()\");\n  }\n  throw e;\n}","preventionTips":["Always follow the Beam protocol: split() then createReader() on a sub-source","In tests, call split() before createReader() instead of reading the root source","Never cache sources across phases where one is pre-split and one is not"],"tags":["hadoop","beam","invalid-state","reader"],"backgroundTag":"invalid-state-transition","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}