{"record":{"id":"0678530681704dec","repo":"pentaho/pentaho-kettle","slug":"i-don-t-know-how-to-convert-binary-values-to-integers","errorCode":null,"errorMessage":" : I don't know how to convert binary values to integers.","messagePattern":" : I don't know how to convert binary values to integers\\.","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/row/value/ValueMetaBase.java","lineNumber":2128,"sourceCode":"              return new Long( ( (BigDecimal) convertBinaryStringToNativeType( (byte[]) object ) ).longValue() );\n            case STORAGE_TYPE_INDEXED:\n              return new Long( ( (BigDecimal) index[( (Integer) object ).intValue()] ).longValue() );\n            default:\n              throw new KettleValueException( toString() + \" : Unknown storage type \" + storageType + \" specified.\" );\n          }\n        case TYPE_BOOLEAN:\n          switch ( storageType ) {\n            case STORAGE_TYPE_NORMAL:\n              return convertBooleanToInteger( (Boolean) object );\n            case STORAGE_TYPE_BINARY_STRING:\n              return convertBooleanToInteger( (Boolean) convertBinaryStringToNativeType( (byte[]) object ) );\n            case STORAGE_TYPE_INDEXED:\n              return convertBooleanToInteger( (Boolean) index[( (Integer) object ).intValue()] );\n            default:\n              throw new KettleValueException( toString() + \" : Unknown storage type \" + storageType + \" specified.\" );\n          }\n        case TYPE_BINARY:\n          throw new KettleValueException( toString() + \" : I don't know how to convert binary values to integers.\" );\n        case TYPE_SERIALIZABLE:\n          throw new KettleValueException( toString()\n              + \" : I don't know how to convert serializable values to integers.\" );\n        default:\n          throw new KettleValueException( toString() + \" : Unknown type \" + type + \" specified.\" );\n      }\n    } catch ( Exception e ) {\n      throw new KettleValueException( \"Unexpected conversion error while converting value [\" + toString()\n          + \"] to an Integer\", e );\n    }\n  }\n\n  @Override\n  public BigDecimal getBigNumber( Object object ) throws KettleValueException {\n    try {\n      if ( isNull( object ) ) {\n        return null;\n      }","sourceCodeStart":2110,"sourceCodeEnd":2146,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/row/value/ValueMetaBase.java#L2110-L2146","documentation":"ValueMetaBase.getInteger() is asked to return a Long for a value whose metadata type is TYPE_BINARY. There is no defined conversion from raw byte[] binary data to an integer, so the method unconditionally throws KettleValueException. This is a deliberate refusal: the caller has an incompatible value type in the row for the requested conversion.","triggerScenarios":"Calling getInteger(Object) (or the row-level getInteger(row, index) helper) on a ValueMeta whose type was set to ValueMetaInterface.TYPE_BINARY, with any non-null object value. Also happens when a step hands binary data to a field expected to be numeric.","commonSituations":"Custom plugin steps putting byte[] into a field typed as binary then downstream steps doing arithmetic or numeric mapping; row metadata built with TYPE_BINARY by mistake; transformations that read blobs into normal row streams then apply a 'convert to integer' step.","solutions":["Change the field's value metadata type to TYPE_INTEGER (or TYPE_STRING) instead of TYPE_BINARY, e.g. new ValueMetaInteger(name) or setValueMeta with the right type","Decode the byte[] yourself first (e.g. parse bytes to a string, then use a String/Integer value meta's getInteger) before calling getInteger","If the data is actually binary-encoded strings, set storage type STORAGE_TYPE_BINARY_STRING with a TYPE_INTEGER meta so convertBinaryStringToNativeType handles it, rather than TYPE_BINARY"],"exampleFix":"// before\nValueMetaInterface meta = new ValueMetaBase(\"col\", ValueMetaInterface.TYPE_BINARY);\nLong n = meta.getInteger(object); // throws\n// after\nValueMetaInterface meta = new ValueMetaInteger(\"col\");\n// or convert explicitly:\nValueMetaInterface intMeta = new ValueMetaInteger(\"col\");\nLong n = intMeta.getInteger(new String(bytes, StandardCharsets.UTF_8).trim());","handlingStrategy":"validation","validationCode":"if (meta.getType() == ValueMetaInterface.TYPE_BINARY) {\n  throw new IllegalArgumentException(\"Field \" + meta.getName() + \" is binary; cannot read as integer\");\n}\nLong n = meta.getInteger(object);","typeGuard":"boolean isNumericReadable(ValueMetaInterface m) {\n  int t = m.getType();\n  return t == ValueMetaInterface.TYPE_INTEGER || t == ValueMetaInterface.TYPE_NUMBER\n      || t == ValueMetaInterface.TYPE_BIGNUMBER || t == ValueMetaInterface.TYPE_STRING;\n}","tryCatchPattern":"try {\n  Long n = meta.getInteger(object);\n} catch (KettleValueException e) {\n  log.error(\"Cannot convert field \" + meta.getName() + \" to integer\", e);\n  // skip row or route to error handling stream\n}","preventionTips":["Check valueMeta.getType() before numeric access","Never declare fields TYPE_BINARY unless raw byte passthrough is intended","Use ValueMetaInteger/ValueMetaNumber classes rather than raw type codes","Use Kettle error-handling streams to divert bad rows instead of failing the transformation"],"tags":["kettle","pdi","type-conversion","binary"],"backgroundTag":"unsupported-operation","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"}