{"record":{"id":"3bbf52094a343608","repo":"pentaho/pentaho-kettle","slug":"please-specify-a-binary-type-for-field","errorCode":null,"errorMessage":"Please specify a Binary type for field [","messagePattern":"Please specify a Binary type for field \\[","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"engine/src/main/java/org/pentaho/di/trans/steps/formula/Formula.java","lineNumber":174,"sourceCode":"              data.returnType[i] = FormulaData.RETURN_TYPE_INTEGER;\n              fn.setNeedDataConversion( fn.getValueType() != ValueMetaInterface.TYPE_INTEGER );\n            } else if ( formulaResult instanceof Long ) {\n              data.returnType[i] = FormulaData.RETURN_TYPE_LONG;\n              fn.setNeedDataConversion( fn.getValueType() != ValueMetaInterface.TYPE_INTEGER );\n            } else if ( formulaResult instanceof Date ) {\n              data.returnType[i] = FormulaData.RETURN_TYPE_DATE;\n              fn.setNeedDataConversion( fn.getValueType() != ValueMetaInterface.TYPE_DATE );\n            } else if ( formulaResult instanceof BigDecimal ) {\n              data.returnType[i] = FormulaData.RETURN_TYPE_BIGDECIMAL;\n              fn.setNeedDataConversion( fn.getValueType() != ValueMetaInterface.TYPE_BIGNUMBER );\n            } else if ( formulaResult instanceof Number ) {\n              data.returnType[i] = FormulaData.RETURN_TYPE_NUMBER;\n              fn.setNeedDataConversion( fn.getValueType() != ValueMetaInterface.TYPE_NUMBER );\n            // this types we will not make attempt to auto-convert\n            } else if ( formulaResult instanceof byte[] ) {\n              data.returnType[i] = FormulaData.RETURN_TYPE_BYTE_ARRAY;\n              if ( fn.getValueType() != ValueMetaInterface.TYPE_BINARY ) {\n                throw new KettleValueException( \"Please specify a Binary type for field [\"\n                  + fn.getFieldName() + \"] as a result of formula [\" + fn.getFormula() + \"]\" );\n              }\n            } else if ( formulaResult instanceof Boolean ) {\n              data.returnType[i] = FormulaData.RETURN_TYPE_BOOLEAN;\n              if ( fn.getValueType() != ValueMetaInterface.TYPE_BOOLEAN ) {\n                throw new KettleValueException( \"Please specify a Boolean type for field [\"\n                  + fn.getFieldName() + \"] as a result of formula [\" + fn.getFormula() + \"]\" );\n              }\n            } else {\n              data.returnType[i] = FormulaData.RETURN_TYPE_STRING;\n              fn.setNeedDataConversion( fn.getValueType() != ValueMetaInterface.TYPE_STRING );\n            }\n          }\n\n          int realIndex = ( data.replaceIndex[i] < 0 ) ? tempIndex++ : data.replaceIndex[i];\n          outputRowData[realIndex] = getReturnValue( formulaResult, data.returnType[i], realIndex, fn );\n        }\n      }","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/formula/Formula.java#L156-L192","documentation":"KettleValueException thrown in Formula.calcFields() when the formula evaluates to a byte[] but the output field's declared value type is not ValueMetaInterface.TYPE_BINARY. The step auto-converts many result types but deliberately refuses to convert byte arrays to non-binary types.","triggerScenarios":"A formula returns raw byte[] (e.g. a field holding binary data passed through, or functions returning bytes) while the 'Type' column of the formula row is set to String, Number, etc.","commonSituations":"Computing MD5/hex or file-content fields with output type String; dragging a binary field through a formula with default output type Number.","solutions":["Set the output field's Type to Binary in the Formula step dialog.","Convert the bytes explicitly in the formula (e.g. HEX_ENCODE / ENCODE functions) so the result is a String.","Handle the binary field upstream/downstream (e.g. a UDF or script step) instead of the Formula step."],"exampleFix":"// before\nfn.setValueType(ValueMetaInterface.TYPE_STRING); // but formula yields byte[]\n// after\nfn.setValueType(ValueMetaInterface.TYPE_BINARY);","handlingStrategy":"validation","validationCode":"if (formulaYieldsBytes && fn.getValueType() != ValueMetaInterface.TYPE_BINARY) {\n  fn.setValueType(ValueMetaInterface.TYPE_BINARY);\n}","typeGuard":"if (result instanceof byte[] && fn.getValueType() != ValueMetaInterface.TYPE_BINARY) { throw new IllegalArgumentException(\"Declare Binary type for \" + fn.getFieldName()); }","tryCatchPattern":null,"preventionTips":["Set output Type=Binary for byte-producing formulas","Encode bytes to hex/base64 strings in-formula when a String is wanted","Recheck declared types after changing formula expressions"],"tags":["formula","type-mismatch","binary"],"backgroundTag":"type-mismatch","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}