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

  1. Keep the position-delete schema as (path STRING, pos LONG) exactly.
  2. Remove custom code/patches that request additional fields from PositionDelete.
  3. Regenerate delete files with the standard Iceberg writer.
  4. 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

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


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 index

View on GitHub (pinned to 86d9c8fc54)