apache/iceberg · error · UnsupportedOperationException
Unknown position: (expected 0- )
Error message
Unknown position: ${pos} (expected 0-${BASE_TYPE.fields().size() - 1}) What it means
BasePartitionStatistics.internalGet(int pos) maps positional field indexes (0..BASE_TYPE.fields().size()-1) to partition-statistics field values. An out-of-range or unrecognized position falls through the switch and throws UnsupportedOperationException via unknownPosition(pos). This is an internal invariant violation, not a user-facing validation.
Solutions
- Use the position constants defined by the class (e.g. PARTITION_POSITION, SNAPSHOT_ID_POSITION) instead of hardcoding indexes
- Align the reader's schema with the table's partition-statistics schema (refresh to the same Iceberg version)
- Wrap access in a check: if (pos < BASE_TYPE.fields().size()) before calling
Example fix
// before
row.get(7, Object.class); // beyond known fields -> Unknown position: 7
// after
Types.StructType type = PartitionStatistics.TYPE;
if (7 < type.fields().size()) {
row.get(7, Object.class);
} Defensive patterns
Strategy: type-guard
Validate before calling
if (pos < 0 || pos >= PartitionStatistics.TYPE.fields().size()) throw new IllegalArgumentException("bad pos"); Type guard
boolean isValidPos(int pos) { return pos >= 0 && pos < PartitionStatistics.TYPE.fields().size(); } Try / catch
try { return internalGet(pos); } catch (UnsupportedOperationException e) { if (e.getMessage().startsWith("Unknown position")) { return null; } throw e; } Prevention
- Derive positions from the class's position constants, never literals
- Keep reader and library versions aligned
- Iterate Types.StructType.fields() when accessing generically
When it happens
Trigger: Calling internalGet with a position >= number of schema fields in PartitionStatistics, e.g. from a StructLike accessor using a stale or foreign schema; a code path assuming extra fields that this class does not define.
Common situations: Reading partition statistics with code compiled against a different Iceberg spec version whose field layout differs; custom StructLike wrappers reusing wrong position constants.
Related errors
- Can't modify an empty struct
- Can't retrieve values from an empty struct
- Cannot set fields in a TypeProjection
- Cannot update InternalRecordWrapper
- Cannot update partition statistics of a
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/bbf0b67aebadb5df.
Report an issue: GitHub.
Appendix: source
Thrown at core/src/main/java/org/apache/iceberg/BasePartitionStatistics.java:176
return totalDataFileSizeInBytes;
case POSITION_DELETE_RECORD_COUNT_POSITION:
return positionDeleteRecordCount;
case POSITION_DELETE_FILE_COUNT_POSITION:
return positionDeleteFileCount;
case EQUALITY_DELETE_RECORD_COUNT_POSITION:
return equalityDeleteRecordCount;
case EQUALITY_DELETE_FILE_COUNT_POSITION:
return equalityDeleteFileCount;
case TOTAL_RECORD_COUNT_POSITION:
return totalRecordCount;
case LAST_UPDATED_AT_POSITION:
return lastUpdatedAt;
case LAST_UPDATED_SNAPSHOT_ID_POSITION:
return lastUpdatedSnapshotId;
case DV_COUNT_POSITION:
return dvCount;
default:
throw unknownPosition(pos);
}
}
@Override
protected <T> void internalSet(int pos, T value) {
if (value == null) {
return;
}
switch (pos) {
case PARTITION_POSITION:
this.partition = (StructLike) value;
break;
case SPEC_ID_POSITION:
this.specId = (int) value;
break;
case DATA_RECORD_COUNT_POSITION:
this.dataRecordCount = (long) value;View on GitHub (pinned to 86d9c8fc54)