{"record":{"id":"2887fcd3900e6a25","repo":"apache/iceberg","slug":"failed-to-read-variant-s-of-type-s-as-double","errorCode":null,"errorMessage":"Failed to read Variant %s of type %s as double","messagePattern":"Failed to read Variant (.+?) of type (.+?) as double","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":273,"sourceCode":"      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()) {\n      case TIMESTAMP -> TimestampData.fromLocalDateTime(variant.getDateTime());\n      case TIMESTAMP_LTZ -> TimestampData.fromInstant(variant.getInstant());\n      case BIGINT -> {\n        Preconditions.checkArgument(\n            precision >= MICROSECOND_PRECISION && precision <= NANOSECOND_PRECISION,\n            \"Invalid precision: %s. Only micros and nanos precision are supported.\",\n            precision);\n        yield precision > MICROSECOND_PRECISION","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/data/VariantRowDataWrapper.java#L255-L291","documentation":"Thrown by VariantRowDataWrapper.doubleValue: a double was requested from a variant whose primitive type is neither FLOAT nor DOUBLE (the handled cases). The message includes the variant value and its type; the consuming Flink job's expected row type disagrees with the variant's stored type.","triggerScenarios":"Calling getDouble on a VariantRowDataWrapper column whose variant is, e.g., a string or decimal rather than a float/double, or elementValue with a DOUBLE-typed field holding another variant type.","commonSituations":"Writers producing decimal variants for double columns; schema drift where a double column now stores numeric variants of other widths.","solutions":["Ensure the variant's physical type is FLOAT or DOUBLE when written","Align the RowType field to DECIMAL and read via getDecimal if variants are decimals","Convert the value upstream to double before writing"],"exampleFix":"// before\nrow.getDouble(5); // variant is DECIMAL -> throws\n// after\nDecimalData d = row.getDecimal(5, precision, scale);","handlingStrategy":"try-catch","validationCode":"if (variant.getType() != Variant.Type.FLOAT\n    && variant.getType() != Variant.Type.DOUBLE) { /* use decimal/other accessor */ }","typeGuard":"boolean isFloatingPoint(Variant v) {\n  return v.getType() == Variant.Type.FLOAT || v.getType() == Variant.Type.DOUBLE;\n}","tryCatchPattern":"try { return row.getDouble(pos); }\ncatch (UnsupportedOperationException e) { /* fall back to getDecimal and convert */ }","preventionTips":["Write float/double variants for DOUBLE-typed columns","Declare DECIMAL columns for decimal variants","Check variant.getType() before numeric accessors"],"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"}