{"record":{"id":"197367314d918ee1","repo":"pentaho/pentaho-kettle","slug":"please-specify-a-boolean-type-for-field","errorCode":null,"errorMessage":"Please specify a Boolean type for field [","messagePattern":"Please specify a Boolean 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":180,"sourceCode":"              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      }\n\n      return outputRowData;\n    } catch ( Throwable e ) {\n      throw new KettleValueException( e );\n    }\n  }","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/engine/src/main/java/org/pentaho/di/trans/steps/formula/Formula.java#L162-L198","documentation":"KettleValueException thrown in Formula.calcFields() when the formula evaluates to a Boolean but the output field's declared value type is not ValueMetaInterface.TYPE_BOOLEAN. The step will not coerce Boolean results to String/Number automatically.","triggerScenarios":"A formula such as \"[a] > 10\" or a comparison returning Boolean is assigned to a field whose Type column is String, Number, Integer, etc.","commonSituations":"Adding a boolean filter column with output type left as default String; changing a formula from numeric to comparison without updating the declared output type.","solutions":["Set the output field Type to Boolean in the Formula step dialog.","Or convert the result to a non-boolean explicitly: IF([a]>10; 1; 0) with type Number, or IF([a]>10;\"Y\";\"N\") with type String.","Re-run the step's field-type inference after editing formulas."],"exampleFix":"// before\nfn.setValueType(ValueMetaInterface.TYPE_STRING); // formula: [x]>0\n// after\nfn.setValueType(ValueMetaInterface.TYPE_BOOLEAN);","handlingStrategy":"validation","validationCode":"if (result instanceof Boolean && fn.getValueType() != ValueMetaInterface.TYPE_BOOLEAN) {\n  fn.setValueType(ValueMetaInterface.TYPE_BOOLEAN);\n}","typeGuard":"if (result instanceof Boolean && fn.getValueType() != ValueMetaInterface.TYPE_BOOLEAN) { throw new IllegalArgumentException(\"Declare Boolean type for \" + fn.getFieldName()); }","tryCatchPattern":null,"preventionTips":["Set output Type=Boolean for comparison formulas","Use IF(cond;1;0) with Number type if you need numeric output","Update declared types whenever the formula result type changes"],"tags":["formula","type-mismatch","boolean"],"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"}