{"record":{"id":"4028b9d2d5fe693d","repo":"apache/iceberg","slug":"field-name-not-found-in-source-schema","errorCode":null,"errorMessage":"Field + name + not found in source schema","messagePattern":"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":65,"sourceCode":"      return future.get();\n    } finally {\n      this.sourceType = null;\n    }\n  }\n\n  private int id(Types.StructType sourceStruct, String name) {\n    Types.NestedField sourceField =\n        caseSensitive ? sourceStruct.field(name) : sourceStruct.caseInsensitiveField(name);\n\n    if (sourceField != null) {\n      return sourceField.fieldId();\n    }\n\n    if (assignId != null) {\n      return assignId.get();\n    }\n\n    throw new IllegalArgumentException(\"Field \" + name + \" not found in source schema\");\n  }\n\n  @Override\n  public Type struct(Types.StructType struct, Iterable<Type> fieldTypes) {\n    Preconditions.checkNotNull(sourceType, \"Evaluation must start with a schema.\");\n    Preconditions.checkArgument(sourceType.isStructType(), \"Not a struct: %s\", sourceType);\n\n    Types.StructType sourceStruct = sourceType.asStructType();\n    List<Types.NestedField> fields = struct.fields();\n    int length = fields.size();\n\n    List<Type> types = Lists.newArrayList(fieldTypes);\n    List<Types.NestedField> newFields = Lists.newArrayListWithExpectedSize(length);\n    for (int i = 0; i < length; i += 1) {\n      Types.NestedField field = fields.get(i);\n      int fieldId = id(sourceStruct, field.name());\n      newFields.add(Types.NestedField.from(field).withId(fieldId).ofType(types.get(i)).build());\n    }","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/api/src/main/java/org/apache/iceberg/types/ReassignIds.java#L47-L83","documentation":"ReassignIds rewrites a type tree so field ids match a source schema. Its id(name) visitor callback looks up the field's id from the source schema and throws IllegalArgumentException when no field with that name exists. This means the schema being re-assigned contains a field absent from the reference schema.","triggerScenarios":"Calling TypeUtil.reassignIds(type, schema) (or the ReassignIds visitor via fieldId) where the incoming type has a field name not present in the source schema — e.g. schemas drifted or fields were renamed.","commonSituations":"Restoring ids on an evolved schema against a stale source schema; merging branches where one renamed a field; writing an Avro/Parquet file whose schema includes fields added after the reference snapshot.","solutions":["Update the source schema to include all fields present in the type being re-assigned","Rename/align field names so they match the source schema exactly","Use reassignOrFreshIds if new fields should receive fresh ids instead of failing"],"exampleFix":"// before\nTypes.StructType t = TypeUtil.reassignIds(newType, oldSchema); // new field 'extra' missing in oldSchema\n// after\nTypes.StructType t = TypeUtil.reassignOrFreshIds(newType, oldSchema::findField); // new fields get fresh ids","handlingStrategy":"validation","validationCode":"for (Types.NestedField f : newType.asNestedType().fields()) {\n  if (schema.findField(f.name()) == null) throw new IllegalArgumentException(\"Field missing in source schema: \" + f.name());\n}","typeGuard":"boolean assignable(Types.StructType t, Schema src) { return t.fields().stream().allMatch(f -> src.findField(f.name()) != null); }","tryCatchPattern":"try { t = TypeUtil.reassignIds(type, schema); } catch (IllegalArgumentException e) { t = TypeUtil.reassignOrFreshIds(type, schema::findField); }","preventionTips":["Prefer reassignOrFreshIds when schemas may have evolved","Diff schemas before reassigning ids","Keep reference schemas in sync with evolved table schemas"],"tags":["java","schema","ids","entity-not-found"],"backgroundTag":"schema-validation-failed","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"}