{"record":{"id":"b3319b74cd8a00e8","repo":"apache/iceberg","slug":"failed-to-read-variant-s-of-type-s-as-timestamp","errorCode":null,"errorMessage":"Failed to read Variant %s of type %s as timestamp","messagePattern":"Failed to read Variant (.+?) of type (.+?) as timestamp","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":295,"sourceCode":"  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\n            ? nanoTimestampValue(variant.getLong())\n            : microTimestampValue(variant.getLong());\n      }\n      default -> throw new UnsupportedOperationException(errMsg(variant, \"timestamp\"));\n    };\n  }\n\n  private static TimestampData microTimestampValue(long micros) {\n    return TimestampData.fromEpochMillis(\n        Math.floorDiv(micros, 1000L), (int) Math.floorMod(micros, 1000L) * 1000);\n  }\n\n  private static TimestampData nanoTimestampValue(long nanos) {\n    return TimestampData.fromEpochMillis(\n        Math.floorDiv(nanos, 1_000_000L), (int) Math.floorMod(nanos, 1_000_000L));\n  }\n\n  private Variant field(int position) {\n    String fieldName = rowType.getFields().get(position).getName();\n    return variantData.getField(fieldName);\n  }\n","sourceCodeStart":277,"sourceCodeEnd":313,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/data/VariantRowDataWrapper.java#L277-L313","documentation":"timestampValue converts a Variant to TimestampData only for recognized timestamp variant types (with micros/nanos precision); any other Variant type throws this UnsupportedOperationException via errMsg(variant, \"timestamp\").","triggerScenarios":"Calling getTimestamp on a VariantRowDataWrapper column holding a non-timestamp variant, or elementValue resolving a TIMESTAMP-typed field whose variant is e.g. a string or long without timestamp variant type.","commonSituations":"Writers storing epoch longs or ISO strings in variant columns while the Flink schema declares TIMESTAMP; table schema evolution from long to timestamp.","solutions":["Ensure the writer stores a proper timestamp-typed Variant (not a raw long/string)","Convert the value to a timestamp variant upstream before writing","Use getLong and construct TimestampData manually if the column actually holds epoch values"],"exampleFix":"// before\nrow.getTimestamp(7, 6); // variant holds epoch millis as LONG -> throws\n// after\nTimestampData ts = TimestampData.fromEpochMillis(row.getLong(7));","handlingStrategy":"try-catch","validationCode":"if (variant.getType() != Variant.Type.TIMESTAMP_MICROS\n    && variant.getType() != Variant.Type.TIMESTAMP_NANOS) { /* not a timestamp variant */ }","typeGuard":"boolean isTimestampVariant(Variant v) {\n  return v.getType() == Variant.Type.TIMESTAMP_MICROS || v.getType() == Variant.Type.TIMESTAMP_NANOS;\n}","tryCatchPattern":"try { return row.getTimestamp(pos, precision); }\ncatch (UnsupportedOperationException e) { /* epoch long in column: construct TimestampData manually */ }","preventionTips":["Store timestamp-typed variants, never raw epoch longs or strings","Keep writer and reader precision (micros/nanos) aligned","Validate variant types after schema evolution"],"tags":["flink","variant","timestamp","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"}