apache/iceberg · error · UnsupportedOperationException

Unsupported primitive type:

Error message

Unsupported primitive type: 

What it means

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.

Source

Thrown at core/src/main/java/org/apache/iceberg/variants/PrimitiveWrapper.java:142

      case DECIMAL8:
        return 10; // 1 header + 1 scale + 8 unscaled value
      case DECIMAL16:
        return 18; // 1 header + 1 scale + 16 unscaled value
      case BINARY:
        return 5 + binary.length; // 1 header + 4 length + value length
      case STRING:
        if (null == buffer) {
          this.buffer = ByteBuffer.wrap(((String) value).getBytes(StandardCharsets.UTF_8));
        }
        if (buffer.remaining() <= MAX_SHORT_STRING_LENGTH) {
          return 1 + buffer.remaining(); // 1 header + value length
        }
        return 5 + buffer.remaining(); // 1 header + 4 length + value length
      case UUID:
        return 1 + 16; // 1 header + 16 length
    }

    throw new UnsupportedOperationException("Unsupported primitive type: " + type());
  }

  @Override
  public int writeTo(ByteBuffer outBuffer, int offset) {
    Preconditions.checkArgument(
        outBuffer.order() == ByteOrder.LITTLE_ENDIAN, "Invalid byte order: big endian");
    switch (type()) {
      case NULL:
        outBuffer.put(offset, NULL_HEADER);
        return 1;
      case BOOLEAN_TRUE:
        outBuffer.put(offset, TRUE_HEADER);
        return 1;
      case BOOLEAN_FALSE:
        outBuffer.put(offset, FALSE_HEADER);
        return 1;
      case INT8:
        outBuffer.put(offset, INT8_HEADER);

View on GitHub (pinned to 86d9c8fc54)

Solutions

  1. Upgrade iceberg-core (and dependent engines) to a version supporting the PhysicalType encountered
  2. Verify the variant data was written by a compatible Iceberg version; rewrite with a supported version
  3. Check which PhysicalType is present before calling sizeInBytes and skip/log unsupported values

Example fix

// before
int size = primitive.sizeInBytes();
// after
if (primitive.type().isKnownType()) {
  int size = primitive.sizeInBytes();
} else {
  throw new IllegalStateException("Encountered unsupported variant primitive: " + primitive.type());
}
Defensive patterns

Strategy: type-guard

Validate before calling

if (primitive.type() == null || !isSupportedPhysicalType(primitive.type())) { throw new IllegalStateException("Unsupported variant type: " + primitive.type()); }

Type guard

boolean isSupported(VariantPrimitive<?> p) { return EnumSet.allOf(PhysicalType.class).contains(p.type()) && KNOWN_TYPES.contains(p.type()); }

Try / catch

try { size = primitive.sizeInBytes(); } catch (UnsupportedOperationException e) { log.warn("Skipping unsupported variant primitive"); size = -1; }

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/084b6b77f477fc3b. Report an issue: GitHub.