{"record":{"id":"ae195d2cdf3d469a","repo":"apache/iceberg","slug":"errmsg-variant-long","errorCode":null,"errorMessage":"errMsg(variant, \"long\")","messagePattern":"errMsg\\(variant, \"long\"\\)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"flink/v2.2/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.2/flink/src/main/java/org/apache/iceberg/flink/data/VariantRowDataWrapper.java#L247-L283","documentation":"longValue converts a Variant to a Flink long, accepting TINYINT, SMALLINT, INT, and BIGINT. Any other variant type throws UnsupportedOperationException with errMsg(variant, \"long\"), which includes the variant's actual type. This prevents a non-numeric variant (string, double, etc.) from being read through getLong or an array/map element accessor.","triggerScenarios":"Calling getLong(pos) or elementValue for a Variant whose getType() is not TINYINT/SMALLINT/INT/BIGINT — e.g. a DOUBLE or STRING variant read through a BIGINT Flink field.","commonSituations":"Variant column contains mixed numeric types; declared Flink type BIGINT but data written as double; downstream job changed variant schema upstream.","solutions":["Verify the variant's stored type and align the Flink field type (DOUBLE -> getDouble, STRING -> getString).","Cast the value explicitly before reading through the wrapper.","Fix the writer producing the variant so numeric fields use integral types."],"exampleFix":"// before\nlong v = wrapper.getLong(pos); // variant is DOUBLE\n// after\ndouble d = wrapper.getDouble(pos);\nlong v = (long) d;","handlingStrategy":"type-guard","validationCode":"if (EnumSet.of(Variant.Type.TINYINT, Variant.Type.SMALLINT, Variant.Type.INT, Variant.Type.BIGINT).contains(variant.getType())) { /* safe to getLong */ }","typeGuard":"boolean isLongVariant(Variant v) { return switch (v.getType()) { case TINYINT, SMALLINT, INT, BIGINT -> true; default -> false; }; }","tryCatchPattern":"try { long v = wrapper.getLong(pos); } catch (UnsupportedOperationException e) { /* fall back to getDouble/getString based on actual type */ }","preventionTips":["Match BIGINT Flink fields only to integral variant types.","Validate writer output types in integration tests.","Log variant.getType() on conversion failures for quick diagnosis."],"tags":["flink","variant","type-mismatch"],"backgroundTag":"unsupported-operation","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"}