apache/iceberg · error · UnsupportedOperationException
Can't retrieve values from an empty struct
Error message
Can't retrieve values from an empty struct
What it means
EmptyStructLike is a StructLike representing a struct with zero fields (used for unpartitioned rows). This library throws UnsupportedOperationException from get() because there are no positions to read from; any positional access is by definition a caller bug.
Source
Thrown at api/src/main/java/org/apache/iceberg/EmptyStructLike.java:40
class EmptyStructLike implements StructLike, Serializable {
private static final EmptyStructLike INSTANCE = new EmptyStructLike();
private EmptyStructLike() {}
static EmptyStructLike get() {
return INSTANCE;
}
@Override
public int size() {
return 0;
}
@Override
public <T> T get(int pos, Class<T> javaClass) {
throw new UnsupportedOperationException("Can't retrieve values from an empty struct");
}
@Override
public <T> void set(int pos, T value) {
throw new UnsupportedOperationException("Can't modify an empty struct");
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
return other != null && getClass() == other.getClass();
}
@Override
public int hashCode() {View on GitHub (pinned to 86d9c8fc54)
Solutions
- Check the partition type/spec field count before accessing positions; skip position access when the struct has 0 fields
- Use the shared EMPTY instance only as a placeholder, never iterate its positions
- If representing an actually-partitioned row, ensure the correct StructLike implementation (e.g. InternalRecordWrapper/Partitioning.partitionType based) is used instead of EmptyStructLike
Example fix
// before
Object value = partition.get(0, Object.class);
// after
if (spec.partitionType().fields().isEmpty()) {
return; // unpartitioned: no partition values to read
}
Object value = partition.get(0, Object.class); Defensive patterns
Strategy: type-guard
Validate before calling
if (spec.partitionType().fields().isEmpty()) { /* skip positional access */ } Type guard
boolean isReadable(StructLike s, int pos) {
return !(s instanceof EmptyStructLike) && pos >= 0;
} Try / catch
try {
value = structLike.get(pos, javaClass);
} catch (UnsupportedOperationException e) {
value = null; // empty struct: no partition values
} Prevention
- Check partitionType().fields().isEmpty() before positional StructLike access
- Never iterate positions of EmptyStructLike
- Use spec.isUnpartitioned() to branch logic early
When it happens
Trigger: Calling get(pos, javaClass) on the EmptyStructLike instance, typically obtained via partition-type.toStructLike(...) or internal code accessing the partition struct of an unpartitioned table with pos >= 0.
Common situations: Custom scan/delete code that assumes a non-empty partition struct; iterating partition positions of a table created with PartitionSpec.unpartitioned(); generic StructLike projection code reused across partitioned and unpartitioned tables.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Can't modify an empty struct
- %s doesn't implement cleanupLevel
- %s doesn't implement cleanExpiredMetadata
- Does not support schema getter
- %s does not implement deleteFile
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/e8a1ad5aec9898c0.
Report an issue: GitHub.