apache/hadoop · error · ClassCastException

Child key classes fail to agree

Error message

Child key classes fail to agree

What it means

Error "Child key classes fail to agree" thrown in apache/hadoop.

Source

Thrown at hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/lib/join/CompositeRecordReader.java:123

        // get keyclass
        if (keyclass == null) {
          keyclass = kids[i].createKey().getClass().
            asSubclass(WritableComparable.class);
        }
        // create priority queue
        if (null == q) {
          cmp = WritableComparator.get(keyclass, conf);
          q = new PriorityQueue<ComposableRecordReader<K,?>>(3,
                new Comparator<ComposableRecordReader<K,?>>() {
                  public int compare(ComposableRecordReader<K,?> o1,
                                     ComposableRecordReader<K,?> o2) {
                    return cmp.compare(o1.key(), o2.key());
                  }
                });
        }
        // Explicit check for key class agreement
        if (!keyclass.equals(kids[i].key().getClass())) {
          throw new ClassCastException("Child key classes fail to agree");
        }
        
        // add the kid to priority queue if it has any elements
        if (kids[i].hasNext()) {
          q.add(kids[i]);
        }
      }
    }
  }

  /**
   * Return the position in the collector this class occupies.
   */
  public int id() {
    return id;
  }

  /**

View on GitHub (pinned to 2add963021)

Solutions

  1. Make all child RecordReaders emit the same key class: align the InputFormats so every joined stream produces keys of one WritableComparable type.
  2. If key types differ intentionally, wrap them in a common type (e.g. TupleWritable or a tagged union) before the join.

Example fix

// use formats that both emit Text keys, e.g. KeyValueTextInputFormat for all joined paths

When it happens

Trigger: Thrown by CompositeRecordReader when the child record readers in a join produce keys of different WritableComparable classes that cannot be compared to each other. Ensure all joined streams emit keys of the same type (or compatible join comparators).

Common situations: Joining inputs whose formats emit Text keys in one stream and IntWritable in another; mixed custom key classes.


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/96921d53d6107f7b. Report an issue: GitHub.