{"record":{"id":"af73713dd3993166","repo":"apache/iceberg","slug":"streaming-writes-are-not-supported-for-rewrites-af7371","errorCode":null,"errorMessage":"Streaming writes are not supported for rewrites","messagePattern":"Streaming writes are not supported for rewrites","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/source/SparkRewriteWriteBuilder.java","lineNumber":82,"sourceCode":"    return new SparkWrite(\n        spark,\n        table,\n        null /* main branch */,\n        writeConf,\n        info,\n        appId,\n        writeSchema,\n        info.schema(),\n        writeConf.writeRequirements()) {\n\n      @Override\n      public BatchWrite toBatch() {\n        return asRewrite(groupId);\n      }\n\n      @Override\n      public StreamingWrite toStreaming() {\n        throw new UnsupportedOperationException(\"Streaming writes are not supported for rewrites\");\n      }\n    };\n  }\n\n  private Schema validateWriteSchema() {\n    Schema writeSchema = SparkSchemaUtil.convert(schema, info.schema(), caseSensitive);\n    TypeUtil.validateWriteSchema(schema, writeSchema, checkNullability, checkOrdering);\n    return writeSchema;\n  }\n}\n","sourceCodeStart":64,"sourceCodeEnd":93,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/source/SparkRewriteWriteBuilder.java#L64-L93","documentation":"Rewrite writes (iceberg.system.rewrite_data_files / rewrite position deletes, i.e. asRewrite batch writes) are batch-only. SparkWriteBuilder's toStreaming() throws UnsupportedOperationException because streaming progress cannot be checkpointed against a rewrite operation that replaces files transactionally.","triggerScenarios":"Calling toStreaming() on the anonymous SparkWriteBuilder returned for rewrite operations — e.g. a Spark streaming query or DataStreamWriter configured to write via a rewrite write builder.","commonSituations":"Passing rewrite operations into a streaming sink; custom maintenance tooling that wraps rewrites in a StreamingWrite; API misuse where asRewrite(groupId) output is fed to Spark streaming execution.","solutions":["Use toBatch()/asRewrite(groupId) and execute rewrites as batch Spark actions, not streaming queries","For streaming ingestion, use the normal append SparkWrite (toAppend/toStreaming) instead of the rewrite builder","Separate maintenance (compaction/rewrites via procedures) from streaming write paths in your pipeline"],"exampleFix":"// before\nStreamingWrite w = rewriteBuilder.toStreaming();\n// after\nBatchWrite w = rewriteBuilder.toBatch(); // run as a batch job","handlingStrategy":"validation","validationCode":"if (isStreamingQuery) {\n  throw new IllegalArgumentException(\"Rewrite writes are batch-only; use toBatch()\");\n}","typeGuard":"boolean isBatchOnly = builder instanceof RewriteWriteBuilderHolder;","tryCatchPattern":null,"preventionTips":["Never feed rewrite write builders into streaming sinks","Run compaction/rewrites as scheduled batch jobs via procedures","Use toAppend/toStreaming builders for streaming ingestion"],"tags":["spark","streaming","rewrite"],"backgroundTag":"unsupported-operation","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}