apache/iceberg · error · UnsupportedOperationException
Failed to read Variant
Error message
Failed to read Variant %s of type %s as %s
What it means
VariantRowDataWrapper.intValue narrows a Variant to an int, accepting TINYINT, SMALLINT and INT variants; anything else throws UnsupportedOperationException with errMsg(variant, "int"): "Failed to read Variant <value> of type <type> as int". Raised when the Variant's actual type cannot losslessly be read as an int.
Solutions
- Declare the Flink field as BIGINT (and use getLong) if values exceed int range.
- Fix the writer so Variant values written for int columns are of type INT.
- Cast the Variant value in the query to a numeric type before int access.
Example fix
// before
DataTypes.FIELD("n", DataTypes.INT()) // variant holds BIGINT
// after
DataTypes.FIELD("n", DataTypes.BIGINT()) Defensive patterns
Strategy: validation
Validate before calling
Variant v = ...;
if (!(v.getType() == Variant.Type.TINYINT || v.getType() == Variant.Type.SMALLINT || v.getType() == Variant.Type.INT)) {
throw new IllegalArgumentException("Variant not int-typed: " + v.getType());
} Type guard
boolean isIntVariant(Variant v) {
switch (v.getType()) {
case TINYINT: case SMALLINT: case INT: return true;
default: return false;
}
} Try / catch
try {
int i = rowData.getInt(pos);
} catch (UnsupportedOperationException e) {
// widen the column to BIGINT or convert the variant value upstream
} Prevention
- Match Flink column LogicalType to the Variant value type written.
- Use BIGINT for values that may exceed int range.
- Validate Variant types in a test pipeline before production reads.
When it happens
Trigger: getInt(pos) or elementValue(...) with an INT LogicalType encountering a Variant of type BIGINT, DOUBLE, STRING, BOOLEAN, etc.
Common situations: Schema/type mismatch where the Flink column declares INT but the stored Variant holds a wider number or a string; mixed-typed arrays/maps with int element declarations.
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
- errMsg(variant, "double")
- errMsg(variant, "int")
- errMsg(variant, "long")
- errMsg(variant, "timestamp")
- Failed to read Variant
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/85247dc54a84358b.
Report an issue: GitHub.
Appendix: source
Thrown at flink/v2.3/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)