{"record":{"id":"07e19c67a2b8327a","repo":"apache/iceberg","slug":"errmsg-variant-timestamp","errorCode":null,"errorMessage":"errMsg(variant, \"timestamp\")","messagePattern":"errMsg\\(variant, \"timestamp\"\\)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"flink/v2.2/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.2/flink/src/main/java/org/apache/iceberg/flink/data/VariantRowDataWrapper.java#L277-L313","documentation":"timestampValue converts a Variant to a Flink TimestampData only when the variant holds a timestamp with micros or nanos precision; any other variant type (or precision) throws UnsupportedOperationException with errMsg(variant, \"timestamp\"). The switch also validates precision, rejecting precisions other than micros/nanos with \"Invalid precision\" beforehand.","triggerScenarios":"Calling getTimestamp(pos, precision) or elementValue where the Variant is not a timestamp type — e.g. a STRING or LONG variant read through a TIMESTAMP Flink field.","commonSituations":"Variant timestamps stored as strings/epoch longs rather than the variant timestamp type; version mismatch where the writer encodes timestamps differently; reading a date-only variant as timestamp.","solutions":["Ensure the writer stores timestamps using the variant timestamp type (micros or nanos).","Read long variants via getLong and convert to TimestampData manually if that is the actual encoding.","Align the Flink field type with the variant's stored type."],"exampleFix":"// before\nTimestampData ts = wrapper.getTimestamp(pos, 6); // variant is epoch-millis long\n// after\nlong millis = wrapper.getLong(pos);\nTimestampData ts = TimestampData.fromEpochMillis(millis);","handlingStrategy":"type-guard","validationCode":"if (variant.getType() == Variant.Type.TIMESTAMP || variant.getType() == Variant.Type.TIMESTAMP_NANOS) { /* safe to getTimestamp */ }","typeGuard":"boolean isTimestampVariant(Variant v) { return v.getType() == Variant.Type.TIMESTAMP || v.getType() == Variant.Type.TIMESTAMP_NANOS; }","tryCatchPattern":"try { TimestampData ts = wrapper.getTimestamp(pos, 6); } catch (UnsupportedOperationException e) { /* convert from long/string variant manually */ }","preventionTips":["Store timestamps in variants using the variant timestamp type (micros/nanos) only.","Never encode timestamps as strings or plain longs in variant columns.","Assert variant types at write time in producer tests."],"tags":["flink","variant","timestamp","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"}