{"record":{"id":"19f67c8195a30426","repo":"apache/iceberg","slug":"field-field-name-not-found-in-source-schema","errorCode":null,"errorMessage":"Field + field.name() + not found in source schema","messagePattern":"Field \\+ field\\.name\\(\\) \\+ not found in source schema","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"api/src/main/java/org/apache/iceberg/types/ReassignIds.java","lineNumber":110,"sourceCode":"    Types.StructType sourceStruct = sourceType.asStructType();\n    Types.NestedField sourceField =\n        caseSensitive\n            ? sourceStruct.field(field.name())\n            : sourceStruct.caseInsensitiveField(field.name());\n    if (sourceField != null) {\n      this.sourceType = sourceField.type();\n      try {\n        return future.get();\n      } finally {\n        sourceType = sourceStruct;\n      }\n\n    } else if (assignId != null) {\n      // there is no corresponding field in the id source schema, assign fresh IDs for the type\n      return TypeUtil.assignFreshIds(field.type(), assignId);\n\n    } else {\n      throw new IllegalArgumentException(\"Field \" + field.name() + \" not found in source schema\");\n    }\n  }\n\n  @Override\n  public Type list(Types.ListType list, Supplier<Type> elementTypeFuture) {\n    Preconditions.checkArgument(sourceType.isListType(), \"Not a list: %s\", sourceType);\n\n    Types.ListType sourceList = sourceType.asListType();\n    int sourceElementId = sourceList.elementId();\n\n    this.sourceType = sourceList.elementType();\n    try {\n      if (list.isElementOptional()) {\n        return Types.ListType.ofOptional(sourceElementId, elementTypeFuture.get());\n      } else {\n        return Types.ListType.ofRequired(sourceElementId, elementTypeFuture.get());\n      }\n","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/api/src/main/java/org/apache/iceberg/types/ReassignIds.java#L92-L128","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure every field in the type being reassigned exists by name in the provided source schema; fix typos or casing mismatches.","For genuinely new fields, use TypeUtil.assignFreshIds or schema update mechanisms instead of reassignIds.","Pass the correct (current) source schema as the ID source rather than an older version.","Catch IllegalArgumentException and handle schemas that legitimately diverge from the source."],"exampleFix":"// before\nSchema projected = TypeUtil.reassignIds(newSchema, oldSchema); // newSchema has field 'ts' not in oldSchema\n// after\nif (newSchema.asStruct().fields().stream().allMatch(f -> oldSchema.findField(f.name()) != null)) {\n  Schema projected = TypeUtil.reassignIds(newSchema, oldSchema);\n} else {\n  Schema projected = TypeUtil.assignIncreasingFreshIds(newSchema);\n}","handlingStrategy":"validation","validationCode":"boolean safe = type.asStructType().fields().stream()\n    .allMatch(f -> sourceSchema.findField(f.name()) != null);\nif (!safe) throw new IllegalStateException(\"Cannot reassign IDs: fields missing from source schema\");","typeGuard":"boolean canReassign = type.asStructType().fields().stream()\n    .allMatch(f -> sourceSchema.findField(f.name()) != null);","tryCatchPattern":"try {\n  Schema reassigned = TypeUtil.reassignIds(type, sourceSchema);\n} catch (IllegalArgumentException e) {\n  // fall back to fresh IDs for schemas that diverged from source\n  Schema reassigned = TypeUtil.assignIncreasingFreshIds(type);\n}","preventionTips":["Always reassign IDs against the schema version the type was derived from.","Use assignFreshIds for newly added fields instead of reassignIds.","Unit-test schema evolution paths with added/renamed fields."],"tags":["schema","iceberg","illegal-argument"],"backgroundTag":"resource-not-found","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}