{"record":{"id":"c8b44d5ba9c67541","repo":"apache/iceberg","slug":"field-key-of-schema-builder-name-is-not-a","errorCode":null,"errorMessage":"Field ${key} of schema ${builder.name()} is not a homogenous array.\nCheck option 'struct' of parameter 'array.encoding'","messagePattern":"Field (.+?) of schema (.+?) is not a homogenous array\\.\nCheck option 'struct' of parameter 'array\\.encoding'","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"kafka-connect/kafka-connect-transforms/src/main/java/org/debezium/connector/mongodb/transforms/MongoDataConverter.java","lineNumber":480,"sourceCode":"\n  private void testType(SchemaBuilder builder, String key, BsonValue value, BsonType valueType) {\n    if (valueType == BsonType.DOCUMENT) {\n      final Map<String, BsonType> union = Maps.newHashMap();\n      for (BsonValue element : value.asArray()) {\n        final BsonDocument arrayDocs = element.asDocument();\n        for (Entry<String, BsonValue> arrayDoc : arrayDocs.entrySet()) {\n          testArrayElementType(builder, arrayDoc, union);\n        }\n      }\n    } else if (valueType == BsonType.ARRAY) {\n      for (BsonValue element : value.asArray()) {\n        BsonType subValueType = element.asArray().get(0).getBsonType();\n        testType(builder, key, element, subValueType);\n      }\n    } else {\n      for (BsonValue element : value.asArray()) {\n        if (element.getBsonType() != valueType) {\n          throw new RuntimeException(\n              \"Field \"\n                  + key\n                  + \" of schema \"\n                  + builder.name()\n                  + \" is not a homogenous array.\\n\"\n                  + \"Check option 'struct' of parameter 'array.encoding'\");\n        }\n      }\n    }\n  }\n\n  private void testArrayElementType(\n      SchemaBuilder builder, Entry<String, BsonValue> arrayDoc, Map<String, BsonType> union) {\n    final String docKey = (String) arrayDoc.getKey();\n    final BsonType currentType = arrayDoc.getValue().getBsonType();\n    final BsonType prevType = union.putIfAbsent(docKey, currentType);\n\n    if (prevType != null) {","sourceCodeStart":462,"sourceCodeEnd":498,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/kafka-connect/kafka-connect-transforms/src/main/java/org/debezium/connector/mongodb/transforms/MongoDataConverter.java#L462-L498","documentation":"MongoDataConverter.testType throws RuntimeException when a BSON array contains elements of differing BsonTypes (a non-homogeneous array). The converter with array.encoding=struct requires all array elements to have the same type to derive a single element schema.","triggerScenarios":"addFieldSchema/testType validating an array where elements have mixed BsonTypes, e.g. [1, \"two\", {\"a\":1}] processed with array.encoding set to struct.","commonSituations":"MongoDB documents with polymorphic arrays (mixed scalars/objects), often created by applications with loosely typed writes.","solutions":["Make the array homogeneous in MongoDB (all elements the same type).","Switch array.encoding to a non-struct option (e.g. encode arrays as JSON strings).","Clean/normalize existing documents before streaming."],"exampleFix":"// before\ndb.coll.insertOne({vals: [1, \"two\"]})\n// after\ndb.coll.insertOne({vals: [1, 2]})","handlingStrategy":"validation","validationCode":"// Check array homogeneity before streaming\njava.util.Set<BsonType> types = new java.util.HashSet<>();\nfor (BsonValue el : arrayValue.asArray()) types.add(el.getBsonType());\nif (types.size() > 1) throw new IllegalStateException(\"non-homogeneous array: \" + types);","typeGuard":"boolean isHomogeneous(BsonArray arr) { return arr.stream().map(BsonValue::getBsonType).distinct().count() <= 1; }","tryCatchPattern":"try { ... } catch (RuntimeException e) { log.error(\"Array homogeneity check failed: {}\", e.getMessage()); }","preventionTips":["Enforce consistent array element types at write time in applications","Use array.encoding=json when arrays may be polymorphic","Run a one-off aggregation to find mixed-type arrays before enabling the transform"],"tags":["kafka-connect","debezium","mongodb","array"],"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"}