{"record":{"id":"9bdc76905f269109","repo":"apache/iceberg","slug":"expected-two-orc-type-descriptions-for-a-map-got-9bdc76","errorCode":null,"errorMessage":"Expected two ORC type descriptions for a map, got: {orcTypes}","messagePattern":"Expected two ORC type descriptions for a map, 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":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/v4.1/spark/src/main/java/org/apache/iceberg/spark/data/SparkOrcValueWriters.java#L160-L196","documentation":"SparkOrcValueWriters.MapWriter expects exactly two ORC TypeDescriptions — one for keys and one for values. If orcTypes.size() != 2 the provided type list does not match a map's layout, so the constructor throws IllegalArgumentException, preventing key/value getters from reading the wrong child types.","triggerScenarios":"Constructing a MapWriter with a child type list that is not exactly [keyType, valueType] — e.g. passing flattened struct children or an empty list due to a schema-mapping bug.","commonSituations":"Custom ORC writer plumbing passing the wrong TypeDescription children; ORC files with non-standard map encoding; mapping code desynced from the ORC file's actual schema.","solutions":["Pass exactly the two child TypeDescriptions (key, value) of the ORC map","Confirm with record.getChildren() that the map column has two children","Fix the schema-mapping code that assembles orcTypes","Upgrade Iceberg if this stems from a known mapping bug"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"List<TypeDescription> children = mapType.getChildren();\nif (children.size() != 2) {\n  throw new IllegalStateException(\"Map column must have key+value types, got: \" + children.size());\n}","typeGuard":null,"tryCatchPattern":"try {\n  new SparkOrcValueWriters.MapWriter<>(kw, vw, orcTypes);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"for a map\")) { /* pass exactly key and value TypeDescriptions */ }\n  else throw e;\n}","preventionTips":["Pass exactly mapType.getChildren() (2 entries) to MapWriter","Verify ORC schema layout with TypeDescription.print() during development","Keep schema-mapping code covered with nested map tests"],"tags":["spark","orc","writer","map","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"}