apache/iceberg · error

Field + field.name() + not found in source schema

Error message

Field + field.name() + not found in source schema

What it means

ReassignIds re-maps field IDs in a type/schema against a source schema that carries the authoritative IDs. When it encounters a field that has no counterpart (by name) in the source schema, it cannot determine a valid ID mapping, so it throws this IllegalArgumentException. This protects against schemas that were renamed or restructured in ways ID reassignment cannot track.

Source

Thrown at api/src/main/java/org/apache/iceberg/types/ReassignIds.java:110

    Types.StructType sourceStruct = sourceType.asStructType();
    Types.NestedField sourceField =
        caseSensitive
            ? sourceStruct.field(field.name())
            : sourceStruct.caseInsensitiveField(field.name());
    if (sourceField != null) {
      this.sourceType = sourceField.type();
      try {
        return future.get();
      } finally {
        sourceType = sourceStruct;
      }

    } else if (assignId != null) {
      // there is no corresponding field in the id source schema, assign fresh IDs for the type
      return TypeUtil.assignFreshIds(field.type(), assignId);

    } else {
      throw new IllegalArgumentException("Field " + field.name() + " not found in source schema");
    }
  }

  @Override
  public Type list(Types.ListType list, Supplier<Type> elementTypeFuture) {
    Preconditions.checkArgument(sourceType.isListType(), "Not a list: %s", sourceType);

    Types.ListType sourceList = sourceType.asListType();
    int sourceElementId = sourceList.elementId();

    this.sourceType = sourceList.elementType();
    try {
      if (list.isElementOptional()) {
        return Types.ListType.ofOptional(sourceElementId, elementTypeFuture.get());
      } else {
        return Types.ListType.ofRequired(sourceElementId, elementTypeFuture.get());
      }

View on GitHub (pinned to 86d9c8fc54)

Solutions

  1. Ensure every field in the type being reassigned exists by name in the provided source schema; fix typos or casing mismatches.
  2. For genuinely new fields, use TypeUtil.assignFreshIds or schema update mechanisms instead of reassignIds.
  3. Pass the correct (current) source schema as the ID source rather than an older version.
  4. Catch IllegalArgumentException and handle schemas that legitimately diverge from the source.

Example fix

// before
Schema projected = TypeUtil.reassignIds(newSchema, oldSchema); // newSchema has field 'ts' not in oldSchema
// after
if (newSchema.asStruct().fields().stream().allMatch(f -> oldSchema.findField(f.name()) != null)) {
  Schema projected = TypeUtil.reassignIds(newSchema, oldSchema);
} else {
  Schema projected = TypeUtil.assignIncreasingFreshIds(newSchema);
}
Defensive patterns

Strategy: validation

Validate before calling

boolean safe = type.asStructType().fields().stream()
    .allMatch(f -> sourceSchema.findField(f.name()) != null);
if (!safe) throw new IllegalStateException("Cannot reassign IDs: fields missing from source schema");

Type guard

boolean canReassign = type.asStructType().fields().stream()
    .allMatch(f -> sourceSchema.findField(f.name()) != null);

Try / catch

try {
  Schema reassigned = TypeUtil.reassignIds(type, sourceSchema);
} catch (IllegalArgumentException e) {
  // fall back to fresh IDs for schemas that diverged from source
  Schema reassigned = TypeUtil.assignIncreasingFreshIds(type);
}

Prevention

When it happens

Trigger: Calling TypeUtil.reassignIds(typeOrSchema, sourceSchema) (directly or via schema evolution helpers) with a type containing a field whose name does not exist in the source schema, e.g. a newly added field or a renamed field being remapped against the old schema.

Common situations: Schema evolution code that adds or renames fields and then attempts to reassign IDs against the pre-evolution schema; building a projection schema from names that don't match the source table schema; hand-built schemas with typos in field names.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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