{"record":{"id":"2c7b7bd2931cb25c","repo":"apache/iceberg","slug":"expected-one-and-same-orc-type-for-list-elements-2c7b7b","errorCode":null,"errorMessage":"Expected one (and same) ORC type for list elements, got: {orcTypes}","messagePattern":"Expected one \\(and same\\) ORC type for list elements, got: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/data/SparkOrcValueWriters.java","lineNumber":137,"sourceCode":"  }\n\n  private static class Decimal38Writer implements OrcValueWriter<Decimal> {\n\n    @Override\n    public void nonNullWrite(int rowId, Decimal decimal, ColumnVector output) {\n      ((DecimalColumnVector) output)\n          .vector[rowId].set(HiveDecimal.create(decimal.toJavaBigDecimal()));\n    }\n  }\n\n  private static class ListWriter<T> implements OrcValueWriter<ArrayData> {\n    private final OrcValueWriter<T> writer;\n    private final SparkOrcWriter.FieldGetter<T> fieldGetter;\n\n    @SuppressWarnings(\"unchecked\")\n    ListWriter(OrcValueWriter<T> writer, List<TypeDescription> orcTypes) {\n      if (orcTypes.size() != 1) {\n        throw new IllegalArgumentException(\n            \"Expected one (and same) ORC type for list elements, got: \" + orcTypes);\n      }\n      this.writer = writer;\n      this.fieldGetter =\n          (SparkOrcWriter.FieldGetter<T>) SparkOrcWriter.createFieldGetter(orcTypes.get(0));\n    }\n\n    @Override\n    public void nonNullWrite(int rowId, ArrayData value, ColumnVector output) {\n      ListColumnVector cv = (ListColumnVector) output;\n      // record the length and start of the list elements\n      cv.lengths[rowId] = value.numElements();\n      cv.offsets[rowId] = cv.childCount;\n      cv.childCount = (int) (cv.childCount + cv.lengths[rowId]);\n      // make sure the child is big enough\n      growColumnVector(cv.child, cv.childCount);\n      // Add each element\n      for (int e = 0; e < cv.lengths[rowId]; ++e) {","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/data/SparkOrcValueWriters.java#L119-L155","documentation":"SparkOrcValueWriters.ListWriter wraps an element writer and expects exactly one ORC TypeDescription describing the list's element type. If orcTypes.size() != 1 the ORC type tree does not match the expected list layout, so the constructor throws IllegalArgumentException to fail fast rather than reading the wrong child types.","triggerScenarios":"Building an ORC ListWriter with a malformed list of child TypeDescriptions — e.g. passing the struct's full child list instead of the list element type, or a corrupted/misaligned schema mapping.","commonSituations":"Bugs in ORC schema-to-writer mapping code; custom writer plumbing passing the wrong orcTypes slice; ORC files written with non-standard nested type layouts.","solutions":["Pass only the element TypeDescription of the ORC list to ListWriter","Verify the schema mapping produces one child type per list column","Update Iceberg if the mismatch comes from a fixed mapping bug","Inspect the ORC schema (TypeDescription.print()) to confirm the list layout"],"exampleFix":"// before\nnew ListWriter<>(elemWriter, record.getChildren())\n// after\nnew ListWriter<>(elemWriter, record.getChildren().get(0).getChildren())","handlingStrategy":"try-catch","validationCode":"List<TypeDescription> children = listType.getChildren();\nif (children.size() != 1) {\n  throw new IllegalStateException(\"List column must have exactly one element type, got: \" + children.size());\n}","typeGuard":null,"tryCatchPattern":"try {\n  new SparkOrcValueWriters.ListWriter<>(w, orcTypes);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"list elements\")) { /* fix the orcTypes slice */ }\n  else throw e;\n}","preventionTips":["Always derive orcTypes from record.getChildren() of the actual list TypeDescription","Unit-test schema mapping for nested list columns","Log ORC TypeDescription trees when debugging writer construction"],"tags":["spark","orc","writer","list","internal-invariant"],"backgroundTag":"internal-invariant-violation","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}