{"record":{"id":"518a04e18fc5d4c0","repo":"apache/iceberg","slug":"expected-one-and-same-orc-type-for-list-elements-518a04","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.2/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.2/spark/src/main/java/org/apache/iceberg/spark/data/SparkOrcValueWriters.java#L119-L155","documentation":"Iceberg's Spark ORC writer builds a ListWriter from the ORC type descriptions of a list column. ORC lists have exactly one element type, so if the planner hands the writer more than one (or zero) TypeDescription entries, the schema and the Iceberg list type are inconsistent and construction fails fast with this IllegalArgumentException.","triggerScenarios":"Writing a Spark DataFrame to an Iceberg ORC table where the ORC schema for a list<T> column yields a List<TypeDescription> whose size != 1 — e.g. a mismatched/mis-derived ORC file schema passed to SparkOrcValueWriters.list.","commonSituations":"Custom ORC schema construction or schema evolution bugs; mixing manually built TypeDescription trees with Iceberg types; writing to a table whose ORC schema was generated by another tool with malformed list types.","solutions":["Verify the ORC schema's list type has exactly one child type (list<T> with a single element subtype).","Regenerate the ORC TypeDescription from the Iceberg schema via SparkSchemaUtil/TypeDescription.fromString instead of hand-building it.","Check for schema evolution mismatches between the table's current schema and the file schema passed to the writer."],"exampleFix":"// before\nListWriter(writer, Arrays.asList(elemTypeA, elemTypeB))\n// after\nListWriter(writer, Collections.singletonList(elemType))","handlingStrategy":"validation","validationCode":"List<TypeDescription> orcTypes = schema.getChildren();\nif (orcTypes.size() != 1) {\n  throw new IllegalArgumentException(\"list schema must have exactly one element type: \" + schema);\n}","typeGuard":"boolean isValidListSchema(TypeDescription t) {\n  return t.getCategory() == TypeDescription.Category.LIST && t.getChildren().size() == 1;\n}","tryCatchPattern":"try {\n  writer = SparkOrcValueWriters.list(elemWriter, orcTypes);\n} catch (IllegalArgumentException e) {\n  throw new IllegalStateException(\"Bad ORC list schema: \" + e.getMessage(), e);\n}","preventionTips":["Derive ORC TypeDescriptions from the Iceberg schema, never hand-build them.","Validate list child counts after schema evolution.","Run orc-tools meta on sample files to sanity-check schemas."],"tags":["orc","spark","schema-mismatch","list-type"],"backgroundTag":"schema-validation-failed","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"}