{"record":{"id":"942b3a72d8dcfcaf","repo":"apache/iceberg","slug":"cannot-get-value-for-invalid-index","errorCode":null,"errorMessage":"Cannot get value for invalid index: ","messagePattern":"Cannot get value for invalid index: ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"orc/src/main/java/org/apache/iceberg/data/orc/GenericOrcWriters.java","lineNumber":650,"sourceCode":"  private static class PositionDeleteStructWriter<T> extends StructWriter<PositionDelete<T>>\n      implements OrcRowWriter<PositionDelete<T>> {\n    private final Function<CharSequence, ?> pathTransformFunc;\n\n    PositionDeleteStructWriter(\n        OrcRowWriter<T> replacedWriter, Function<CharSequence, ?> pathTransformFunc) {\n      super(replacedWriter.writers());\n      this.pathTransformFunc = pathTransformFunc;\n    }\n\n    @Override\n    protected Object get(PositionDelete<T> delete, int index) {\n      switch (index) {\n        case 0:\n          return pathTransformFunc.apply(delete.path());\n        case 1:\n          return delete.pos();\n      }\n      throw new IllegalArgumentException(\"Cannot get value for invalid index: \" + index);\n    }\n\n    @Override\n    public void write(PositionDelete<T> row, VectorizedRowBatch output) throws IOException {\n      Preconditions.checkArgument(row != null, \"value must not be null\");\n      writeRow(row, output);\n    }\n  }\n\n  /** Returns a mapping from writer index to field index, skipping Unknown columns. */\n  static int[] writerToFieldIndex(Types.StructType struct, int numWriters) {\n    if (null == struct) {\n      return IntStream.rangeClosed(0, numWriters).toArray();\n    }\n\n    List<Types.NestedField> recordFields = struct.fields();\n\n    // value writer index to record field index","sourceCodeStart":632,"sourceCodeEnd":668,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/orc/src/main/java/org/apache/iceberg/data/orc/GenericOrcWriters.java#L632-L668","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nrow.get(2) // extra column on PositionDelete -> invalid index\n// after\nrow.get(0) // path; only indices 0 and 1 exist on PositionDelete","handlingStrategy":"validation","validationCode":"// delete schema must be exactly [path, pos]\nSchema delSchema = deleteFile.schema();\nif (delSchema.columns().size() != 2 || !delSchema.columns().get(0).name().equals(\"path\") || !delSchema.columns().get(1).name().equals(\"pos\")) {\n  throw new IllegalArgumentException(\"position delete schema must be (path, pos)\");\n}","typeGuard":null,"tryCatchPattern":"try { writer.write(row, batch); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith(\"Cannot get value for invalid index\")) { /* fix delete schema/indexing */ } throw e; }","preventionTips":["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"],"tags":["orc","writer","deletes","index-out-of-range"],"backgroundTag":"index-out-of-range","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}