{"record":{"id":"088291156af7cbf3","repo":"apache/beam","slug":"value-translation-s-input-type-is-not-same-as-hadoop","errorCode":null,"errorMessage":"Value translation's input type is not same as hadoop InputFormat :  %s value class : %s","messagePattern":"Value translation's input type is not same as hadoop InputFormat :  (.+?) value class : (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/hadoop-format/src/main/java/org/apache/beam/sdk/io/hadoop/format/HadoopFormatIO.java","lineNumber":587,"sourceCode":"      checkArgument(getConfiguration() != null, \"withConfiguration() is required\");\n      // Validate that the key translation input type must be same as key class of InputFormat.\n      validateTranslationFunction(\n          getinputFormatKeyClass(),\n          getKeyTranslationFunction(),\n          \"Key translation's input type is not same as hadoop InputFormat : %s key class : %s\");\n      // Validate that the value translation input type must be same as value class of InputFormat.\n      validateTranslationFunction(\n          getinputFormatValueClass(),\n          getValueTranslationFunction(),\n          \"Value translation's input type is not same as hadoop InputFormat :  \"\n              + \"%s value class : %s\");\n    }\n\n    /** Validates translation function given for key/value translation. */\n    private void validateTranslationFunction(\n        TypeDescriptor<?> inputType, SimpleFunction<?, ?> simpleFunction, String errorMsg) {\n      if (simpleFunction != null && !simpleFunction.getInputTypeDescriptor().equals(inputType)) {\n        throw new IllegalArgumentException(\n            String.format(errorMsg, getinputFormatClass().getRawType(), inputType.getRawType()));\n      }\n    }\n\n    /**\n     * Returns the default coder for a given type descriptor. Coder Registry is queried for correct\n     * coder, if not found in Coder Registry, then check if the type descriptor provided is of type\n     * Writable, then WritableCoder is returned, else exception is thrown \"Cannot find coder\".\n     */\n    @SuppressWarnings({\"unchecked\", \"WeakerAccess\"})\n    public <T> Coder<T> getDefaultCoder(TypeDescriptor<?> typeDesc, CoderRegistry coderRegistry) {\n      Class classType = typeDesc.getRawType();\n      try {\n        return (Coder<T>) coderRegistry.getCoder(typeDesc);\n      } catch (CannotProvideCoderException e) {\n        if (Writable.class.isAssignableFrom(classType)) {\n          return (Coder<T>) WritableCoder.of(classType);\n        }","sourceCodeStart":569,"sourceCodeEnd":605,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/hadoop-format/src/main/java/org/apache/beam/sdk/io/hadoop/format/HadoopFormatIO.java#L569-L605","documentation":"HadoopFormatIO.validateTranslationFunction() throws IllegalArgumentException when the user-supplied key/value translation SimpleFunction's input type does not match the expected key or value type of the configured Hadoop InputFormat. It fails fast at pipeline construction rather than at runtime.","triggerScenarios":"Calling .withKeyTranslation(fn) or .withValueTranslation(fn) on HadoopFormatIO.Read where fn.getInputTypeDescriptor() differs from the InputFormat's key class or value class respectively.","commonSituations":"Translating a WritableComparable key (e.g. LongWritable) with a function typed for plain Long; copy-pasted translation functions between jobs with different InputFormats; generic type erasure hiding the mismatch until validation.","solutions":["Make the translation function's input type exactly match the InputFormat's key/value class (e.g. SimpleFunction<LongWritable, Long>).","Verify getinputFormatClass() key/value types via the InputFormat's setInputKeyClass/setInputValueClass configuration and align the function.","Add explicit generic type parameters so the compiler catches the mismatch before runtime."],"exampleFix":"// before\n.withValueTranslation(new SimpleFunction<String, String>() {...}) // InputFormat value is Text\n// after\n.withValueTranslation(new SimpleFunction<Text, String>() {\n  public String apply(Text t) { return t.toString(); }\n})","handlingStrategy":"type-guard","validationCode":"if (!fn.getInputTypeDescriptor().equals(TypeDescriptor.of(keyClass))) { throw new IllegalArgumentException(\"translation input must be \" + keyClass); }","typeGuard":"<K> SimpleFunction<K,?> typedFn(Class<K> expected, SimpleFunction<? super K,?> fn) { checkArgument(fn.getInputTypeDescriptor().getRawType().isAssignableFrom(expected)); return (SimpleFunction<K,?>) fn; }","tryCatchPattern":"try { read.withKeyTranslation(fn).expand(p); } catch (IllegalArgumentException e) { throw new IllegalStateException(\"Fix translation function input type to match InputFormat key class\", e); }","preventionTips":["Type translation functions with the exact Writable classes from the InputFormat config","Use explicit generics instead of raw lambdas","Validate key/value classes against the function types in tests"],"tags":["java","beam","type-mismatch","hadoop-inputformat"],"backgroundTag":"type-mismatch","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}