apache/iceberg · error · java.lang.UnsupportedOperationException
Failed to read Variant %s of type %s as int
Error message
Failed to read Variant %s of type %s as int
What it means
intValue extracts an int from a Variant only when its Variant.Type is TINYINT, SMALLINT, or INT; any other physical type (e.g. BIGINT, DOUBLE, STRING) throws this UnsupportedOperationException via errMsg(variant, "int").
Source
Thrown at flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/data/VariantRowDataWrapper.java:255
}
int arraySize = BinaryVariantAccessorUtils.arraySize(variant);
Object[] elements = new Object[arraySize];
for (int i = 0; i < arraySize; i++) {
Variant element = variant.getElement(i);
elements[i] = elementValue(element, innerElementType);
}
return new GenericArrayData(elements);
}
private static int intValue(Variant variant) {
return switch (variant.getType()) {
case TINYINT -> variant.getByte();
case SMALLINT -> variant.getShort();
case INT -> variant.getInt();
default -> throw new UnsupportedOperationException(errMsg(variant, "int"));
};
}
private static long longValue(Variant variant) {
return switch (variant.getType()) {
case TINYINT -> variant.getByte();
case SMALLINT -> variant.getShort();
case INT -> variant.getInt();
case BIGINT -> variant.getLong();
default -> throw new UnsupportedOperationException(errMsg(variant, "long"));
};
}
private static double doubleValue(Variant variant) {
return switch (variant.getType()) {
case FLOAT -> variant.getFloat();
case DOUBLE -> variant.getDouble();
default -> throw new UnsupportedOperationException(errMsg(variant, "double"));View on GitHub (pinned to 86d9c8fc54)
Solutions
- Check variant.getType() at the source and ensure the writer emits an int-width value
- Align the Flink RowType column to INT (not BIGINT) or read with getLong instead
- Coerce the variant upstream (cast the value) before writing it into the variant column
Example fix
// before row.getInt(3); // variant is BIGINT -> throws // after long v = row.getLong(3); // matches BIGINT variant
Defensive patterns
Strategy: try-catch
Validate before calling
if (variant.getType() != Variant.Type.TINYINT
&& variant.getType() != Variant.Type.SMALLINT
&& variant.getType() != Variant.Type.INT) { /* coerce or use getLong */ } Type guard
boolean isIntWidth(Variant v) {
return v.getType() == Variant.Type.TINYINT || v.getType() == Variant.Type.SMALLINT
|| v.getType() == Variant.Type.INT;
} Try / catch
try { int i = row.getInt(pos); }
catch (UnsupportedOperationException e) { long l = row.getLong(pos); int i = (int) l; } Prevention
- Match writer variant physical types to declared column types
- Avoid evolving int columns to long without updating readers
- Log variant.getType() when diagnosing type mismatches
When it happens
Trigger: Calling getInt on a VariantRowDataWrapper whose column holds a Variant of an incompatible type, or elementValue widening an int-typed field whose variant is e.g. a long.
Common situations: Schema/variant type mismatch after table evolution (column changed from int to long) or writers producing variants of the wrong physical type.
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
- Failed to read Variant %s of type %s as long
- Failed to read Variant %s of type %s as double
- Failed to read Variant %s of type %s as timestamp
- errMsg(variant, "int")
- errMsg(variant, "long")
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/26d243d1ffd2ccd2.
Report an issue: GitHub.