deeplearning4j/deeplearning4j · error · UnsupportedOperationException

Tried to combine() incompatible

Error message

Tried to combine() incompatible <accu class name> operator where org.datavec.api.transform.ops.LongWritableOp expected

What it means

LongWritableOp.combine() can only merge state with another LongWritableOp accumulator, because the underlying per-column reduce operation expects Long values. When handed a different IAggregableReduceOp implementation (typically from combining reductions over mismatched columns), it throws UnsupportedOperationException naming both classes. This is a programming/alignment bug, not a data problem.

Solutions

  1. Check that every accumulator you combine was produced for the same column type as the target LongWritableOp (Long/Int columns only).
  2. Inspect the accu class name in the message and trace where that accumulator was created; fix the column-to-op mapping at creation time (see AggregableReductionUtils.reduceColumn).
  3. If you need to combine heterogeneous accumulators, combine them per-column first (each column's ops combined only with matching-type ops), then assemble results.

Example fix

// before: positional combine over mixed columns
for (int i = 0; i < ops.size(); i++) ops.get(0).combine(ops.get(i));
// after: only combine same-typed accumulators
for (IAggregableReduceOp<Writable, T> op : ops)
    if (op.getClass() == ops.get(0).getClass()) ops.get(0).combine(op);
Defensive patterns

Strategy: validation

Validate before calling

Schema s = transformProcess.getFinalSchema();
// ensure the column being reduced is Integer/Long before building LongWritableOp-based reducers
if (!metaData.getColumnType().equals(ColumnType.Integer) && !metaData.getColumnType().equals(ColumnType.Long))
    throw new IllegalArgumentException("Expected Integer/Long column, got " + metaData.getColumnType());

Type guard

if (!(accu instanceof LongWritableOp)) throw new IllegalArgumentException("cannot combine " + accu.getClass().getName());

Try / catch

try { op.combine(accu); } catch (UnsupportedOperationException e) { log.error("Incompatible accumulator: {}", e.getMessage()); throw e; }

Prevention

When it happens

Trigger: Calling combine(accu) on a LongWritableOp with an accumulator of any other class, e.g. combining reduce results from a String column with those from a Long column, or mixing AggregableReductionUtils outputs across column types (common in distributed/spark aggregation combine phases).

Common situations: Custom reduce pipelines where column metadata and the reduce-op list get out of sync; parallel aggregation where reducers are combined positionally but columns were reordered; hand-rolled IAggregableReduceOp implementations passed to an existing reduce.

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 deeplearning4j/deeplearning4j@4c22ac5fe4 (2026-09-07). Data as JSON: /api/errors/f4bbad0ab99747f8. Report an issue: GitHub.

Appendix: source

Thrown at datavec/datavec-api/src/main/java/org/datavec/api/transform/ops/LongWritableOp.java:40

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import org.datavec.api.writable.Writable;

@AllArgsConstructor
@Data
public class LongWritableOp<T> implements IAggregableReduceOp<Writable, T> {

    @Getter
    private IAggregableReduceOp<Long, T> operation;

    @Override
    public <W extends IAggregableReduceOp<Writable, T>> void combine(W accu) {
        if (accu instanceof LongWritableOp)
            operation.combine(((LongWritableOp) accu).getOperation());
        else
            throw new UnsupportedOperationException("Tried to combine() incompatible " + accu.getClass().getName()
                            + " operator where " + this.getClass().getName() + " expected");
    }

    @Override
    public void accept(Writable writable) {
        operation.accept(writable.toLong());
    }

    @Override
    public T get() {
        return operation.get();
    }
}

View on GitHub (pinned to 4c22ac5fe4)