{"record":{"id":"e41264fb0837ffbf","repo":"apache/iceberg","slug":"expected-two-orc-type-descriptions-for-a-map-got","errorCode":null,"errorMessage":"Expected two ORC type descriptions for a map, got: ","messagePattern":"Expected two ORC type descriptions for a map, got: ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/data/SparkOrcValueWriters.java","lineNumber":178,"sourceCode":"    @Override\n    public Stream<FieldMetrics<?>> metrics() {\n      return writer.metrics();\n    }\n  }\n\n  private static class MapWriter<K, V> implements OrcValueWriter<MapData> {\n    private final OrcValueWriter<K> keyWriter;\n    private final OrcValueWriter<V> valueWriter;\n    private final SparkOrcWriter.FieldGetter<K> keyFieldGetter;\n    private final SparkOrcWriter.FieldGetter<V> valueFieldGetter;\n\n    @SuppressWarnings(\"unchecked\")\n    MapWriter(\n        OrcValueWriter<K> keyWriter,\n        OrcValueWriter<V> valueWriter,\n        List<TypeDescription> orcTypes) {\n      if (orcTypes.size() != 2) {\n        throw new IllegalArgumentException(\n            \"Expected two ORC type descriptions for a map, got: \" + orcTypes);\n      }\n      this.keyWriter = keyWriter;\n      this.valueWriter = valueWriter;\n      this.keyFieldGetter =\n          (SparkOrcWriter.FieldGetter<K>) SparkOrcWriter.createFieldGetter(orcTypes.get(0));\n      this.valueFieldGetter =\n          (SparkOrcWriter.FieldGetter<V>) SparkOrcWriter.createFieldGetter(orcTypes.get(1));\n    }\n\n    @Override\n    public void nonNullWrite(int rowId, MapData map, ColumnVector output) {\n      ArrayData key = map.keyArray();\n      ArrayData value = map.valueArray();\n      MapColumnVector cv = (MapColumnVector) output;\n      // record the length and start of the list elements\n      cv.lengths[rowId] = value.numElements();\n      cv.offsets[rowId] = cv.childCount;","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v3.5/spark/src/main/java/org/apache/iceberg/spark/data/SparkOrcValueWriters.java#L160-L196","documentation":"SparkOrcValueWriters.MapWriter requires exactly two ORC TypeDescriptions — one for keys and one for values — as ORC maps have exactly two child types. A size other than 2 indicates the ORC schema does not match the expected map layout. This IllegalArgumentException is an internal consistency check on the ORC type tree.","triggerScenarios":"Constructing a MapWriter where the ORC map column's child type list has fewer or more than 2 entries, caused by a malformed or mismatched ORC schema handed to SparkOrcWriter.","commonSituations":"Reading/writing ORC produced by non-standard writers, custom schema stitching, or version-skew producing a map schema with unexpected children.","solutions":["Confirm the ORC TypeDescription for the map column has exactly two children (key, value).","Rewrite the data with a standard ORC writer to normalize the schema.","Check the schema passed into SparkOrcWriter against the actual file schema.","Align Iceberg and ORC library versions."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"org.apache.orc.TypeDescription mapType = schema.findSubtype(\"my_map\");\nif (mapType.getChildren().size() != 2) {\n  throw new IllegalStateException(\"ORC map must have exactly two child types, got \" + mapType.getChildren());\n}","typeGuard":"static boolean isWellFormedOrcMap(org.apache.orc.TypeDescription t) {\n  return t.getCategory() == org.apache.orc.TypeDescription.Category.MAP && t.getChildren().size() == 2;\n}","tryCatchPattern":null,"preventionTips":["Write ORC maps with standard writers","Sanity-check ORC schemas from external producers","Keep ORC library versions consistent"],"tags":["spark","orc","writer","schema-mismatch","map"],"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"}