apache/iceberg · error · IllegalArgumentException
Cannot get value for invalid index:
Error message
Cannot get value for invalid index:
What it means
The ORC PositionDelete writer's row accessor supports exactly index 0 (file path) and index 1 (position). Requesting any other index from the struct-like PositionDelete throws IllegalArgumentException("Cannot get value for invalid index: N"), indicating an internal column-index mismatch.
Solutions
- Keep the position-delete schema as (path STRING, pos LONG) exactly.
- Remove custom code/patches that request additional fields from PositionDelete.
- Regenerate delete files with the standard Iceberg writer.
- Check Iceberg version compatibility for delete file writing.
Example fix
// before row.get(2) // extra column on PositionDelete -> invalid index // after row.get(0) // path; only indices 0 and 1 exist on PositionDelete
Defensive patterns
Strategy: validation
Validate before calling
// delete schema must be exactly [path, pos]
Schema delSchema = deleteFile.schema();
if (delSchema.columns().size() != 2 || !delSchema.columns().get(0).name().equals("path") || !delSchema.columns().get(1).name().equals("pos")) {
throw new IllegalArgumentException("position delete schema must be (path, pos)");
} Try / catch
try { writer.write(row, batch); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith("Cannot get value for invalid index")) { /* fix delete schema/indexing */ } throw e; } Prevention
- Never add columns to position-delete schemas
- Use Iceberg's built-in delete writers
- Keep reader/writer versions aligned
- Access PositionDelete only via index 0/1
When it happens
Trigger: Vectorized position-delete writing where the requested field index is outside {0,1}; malformed delete schema with extra/renamed columns; internal misordering of delete columns.
Common situations: Custom delete writers or copy patches modifying the delete schema; version mismatch between the delete file schema and the reader/writer; manual vectorized row batch configuration.
Related errors
- Encountered an unsupported ORC type during a write from…
- Expected one (and same) ORC type for list elements, got:
- Expected one (and same) ORC type for list elements, got
- Expected two ORC type descriptions for a map, got:
- Expected two ORC type descriptions for a map, got
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/942b3a72d8dcfcaf.
Report an issue: GitHub.
Appendix: source
Thrown at orc/src/main/java/org/apache/iceberg/data/orc/GenericOrcWriters.java:650
private static class PositionDeleteStructWriter<T> extends StructWriter<PositionDelete<T>>
implements OrcRowWriter<PositionDelete<T>> {
private final Function<CharSequence, ?> pathTransformFunc;
PositionDeleteStructWriter(
OrcRowWriter<T> replacedWriter, Function<CharSequence, ?> pathTransformFunc) {
super(replacedWriter.writers());
this.pathTransformFunc = pathTransformFunc;
}
@Override
protected Object get(PositionDelete<T> delete, int index) {
switch (index) {
case 0:
return pathTransformFunc.apply(delete.path());
case 1:
return delete.pos();
}
throw new IllegalArgumentException("Cannot get value for invalid index: " + index);
}
@Override
public void write(PositionDelete<T> row, VectorizedRowBatch output) throws IOException {
Preconditions.checkArgument(row != null, "value must not be null");
writeRow(row, output);
}
}
/** Returns a mapping from writer index to field index, skipping Unknown columns. */
static int[] writerToFieldIndex(Types.StructType struct, int numWriters) {
if (null == struct) {
return IntStream.rangeClosed(0, numWriters).toArray();
}
List<Types.NestedField> recordFields = struct.fields();
// value writer index to record field indexView on GitHub (pinned to 86d9c8fc54)