apache/iceberg · warning · UnsupportedOperationException

does not implement length

Error message

<className> does not implement length

What it means

RollingFileWriter.length() is not supported: the rolling wrapper does not track the size of its underlying writers and only subclasses that override length() (e.g. file-formats that expose the output file length) support it. Calling it on a base RollingFileWriter instance throws UnsupportedOperationException.

Solutions

  1. Close the rolling writer and call length() on the resulting OutputFile instead (currentFile.encryptingOutputFile().length()).
  2. Track currentFileRows() as a proxy if row count, not byte length, is needed.
  3. Override length() in custom RollingFileWriter subclasses to delegate to the current writer.
  4. Guard the call with instanceof/feature check before invoking length().

Example fix

// before
long size = rollingWriter.length(); // throws UnsupportedOperationException

// after
rollingWriter.close();
long size = rollingWriter.result().length(); // use completed files' lengths
Defensive patterns

Strategy: validation

Validate before calling

long size(Writer<?> w) {
  if (w instanceof RollingFileWriter && !(w.getClass().getMethod("length").getDeclaringClass()
      .isAssignableFrom(RollingFileWriter.class) && w.getClass() != RollingFileWriter.class)) {
    throw new UnsupportedOperationException("length() not supported by " + w.getClass().getName());
  }
  return w.length();
}

Type guard

// check subclass actually overrides length()
boolean supportsLength(Writer<?> w) {
  try {
    return w.getClass().getMethod("length").getDeclaringClass() != RollingFileWriter.class;
  } catch (NoSuchMethodException e) { return false; }
}

Try / catch

try {
  size = writer.length();
} catch (UnsupportedOperationException e) {
  size = -1; // fall back to row count: writer.currentFileRows()
}

Prevention

When it happens

Trigger: Invoking RollingFileWriter.length() (or code paths such as metadata/statistics collection that query the writer's length) on a subclass that has not overridden length().

Common situations: Computing file sizes for metrics or statistics before the file is closed; custom RollingFileWriter subclasses not overriding length(); engine integrations that assume every writer reports a length.

Related errors


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

Appendix: source

Thrown at core/src/main/java/org/apache/iceberg/io/RollingFileWriter.java:88

  protected PartitionSpec spec() {
    return spec;
  }

  protected StructLike partition() {
    return partition;
  }

  public CharSequence currentFilePath() {
    return currentFile.encryptingOutputFile().location();
  }

  public long currentFileRows() {
    return currentFileRows;
  }

  @Override
  public long length() {
    throw new UnsupportedOperationException(
        this.getClass().getName() + " does not implement length");
  }

  @Override
  public void write(T row) {
    currentWriter.write(row);
    currentFileRows++;

    if (shouldRollToNewFile()) {
      closeCurrentWriter();
      openCurrentWriter();
    }
  }

  private boolean shouldRollToNewFile() {
    return currentFileRows % ROWS_DIVISOR == 0 && currentWriter.length() >= targetFileSizeInBytes;
  }

View on GitHub (pinned to 86d9c8fc54)