apache/seatunnel · error · IllegalArgumentException

The size of collection is not equal to the size of row type

Error message

The size of collection is not equal to the size of row type

What it means

When convertRow receives a Collection (not already a SeaTunnelRow), it builds a SeaTunnelRow positionally from the collection's elements. This IllegalArgumentException is thrown when collection.size() does not equal typeDefine.getTotalFields(), because the fields could not be mapped one-to-one onto the row schema.

Source

Thrown at seatunnel-api/src/main/java/org/apache/seatunnel/api/table/converter/BasicDataConverter.java:211

        throw new UnsupportedOperationException(
                "Unsupported convert " + value.getClass() + " to Array, typeDefine: " + typeDefine);
    }

    default SeaTunnelRow convertRow(T typeDefine, Column columnDefine, Object value)
            throws UnsupportedOperationException {
        return convertRow((SeaTunnelRowType) columnDefine.getDataType(), value);
    }

    default SeaTunnelRow convertRow(SeaTunnelRowType typeDefine, Object value)
            throws UnsupportedOperationException {
        if (value instanceof SeaTunnelRow) {
            return (SeaTunnelRow) value;
        }
        if (value instanceof Collection) {
            Collection collection = (Collection) value;
            if (collection.size() != typeDefine.getTotalFields()) {
                throw new IllegalArgumentException(
                        "The size of collection is not equal to the size of row type");
            }

            Object[] array = new Object[collection.size()];
            int i = 0;
            for (Iterator iterator = collection.iterator(); iterator.hasNext(); i++) {
                Object object = iterator.next();
                SeaTunnelDataType<?> type = typeDefine.getFieldType(i);
                array[i] = convert(type, object);
            }
            return new SeaTunnelRow(array);
        }
        if (value instanceof Map) {
            Map map = (Map) value;

            Object[] array = new Object[typeDefine.getTotalFields()];
            for (int i = 0; i < typeDefine.getTotalFields(); i++) {
                String key = typeDefine.getFieldName(i);

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Make the collection size match the SeaTunnelRowType field count — add missing values or pad with nulls intentionally.
  2. Update the SeaTunnelRowType (CatalogTable schema) to reflect the actual number of fields in the data.
  3. Log/inspect the collection contents to find the extra or missing field, then fix the producing code.
  4. If fields are misaligned rather than missing, reorder the collection to match the declared field order.

Example fix

// before
converter.convertRow(rowType, column, Arrays.asList("a", 1)); // rowType has 3 fields
// after
converter.convertRow(rowType, column, Arrays.asList("a", 1, null)); // pad missing field with null
Defensive patterns

Strategy: validation

Validate before calling

if (value instanceof Collection) {
    if (((Collection<?>) value).size() != rowType.getTotalFields()) {
        throw new IllegalArgumentException("Collection size " + ((Collection<?>) value).size()
            + " != row type fields " + rowType.getTotalFields());
    }
}

Try / catch

try {
    return converter.convertRow(rowType, column, collection);
} catch (IllegalArgumentException e) {
    LOG.error("Row arity mismatch: {}", e.getMessage());
    throw new IOException("Schema/data arity mismatch", e);
}

Prevention

When it happens

Trigger: Calling convertRow(rowType, column, value) — directly or through convert(...) with a ROW SqlType — with a List whose element count differs from the number of fields declared in the SeaTunnelRowType.

Common situations: Upstream added/removed a column but the declared row type was not updated; mapping a SELECT with fewer columns than the target table schema; off-by-one from including or excluding an extra value like a version or timestamp column.

Related errors


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/05698a61601bb508. Report an issue: GitHub.