{"record":{"id":"64190ab6cdb62c26","repo":"apache/iceberg","slug":"cannot-find-projected-field","errorCode":null,"errorMessage":"Cannot find projected field: ","messagePattern":"Cannot find projected field: ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/GenericPartitionFieldSummary.java","lineNumber":67,"sourceCode":"  public GenericPartitionFieldSummary(Schema avroSchema) {\n    this.avroSchema = avroSchema;\n\n    List<Types.NestedField> fields =\n        AvroSchemaUtil.convert(avroSchema).asNestedType().asStructType().fields();\n    List<Types.NestedField> allFields = PartitionFieldSummary.getType().fields();\n\n    this.fromProjectionPos = new int[fields.size()];\n    for (int i = 0; i < fromProjectionPos.length; i += 1) {\n      boolean found = false;\n      for (int j = 0; j < allFields.size(); j += 1) {\n        if (fields.get(i).fieldId() == allFields.get(j).fieldId()) {\n          found = true;\n          fromProjectionPos[i] = j;\n        }\n      }\n\n      if (!found) {\n        throw new IllegalArgumentException(\"Cannot find projected field: \" + fields.get(i));\n      }\n    }\n  }\n\n  public GenericPartitionFieldSummary(\n      boolean containsNull, boolean containsNaN, ByteBuffer lowerBound, ByteBuffer upperBound) {\n    this.avroSchema = AVRO_SCHEMA;\n    this.containsNull = containsNull;\n    this.containsNaN = containsNaN;\n    this.lowerBound = ByteBuffers.toByteArray(lowerBound);\n    this.upperBound = ByteBuffers.toByteArray(upperBound);\n    this.fromProjectionPos = null;\n  }\n\n  // for testing backward compatibility only\n  @VisibleForTesting\n  GenericPartitionFieldSummary(boolean containsNull, ByteBuffer lowerBound, ByteBuffer upperBound) {\n    this.avroSchema = AVRO_SCHEMA;","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/GenericPartitionFieldSummary.java#L49-L85","documentation":"In GenericPartitionFieldSummary's projection-matching constructor, each field of the projected schema must be found among the partition-field-summary fields to record fromProjectionPos; when a projected field has no matching summary field, the constructor throws IllegalArgumentException('Cannot find projected field: ' + field). It means the requested projection is not a subset of the fields a partition stats summary actually provides (contains_null, contains_nan, lower_bound, upper_bound).","triggerScenarios":"Constructing GenericPartitionFieldSummary with a projection schema that contains a field name not present in the partition statistics summary struct — e.g. projecting partition stats with fields from a different/older partition type, or misspelled field names in custom projection code.","commonSituations":"Reading partition statistics files written for an older partition spec against a table whose spec evolved; custom metadata-table code building projections by hand; Spark/Flink readers reusing stale projections after schema evolution.","solutions":["Rebuild the projection from the current partition stats type (Partitioning.partitionType / stats schema) instead of a cached schema.","Regenerate partition statistics files after partition spec evolution so summaries match the projected fields.","Check field names in the error message against the summary struct fields (contains_null, contains_nan, lower_bound, upper_bound) for typos or drift."],"exampleFix":"// before: stale cached projection\nTypes.StructType projection = cachedProjection; // from old partition type\n// after: derive from current summary type\nTypes.StructType projection = partitionStatsType();\nGenericPartitionFieldSummary summary = new GenericPartitionFieldSummary(projection, ...);","handlingStrategy":"validation","validationCode":"Types.StructType summaryType = partitionStatsSummaryType();\nfor (Types.NestedField f : projection.asStructType().fields()) {\n  Preconditions.checkArgument(summaryType.field(f.name()) != null,\n      \"Field not in partition stats summary: %s\", f.name());\n}","typeGuard":"boolean isProjectable(String fieldName) {\n  return Set.of(\"contains_null\", \"contains_nan\", \"lower_bound\", \"upper_bound\").contains(fieldName);\n}","tryCatchPattern":"try {\n  GenericPartitionFieldSummary s = new GenericPartitionFieldSummary(projection, fields...);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Cannot find projected field\")) {\n    // rebuild the projection from the current partition stats type\n  } else throw e;\n}","preventionTips":["Derive projections from the live partition stats schema, never cached schemas.","Regenerate partition statistics after partition spec evolution.","Match stats file writer/reader versions."],"tags":["partition-stats","projection","schema-mismatch"],"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-14T11:17:12.474Z"}