apache/iceberg · error · IllegalArgumentException

Cannot convert to float

Error message

Cannot convert to float: ${value.getClass().getName()}

What it means

Conversion failure in RecordConverter.convertFloat: the Kafka Connect value for a float-typed field is neither a Number nor a String (the two accepted coercions). The appended class name is the value's runtime type; it signals a schema mismatch between the source record and the Iceberg table column.

Solutions

  1. Send numeric or numeric-parsable-string values for float fields.
  2. Change the Iceberg column type to match the actual value type.
  3. Normalize the value with an SMT before the sink connector.
  4. Catch IllegalArgumentException and send the record to a DLQ.

Example fix

// before
record.set("ratio", "N/A"); // non-numeric string? no — fails earlier; here: record.set("ratio", true);
// after
record.set("ratio", 1.0f); // or change column to BOOLEAN
Defensive patterns

Strategy: validation

Validate before calling

Object v = record.get("ratio");
if (!(v instanceof Number) && !(v instanceof String)) {
  throw new IllegalArgumentException("ratio must be numeric, got " + v.getClass().getSimpleName());
}

Type guard

boolean isFloatConvertible(Object v) {
  return v instanceof Number || v instanceof String;
}

Try / catch

try {
  sink.write(record);
} catch (IllegalArgumentException e) {
  if (e.getMessage() != null && e.getMessage().contains("Cannot convert to float")) {
    sendToDlq(record, e);
  } else throw e;
}

Prevention

When it happens

Trigger: A field mapped to an Iceberg FloatType column holding a Boolean, byte[], Map, List, or other non-numeric non-string value.

Common situations: Float columns fed boolean JSON values; misconfigured schema mapping; producers sending objects where float is declared.

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/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/ac65dd5290327e3a. Report an issue: GitHub.

Appendix: source

Thrown at kafka-connect/kafka-connect/src/main/java/org/apache/iceberg/connect/data/RecordConverter.java:447

    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, DecimalType type) {
    BigDecimal bigDecimal;
    if (value instanceof BigDecimal) {
      bigDecimal = (BigDecimal) value;
    } else if (value instanceof Number) {
      Number num = (Number) value;
      Double dbl = num.doubleValue();

View on GitHub (pinned to 86d9c8fc54)