{"record":{"id":"5ecbe0e6cbca5966","repo":"apache/iceberg","slug":"failed-to-read-variant-s-of-type-s-as-long","errorCode":null,"errorMessage":"Failed to read Variant %s of type %s as long","messagePattern":"Failed to read Variant (.+?) of type (.+?) as long","errorType":"exception","errorClass":"java.lang.UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/data/VariantRowDataWrapper.java","lineNumber":265,"sourceCode":"    return new GenericArrayData(elements);\n  }\n\n  private static int intValue(Variant variant) {\n    return switch (variant.getType()) {\n      case TINYINT -> variant.getByte();\n      case SMALLINT -> variant.getShort();\n      case INT -> variant.getInt();\n      default -> throw new UnsupportedOperationException(errMsg(variant, \"int\"));\n    };\n  }\n\n  private static long longValue(Variant variant) {\n    return switch (variant.getType()) {\n      case TINYINT -> variant.getByte();\n      case SMALLINT -> variant.getShort();\n      case INT -> variant.getInt();\n      case BIGINT -> variant.getLong();\n      default -> throw new UnsupportedOperationException(errMsg(variant, \"long\"));\n    };\n  }\n\n  private static double doubleValue(Variant variant) {\n    return switch (variant.getType()) {\n      case FLOAT -> variant.getFloat();\n      case DOUBLE -> variant.getDouble();\n      default -> throw new UnsupportedOperationException(errMsg(variant, \"double\"));\n    };\n  }\n\n  private static DecimalData decimalDataValue(Variant variant, DecimalType decimalType) {\n    return DecimalData.fromBigDecimal(\n        variant.getDecimal(), decimalType.getPrecision(), decimalType.getScale());\n  }\n\n  private static TimestampData timestampValue(Variant variant, int precision) {\n    return switch (variant.getType()) {","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/data/VariantRowDataWrapper.java#L247-L283","documentation":"Thrown by VariantRowDataWrapper.longValue: the Flink RowData getter requested a long, but the variant's actual primitive type is not a numeric family member representable as long (tinyint/smallint/int/bigint are handled; e.g. it holds a string, boolean, or double). The formatted message names the variant and its type — a read-schema/type mismatch on variant data.","triggerScenarios":"Calling getLong on a VariantRowDataWrapper column whose variant is not an integral type, or elementValue resolving a BIGINT field whose variant is e.g. a double.","commonSituations":"Column type evolution (bigint -> double) or writers emitting non-integral variants into long-typed fields.","solutions":["Ensure the writer stores an integral variant for BIGINT columns","Use getDouble when the variant is floating point, or fix the RowType to DOUBLE","Cast the value upstream to a long before writing it as a variant"],"exampleFix":"// before\nrow.getLong(2); // variant is DOUBLE -> throws\n// after\nrow.getDouble(2); // or rewrite variants as long","handlingStrategy":"try-catch","validationCode":"switch (variant.getType()) {\n  case TINYINT: case SMALLINT: case INT: case BIGINT: break;\n  default: /* not a long; use appropriate accessor */ }\n}","typeGuard":"boolean isIntegral(Variant v) {\n  switch (v.getType()) {\n    case TINYINT: case SMALLINT: case INT: case BIGINT: return true;\n    default: return false;\n  }\n}","tryCatchPattern":"try { return row.getLong(pos); }\ncatch (UnsupportedOperationException e) { /* variant is non-integral; route to double/decimal accessor */ }","preventionTips":["Writers must emit integral variants for BIGINT columns","Update readers after column type evolution","Centralize variant-type dispatch in one helper"],"tags":["flink","variant","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}