apache/iceberg · error

Not a nested type: + this

Error message

Not a nested type: + this

What it means

Type.asNestedType() narrows a Type to the NestedType base class (struct/list/map/variant). The default implementation throws IllegalArgumentException because primitives are not nested. Nested types expose inner fields and IDs; primitives do not.

Solutions

  1. Check type.isNestedType() before calling asNestedType().
  2. Branch on isPrimitiveType() vs isNestedType() in traversal code.
  3. Correct the field/type reference so nested access happens only on struct/list/map/variant types.

Example fix

// before
Types.NestedType nested = partitionField.sourceType().asNestedType();
// after
Type t = partitionField.sourceType();
Types.NestedType nested = t.isNestedType() ? (Types.NestedType) t : null;
Defensive patterns

Strategy: type-guard

Validate before calling

Preconditions.checkArgument(type.isNestedType(), "Expected nested type, got: %s", type);

Type guard

if (type.isNestedType()) {
  Types.NestedType nested = (Types.NestedType) type;
}

Try / catch

try {
  Types.NestedType nested = type.asNestedType();
} catch (IllegalArgumentException e) {
  // primitive path
}

Prevention

When it happens

Trigger: Calling asNestedType() on a primitive Type — e.g. helpers like struct/list/map/stringType/decimalType or BaseFile code that inspects a partition/source type assuming it is nested.

Common situations: Partition handling where a partition field's source is a primitive (identity-partitioned by a primitive column); generic schema traversal that skips the isNestedType check; refactoring that changed a field from struct to primitive.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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

Appendix: source

Thrown at api/src/main/java/org/apache/iceberg/types/Type.java:113

  default boolean isStructType() {
    return false;
  }

  default boolean isListType() {
    return false;
  }

  default boolean isMapType() {
    return false;
  }

  default boolean isVariantType() {
    return false;
  }

  default NestedType asNestedType() {
    throw new IllegalArgumentException("Not a nested type: " + this);
  }

  abstract class PrimitiveType implements Type {
    @Override
    public boolean isPrimitiveType() {
      return true;
    }

    @Override
    public PrimitiveType asPrimitiveType() {
      return this;
    }

    Object writeReplace() throws ObjectStreamException {
      return new PrimitiveLikeHolder(toString());
    }

    @Override

View on GitHub (pinned to 86d9c8fc54)