{"record":{"id":"9545a24cf0ab6618","repo":"pentaho/pentaho-kettle","slug":"i-don-t-know-how-to-convert-binary-values-to-numbers","errorCode":null,"errorMessage":" : I don't know how to convert binary values to numbers.","messagePattern":" : I don't know how to convert binary values to numbers\\.","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/row/value/ValueMetaBase.java","lineNumber":2041,"sourceCode":"              return new Double( ( (BigDecimal) convertBinaryStringToNativeType( (byte[]) object ) ).doubleValue() );\n            case STORAGE_TYPE_INDEXED:\n              return new Double( ( (BigDecimal) index[( (Integer) object ).intValue()] ).doubleValue() );\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 convertBooleanToNumber( (Boolean) object );\n            case STORAGE_TYPE_BINARY_STRING:\n              return convertBooleanToNumber( (Boolean) convertBinaryStringToNativeType( (byte[]) object ) );\n            case STORAGE_TYPE_INDEXED:\n              return convertBooleanToNumber( (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 numbers.\" );\n        case TYPE_SERIALIZABLE:\n          throw new KettleValueException( toString() + \" : I don't know how to convert serializable values to numbers.\" );\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 a Number\", e );\n    }\n  }\n\n  @Override\n  public Long getInteger( Object object ) throws KettleValueException {\n    try {\n      if ( isNull( object ) ) {\n        return null;\n      }\n      switch ( type ) {","sourceCodeStart":2023,"sourceCodeEnd":2059,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/row/value/ValueMetaBase.java#L2023-L2059","documentation":"ValueMetaBase.getNumber() throws this KettleValueException when the value metadata has type TYPE_BINARY, because there is no defined conversion from a raw byte[] payload to a Double number. Pentaho Kettle (PDI) simply refuses to guess a numeric interpretation of opaque binary data. You must decode the bytes yourself (e.g. to a String or numeric type) before requesting a Number.","triggerScenarios":"Calling ValueMeta.getNumber(Object) (or row.getNumber()/getRow with conversion) on a field whose valueMeta.getType() == ValueMetaInterface.TYPE_BINARY and whose data is a byte[].","commonSituations":"Reading binary columns from databases or files (BLOB, images, PDFs) and asking for them as numbers; misconfigured CSV/text input steps that set the field type to Binary instead of String/Number; custom transformation code that copies row data into Number-typed targets without changing the metadata type.","solutions":["Change the field's value metadata type from TYPE_BINARY to a convertible type (TYPE_STRING or TYPE_INTEGER) using a 'Select values' / Metadata step or a new ValueMeta before calling getNumber().","Convert the byte[] manually first (e.g. new ValueMetaString(...).convertBinaryStringToNativeType(bytes) or decode to a String/Integer) and then request the Number.","If the column is genuinely opaque binary, do not call getNumber(); store/pass it as byte[] and only derive numeric values (length, checksum) explicitly.","Catch KettleValueException and log/skip the field if binary data in a numeric context is acceptable."],"exampleFix":"// before\nValueMetaInterface meta = new ValueMetaBase(\"blob\", ValueMetaInterface.TYPE_BINARY);\nDouble n = meta.getNumber(rowData[0]); // throws\n\n// after\nValueMetaInterface meta = new ValueMetaBase(\"blob\", ValueMetaInterface.TYPE_STRING);\nDouble n = meta.getNumber(meta.convertBinaryStringToNativeType((byte[]) rowData[0]));","handlingStrategy":"type-guard","validationCode":"if (meta.getType() == ValueMetaInterface.TYPE_BINARY) {\n  throw new IllegalArgumentException(\"Field '\" + meta.getName() + \"' is BINARY; convert to String/Integer before getNumber()\");\n}","typeGuard":"boolean isNumberConvertible(ValueMetaInterface m) {\n  int t = m.getType();\n  return t == ValueMetaInterface.TYPE_STRING || t == ValueMetaInterface.TYPE_INTEGER\n      || t == ValueMetaInterface.TYPE_NUMBER || t == ValueMetaInterface.TYPE_BIGNUMBER\n      || t == ValueMetaInterface.TYPE_BOOLEAN || t == ValueMetaInterface.TYPE_DATE;\n}","tryCatchPattern":"try {\n  Double n = meta.getNumber(value);\n} catch (KettleValueException e) {\n  log.warn(\"Cannot convert \" + meta.getName() + \" (binary) to Number\", e);\n}","preventionTips":["Set binary columns (BLOBs, images) to TYPE_STRING or the correct numeric type in input step metadata, never TYPE_BINARY, when numeric use is expected.","Check meta.getType() before calling any getXxx() conversion helper.","Centralize conversions behind a utility that maps unsupported types explicitly."],"tags":["kettle","type-conversion","binary-data","value-metadata"],"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"}