{"record":{"id":"1d1af7020e4b6a15","repo":"apache/iceberg","slug":"cannot-find-field-s-in-s","errorCode":null,"errorMessage":"Cannot find field %s in %s","messagePattern":"Cannot find field (.+?) in (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/org/apache/iceberg/util/StructProjection.java","lineNumber":173,"sourceCode":"              Preconditions.checkArgument(\n                  elementProjectable,\n                  \"Cannot project a partial list element struct. Trying to project %s out of %s\",\n                  projectedField,\n                  dataField);\n\n              nestedProjections[pos] = null;\n              break;\n            default:\n              nestedProjections[pos] = null;\n          }\n        }\n      }\n\n      if (!found && projectedField.isOptional() && allowMissing) {\n        positionMap[pos] = -1;\n        nestedProjections[pos] = null;\n      } else if (!found) {\n        throw new IllegalArgumentException(\n            String.format(\"Cannot find field %s in %s\", projectedField, structType));\n      }\n    }\n  }\n\n  public int projectedFields() {\n    return (int) Ints.asList(positionMap).stream().filter(val -> val != -1).count();\n  }\n\n  public StructProjection wrap(StructLike newStruct) {\n    this.struct = newStruct;\n    return this;\n  }\n\n  public StructProjection copyFor(StructLike newStruct) {\n    return new StructProjection(type, positionMap, nestedProjections).wrap(newStruct);\n  }\n","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/api/src/main/java/org/apache/iceberg/util/StructProjection.java#L155-L191","documentation":"StructProjection projects a source StructType down to a set of projected fields. During create(), each projected field is looked up in the source struct; if a required (or non-allowMissing) projected field has no matching source field, this IllegalArgumentException is thrown. It means the projection schema and the struct schema are out of sync.","triggerScenarios":"Calling StructProjection.create(sourceType, projectedType or ids) when the projected schema contains a field name/id that does not exist in the source struct type, and the field is required or allowMissing=false.","commonSituations":"Evolving a table (renaming/dropping a field) while cached projections or scan schemas still reference the old field; passing a projection built from one table's schema to rows of another schema; case-sensitivity mismatches in field names.","solutions":["Rebuild the StructProjection from the current source struct type instead of a stale/cached one","Check that every field name/id in the projected schema exists in the source schema (Types.StructType.field(name) != null) before creating the projection","If optional projected fields may legitimately be absent, use the create overload with allowMissing=true","Align case sensitivity: use the same case-sensitivity setting as the schema or case-insensitive lookup"],"exampleFix":"// before\nStructProjection.create(oldTableSchema, projectedType);\n// after\nTypes.StructType current = table.schema().asStruct();\nTypes.NestedField f = current.field(projectedFieldId);\nif (f == null) { throw new IllegalStateException(\"schema changed; rebuild projection\"); }\nStructProjection.create(current, projectedType);","handlingStrategy":"validation","validationCode":"boolean projectable = projectedType.fields().stream()\n    .allMatch(f -> f.isOptional() || sourceType.field(f.name()) != null);\nif (!projectable) { throw new IllegalStateException(\"projected schema fields missing from source\"); }","typeGuard":null,"tryCatchPattern":"try {\n  StructProjection p = StructProjection.create(sourceType, ids);\n} catch (IllegalArgumentException e) {\n  // rebuild projection from the current schema or fall back to full row\n}","preventionTips":["Rebuild projections whenever the table schema changes instead of caching them","Validate projected field ids exist in the source schema before create()","Use allowMissing=true when projecting optional fields that may not exist","Keep case-sensitivity consistent between schema and projection field names"],"tags":["schema","projection","illegal-argument"],"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"}