{"record":{"id":"33c4e954b60282c7","repo":"apache/iceberg","slug":"expected-two-orc-type-descriptions-for-a-map-got-33c4e9","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.2/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.2/spark/src/main/java/org/apache/iceberg/spark/data/SparkOrcValueWriters.java#L160-L196","documentation":"ORC maps are encoded with exactly two child type descriptions: one for keys and one for values. The MapWriter constructor validates this when building Spark-to-ORC writers and throws IllegalArgumentException if the supplied type list does not contain exactly two entries.","triggerScenarios":"Writing a Spark map column to an Iceberg ORC table when the ORC TypeDescription list for the map column has fewer or more than 2 elements (e.g. a corrupt or hand-built schema).","commonSituations":"Hand-constructed ORC schemas missing key/value child types; schema evolution leaving map columns malformed; third-party tools writing ORC schemas that Iceberg cannot map.","solutions":["Ensure the ORC map type has exactly two children: map<keyType,valueType>.","Derive the TypeDescription from the Iceberg schema (TypeDescription.fromString or SparkSchemaUtil) rather than building it manually.","Re-check the table schema after any schema evolution operation that touched map columns."],"exampleFix":"// before\nMapWriter(kw, vw, Collections.singletonList(mapType))\n// after\nMapWriter(kw, vw, Arrays.asList(keyType, valueType))","handlingStrategy":"validation","validationCode":"if (orcTypes.size() != 2) {\n  throw new IllegalArgumentException(\"map schema must have exactly key+value children: \" + orcTypes);\n}","typeGuard":"boolean isValidMapSchema(TypeDescription t) {\n  return t.getCategory() == TypeDescription.Category.MAP && t.getChildren().size() == 2;\n}","tryCatchPattern":"try {\n  writer = SparkOrcValueWriters.map(kw, vw, orcTypes);\n} catch (IllegalArgumentException e) {\n  throw new IllegalStateException(\"Bad ORC map schema: \" + e.getMessage(), e);\n}","preventionTips":["Use TypeDescription.fromString or Iceberg's ORC schema conversion for map columns.","Re-derive file schemas after any schema evolution touching maps."],"tags":["orc","spark","schema-mismatch","map-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"}