apache/seatunnel · error · UnsupportedOperationException

Unsupported convert ${value.getClass()} to Long

Error message

Unsupported convert ${value.getClass()} to Long

What it means

Thrown by BasicDataConverter.convertLong(Object value) when the value is neither LocalDate nor LocalDateTime (and not a Number/String handled by default branches). It is the typeDefine-less variant of error 102; the message reports the actual class that could not be converted to a long.

Source

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

        if (value instanceof String) {
            return convertLong((String) value);
        }
        if (value instanceof Time) {
            return convertLong((Time) value);
        }
        if (value instanceof LocalTime) {
            return convertLong((LocalTime) value);
        }
        if (value instanceof Date) {
            return convertLong((Date) value);
        }
        if (value instanceof LocalDate) {
            return convertLong((LocalDate) value);
        }
        if (value instanceof LocalDateTime) {
            return convertLong((LocalDateTime) value);
        }
        throw new UnsupportedOperationException(
                "Unsupported convert " + value.getClass() + " to Long");
    }

    default long convertLong(Number value) {
        return value.longValue();
    }

    default long convertLong(String value) {
        return Long.parseLong(value);
    }

    default long convertLong(Time value) {
        return value.toLocalTime().toSecondOfDay();
    }

    default long convertLong(LocalTime value) {
        return value.toSecondOfDay();
    }

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Convert the value to a Number, LocalDate or LocalDateTime before calling convertLong (e.g. Long.parseLong for numeric strings)
  2. Fix the catalog/schema so the field type matches what the source actually produces
  3. Override convertLong(Object) in a custom converter implementation to handle the reported class

Example fix

// before
long l = converter.convertLong(row.getField(0)); // String timestamp throws
// after
Object v = row.getField(0);
long l = (v instanceof String) ? Long.parseLong((String) v) : converter.convertLong(v);
Defensive patterns

Strategy: type-guard

Validate before calling

Object v = row.getField(0);
if (!(v instanceof Number) && !(v instanceof LocalDate) && !(v instanceof LocalDateTime)) {
    throw new IllegalArgumentException("Value " + v.getClass() + " cannot be converted to long");
}

Type guard

static boolean isLongConvertible(Object v) {
    return v instanceof Number || v instanceof LocalDate || v instanceof LocalDateTime;
}

Try / catch

try {
    l = converter.convertLong(value);
} catch (UnsupportedOperationException e) {
    LOG.warn("Cannot convert {} to long", value.getClass());
    l = 0L;
}

Prevention

When it happens

Trigger: Calling the convertLong(Object) overload with String, byte[], java.util.Date, Boolean or arbitrary objects while expecting a BIGINT-compatible value.

Common situations: Direct use of the convenience overload in custom code; schema drift where a timestamp column changed to BIGINT in the sink but the source still emits String/Date objects; raw deserialization feeding numeric columns.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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