apache/seatunnel · error · IllegalArgumentException

Cannot convert to float:

Error message

Cannot convert to float: 

What it means

Thrown by RowConverter.convertFloat when an Iceberg field value being converted to a float is neither a Number nor a parseable String; the message names the value's Java class, identifying the incompatible source type.

Source

Thrown at seatunnel-connectors-v2/connector-iceberg/src/main/java/org/apache/seatunnel/connectors/seatunnel/iceberg/data/RowConverter.java:305

        throw new IllegalArgumentException("Cannot convert to int: " + value.getClass().getName());
    }

    protected long convertLong(Object value) {
        if (value instanceof Number) {
            return ((Number) value).longValue();
        } else if (value instanceof String) {
            return Long.parseLong((String) value);
        }
        throw new IllegalArgumentException("Cannot convert to long: " + value.getClass().getName());
    }

    protected float convertFloat(Object value) {
        if (value instanceof Number) {
            return ((Number) value).floatValue();
        } else if (value instanceof String) {
            return Float.parseFloat((String) value);
        }
        throw new IllegalArgumentException(
                "Cannot convert to float: " + value.getClass().getName());
    }

    protected double convertDouble(Object value) {
        if (value instanceof Number) {
            return ((Number) value).doubleValue();
        } else if (value instanceof String) {
            return Double.parseDouble((String) value);
        }
        throw new IllegalArgumentException(
                "Cannot convert to double: " + value.getClass().getName());
    }

    protected BigDecimal convertDecimal(Object value, Types.DecimalType type) {
        BigDecimal bigDecimal;
        if (value instanceof BigDecimal) {
            bigDecimal = (BigDecimal) value;
        } else if (value instanceof Number) {

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Ensure float fields carry numeric values or numeric strings.
  2. Pre-cast in a transform (CAST(col AS FLOAT)).
  3. Change the Iceberg column type to match actual data.
  4. Catch IllegalArgumentException and skip/redirect bad records.

Example fix

// before
row.setField(0, "1.5x"); // throws NumberFormatException / or non-number object
// after
row.setField(0, 1.5f);
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(v instanceof Number) && !(v instanceof String)) { throw new IllegalArgumentException("float field expects Number/String, got " + v.getClass()); }

Type guard

Float safeToFloat(Object v) { if (v instanceof Number) return ((Number) v).floatValue(); if (v instanceof String) return Float.valueOf((String) v); return null; }

Try / catch

try { value = convertFloat(raw); } catch (IllegalArgumentException e) { log.warn("Bad float value: {}", e.getMessage()); }

Prevention

When it happens

Trigger: convertValue targeting an Iceberg FloatType field receives a non-numeric, non-string value.

Common situations: Boolean or byte[] data landing in FLOAT columns; CSV readers inferring wrong types; upstream transforms emitting objects instead of primitives.

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/d3cb775901144c59. Report an issue: GitHub.