{"record":{"id":"084b6b77f477fc3b","repo":"apache/iceberg","slug":"unsupported-primitive-type-084b6b","errorCode":null,"errorMessage":"Unsupported primitive type: ","messagePattern":"Unsupported primitive type: ","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/variants/PrimitiveWrapper.java","lineNumber":142,"sourceCode":"      case DECIMAL8:\n        return 10; // 1 header + 1 scale + 8 unscaled value\n      case DECIMAL16:\n        return 18; // 1 header + 1 scale + 16 unscaled value\n      case BINARY:\n        return 5 + binary.length; // 1 header + 4 length + value length\n      case STRING:\n        if (null == buffer) {\n          this.buffer = ByteBuffer.wrap(((String) value).getBytes(StandardCharsets.UTF_8));\n        }\n        if (buffer.remaining() <= MAX_SHORT_STRING_LENGTH) {\n          return 1 + buffer.remaining(); // 1 header + value length\n        }\n        return 5 + buffer.remaining(); // 1 header + 4 length + value length\n      case UUID:\n        return 1 + 16; // 1 header + 16 length\n    }\n\n    throw new UnsupportedOperationException(\"Unsupported primitive type: \" + type());\n  }\n\n  @Override\n  public int writeTo(ByteBuffer outBuffer, int offset) {\n    Preconditions.checkArgument(\n        outBuffer.order() == ByteOrder.LITTLE_ENDIAN, \"Invalid byte order: big endian\");\n    switch (type()) {\n      case NULL:\n        outBuffer.put(offset, NULL_HEADER);\n        return 1;\n      case BOOLEAN_TRUE:\n        outBuffer.put(offset, TRUE_HEADER);\n        return 1;\n      case BOOLEAN_FALSE:\n        outBuffer.put(offset, FALSE_HEADER);\n        return 1;\n      case INT8:\n        outBuffer.put(offset, INT8_HEADER);","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/variants/PrimitiveWrapper.java#L124-L160","documentation":"PrimitiveWrapper serializes variant primitives into the Iceberg variant binary encoding. sizeInBytes computes the encoded size per PhysicalType, and throws UnsupportedOperationException when the wrapper's PhysicalType is not one of the known serializable primitive types (e.g. unhandled future/unknown type). The library throws because encoding size is undefined for an unrecognized physical type.","triggerScenarios":"Calling VariantPrimitive.sizeInBytes() on a PrimitiveWrapper whose type() is not a concrete serializable PhysicalType (e.g. a type added in a newer variant spec, or a corrupted/default PhysicalType).","commonSituations":"Reading variant data written by a newer Iceberg/variant-spec version into an older runtime; custom code constructing PrimitiveWrapper with an unexpected PhysicalType; deserialization producing an unmapped type byte.","solutions":["Upgrade iceberg-core (and dependent engines) to a version supporting the PhysicalType encountered","Verify the variant data was written by a compatible Iceberg version; rewrite with a supported version","Check which PhysicalType is present before calling sizeInBytes and skip/log unsupported values"],"exampleFix":"// before\nint size = primitive.sizeInBytes();\n// after\nif (primitive.type().isKnownType()) {\n  int size = primitive.sizeInBytes();\n} else {\n  throw new IllegalStateException(\"Encountered unsupported variant primitive: \" + primitive.type());\n}","handlingStrategy":"type-guard","validationCode":"if (primitive.type() == null || !isSupportedPhysicalType(primitive.type())) { throw new IllegalStateException(\"Unsupported variant type: \" + primitive.type()); }","typeGuard":"boolean isSupported(VariantPrimitive<?> p) { return EnumSet.allOf(PhysicalType.class).contains(p.type()) && KNOWN_TYPES.contains(p.type()); }","tryCatchPattern":"try { size = primitive.sizeInBytes(); } catch (UnsupportedOperationException e) { log.warn(\"Skipping unsupported variant primitive\"); size = -1; }","preventionTips":["Keep Iceberg runtime versions aligned across writer and reader","Pin the variant spec version your data uses","Test variant reads against data from all producers in your pipeline"],"tags":["variants","unsupported-type","serialization"],"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"}