apache/seatunnel · error · IllegalArgumentException

Long value is out of range

Error message

Long value is out of range

What it means

DocumentDBItemDeserializer.checkedLong converts a BSON number to long and throws IllegalArgumentException when a double value exceeds the representable Long range (below -2^63 or above 2^63-1, including infinities). This avoids undefined casts and silent data corruption for BIGINT columns.

Source

Thrown at seatunnel-connectors-v2/connector-amazondocumentdb/src/main/java/org/apache/seatunnel/connectors/seatunnel/amazondocumentdb/serialize/DocumentDBItemDeserializer.java:150

                || (value.isDecimal128() && value.asDecimal128().getValue().isNaN());
    }

    private static int checkedInteger(BsonValue value, int minimum, int maximum) {
        long number = value.asNumber().longValue();
        if (number < minimum || number > maximum) {
            throw new IllegalArgumentException("Integer value is out of range");
        }
        return (int) number;
    }

    private static long checkedLong(BsonValue value) {
        if (value.isInt32() || value.isInt64()) {
            return value.asNumber().longValue();
        }
        if (value.isDouble()) {
            double number = value.asNumber().doubleValue();
            if (number < Long.MIN_VALUE || number > Long.MAX_VALUE) {
                throw new IllegalArgumentException("Long value is out of range");
            }
            return value.asNumber().longValue();
        }
        throw new IllegalArgumentException("Value is not a supported long");
    }

    /**
     * Applies the configured scale and rejects precision overflow instead of silently emitting
     * {@code null}, which would make malformed source data indistinguishable from BSON null.
     */
    private static BigDecimal convertDecimal(DecimalType type, BsonValue value) {
        Decimal128 decimal128 = value.asDecimal128().decimal128Value();
        if (!decimal128.isFinite()) {
            throw new IllegalArgumentException("Infinite Decimal128 values are not supported");
        }
        BigDecimal decimal =
                decimal128.bigDecimalValue().setScale(type.getScale(), RoundingMode.HALF_UP);
        if (decimal.precision() > type.getPrecision()) {

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Change the target column to DOUBLE/DECIMAL type instead of bigint for such large values.
  2. Clean or clamp the source data so values fit in long range.
  3. Add a match query to exclude documents with out-of-range doubles.

Example fix

// before
{"name": "measure", "type": "bigint"}   // double 1e30
// after
{"name": "measure", "type": "double"}
Defensive patterns

Strategy: validation

Validate before calling

if (bsonValue.isDouble()) {
    double d = bsonValue.asNumber().doubleValue();
    if (d < Long.MIN_VALUE || d > Long.MAX_VALUE || Double.isNaN(d) || Double.isInfinite(d)) {
        throw new IllegalArgumentException("double does not fit bigint column: " + d);
    }
}

Try / catch

try {
    long v = checkedLong(bsonValue);
} catch (IllegalArgumentException e) {
    log.error("Cannot read value as long", e);
}

Prevention

When it happens

Trigger: A BSON double field mapped to SeaTunnel BIGINT holds a value larger than Long.MAX_VALUE (e.g. 1e30) or smaller than Long.MIN_VALUE.

Common situations: Scientific/computed values stored as doubles cast to bigint in the schema; a field changed from small magnitudes to huge values upstream; NaN/Infinity doubles entering numeric columns.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


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