apache/iceberg · error · UnsupportedOperationException

Streaming writes are not supported for rewrites

Error message

Streaming writes are not supported for rewrites

What it means

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.

Solutions

  1. Use toBatch()/asRewrite(groupId) and execute rewrites as batch Spark actions, not streaming queries
  2. For streaming ingestion, use the normal append SparkWrite (toAppend/toStreaming) instead of the rewrite builder
  3. Separate maintenance (compaction/rewrites via procedures) from streaming write paths in your pipeline

Example fix

// before
StreamingWrite w = rewriteBuilder.toStreaming();
// after
BatchWrite w = rewriteBuilder.toBatch(); // run as a batch job
Defensive patterns

Strategy: validation

Validate before calling

if (isStreamingQuery) {
  throw new IllegalArgumentException("Rewrite writes are batch-only; use toBatch()");
}

Type guard

boolean isBatchOnly = builder instanceof RewriteWriteBuilderHolder;

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/af73713dd3993166. Report an issue: GitHub.

Appendix: source

Thrown at spark/v4.2/spark/src/main/java/org/apache/iceberg/spark/source/SparkRewriteWriteBuilder.java:82

    return new SparkWrite(
        spark,
        table,
        null /* main branch */,
        writeConf,
        info,
        appId,
        writeSchema,
        info.schema(),
        writeConf.writeRequirements()) {

      @Override
      public BatchWrite toBatch() {
        return asRewrite(groupId);
      }

      @Override
      public StreamingWrite toStreaming() {
        throw new UnsupportedOperationException("Streaming writes are not supported for rewrites");
      }
    };
  }

  private Schema validateWriteSchema() {
    Schema writeSchema = SparkSchemaUtil.convert(schema, info.schema(), caseSensitive);
    TypeUtil.validateWriteSchema(schema, writeSchema, checkNullability, checkOrdering);
    return writeSchema;
  }
}

View on GitHub (pinned to 86d9c8fc54)