{"record":{"id":"aff08127297b1d73","repo":"pentaho/pentaho-kettle","slug":"i-don-t-know-how-to-convert-a-binary-value-to-timestamp","errorCode":null,"errorMessage":" : I don't know how to convert a binary value to timestamp.","messagePattern":" : I don't know how to convert a binary value to timestamp\\.","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/row/value/ValueMetaTimestamp.java","lineNumber":188,"sourceCode":"            return convertIntegerToTimestamp( (Long) index[ ( (Integer) object ).intValue() ] );\n          default:\n            throw new KettleValueException( toString() + \" : Unknown storage type \" + storageType + \" specified.\" );\n        }\n      case TYPE_BIGNUMBER:\n        switch ( storageType ) {\n          case STORAGE_TYPE_NORMAL:\n            return convertBigNumberToTimestamp( (BigDecimal) object );\n          case STORAGE_TYPE_BINARY_STRING:\n            return convertBigNumberToTimestamp( (BigDecimal) convertBinaryStringToNativeType( (byte[]) object ) );\n          case STORAGE_TYPE_INDEXED:\n            return convertBigNumberToTimestamp( (BigDecimal) index[ ( (Integer) object ).intValue() ] );\n          default:\n            throw new KettleValueException( toString() + \" : Unknown storage type \" + storageType + \" specified.\" );\n        }\n      case TYPE_BOOLEAN:\n        throw new KettleValueException( toString() + \" : I don't know how to convert a boolean to a timestamp.\" );\n      case TYPE_BINARY:\n        throw new KettleValueException( toString() + \" : I don't know how to convert a binary value to timestamp.\" );\n      case TYPE_SERIALIZABLE:\n        throw new KettleValueException( toString()\n          + \" : I don't know how to convert a serializable value to timestamp.\" );\n\n      default:\n        throw new KettleValueException( toString() + \" : Unknown type \" + type + \" specified.\" );\n    }\n  }\n\n  public int compare( Object data1, Object data2 ) throws KettleValueException {\n    Timestamp timestamp1 = getTimestamp( data1 );\n    Timestamp timestamp2 = getTimestamp( data2 );\n    int cmp = 0;\n    if ( timestamp1 == null ) {\n      if ( timestamp2 == null ) {\n        cmp = 0;\n      } else {\n        cmp = -1;","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/row/value/ValueMetaTimestamp.java#L170-L206","documentation":"The TYPE_BINARY case of getTimestamp() always throws this KettleValueException: PDI does not define a conversion from raw binary (byte[]) values declared as TYPE_BINARY to Timestamp. Note this differs from STORAGE_TYPE_BINARY_STRING, which is a storage detail of convertible types and is supported — this throw applies only when the field's logical type is TYPE_BINARY.","triggerScenarios":"getTimestamp(object) called on a ValueMetaTimestamp where the value meta's type is TYPE_BINARY (binary-typed field), regardless of storage type.","commonSituations":"Reading raw binary database columns or files and then attempting timestamp conversion; a field type mis-set to TYPE_BINARY during metadata construction; plugins that emit binary fields consumed by timestamp-expecting steps.","solutions":["Decode the binary yourself first (e.g. new String(bytes, encoding) then meta.convertStringToTimestamp(s)) and pass the result through the STRING branch of getTimestamp().","Fix the field's declared type: if the bytes actually encode a timestamp string, set the meta type to TYPE_STRING (or TYPE_DATE) so the supported conversion path runs.","Insert a conversion step (e.g. 'Calculator'/'User Defined Java Expression') upstream that turns the binary data into a parseable string/timestamp.","Guard in code: check meta.getType() != TYPE_BINARY before calling getTimestamp() and skip or transform such fields."],"exampleFix":"// before\nTimestamp t = meta.getTimestamp( byteArray ); // TYPE_BINARY -> throws\n// after\nString s = new String( (byte[]) byteArray, StandardCharsets.UTF_8 );\nTimestamp t = meta.convertStringToTimestamp( s );","handlingStrategy":"type-guard","validationCode":"if ( meta.getType() == ValueMetaInterface.TYPE_BINARY ) {\n  // decode bytes yourself; getTimestamp() will throw\n}","typeGuard":"boolean isTimestampConvertible( ValueMetaInterface meta ) {\n  switch ( meta.getType() ) {\n    case ValueMetaInterface.TYPE_TIMESTAMP:\n    case ValueMetaInterface.TYPE_DATE:\n    case ValueMetaInterface.TYPE_STRING:\n    case ValueMetaInterface.TYPE_NUMBER:\n    case ValueMetaInterface.TYPE_INTEGER:\n    case ValueMetaInterface.TYPE_BIGNUMBER:\n      return true;\n    default:\n      return false;\n  }\n}","tryCatchPattern":"try {\n  t = meta.getTimestamp( value );\n} catch ( KettleValueException e ) {\n  if ( e.getMessage().contains( \"convert a binary value to timestamp\" ) ) {\n    String s = new String( (byte[]) value, StandardCharsets.UTF_8 );\n    t = meta.convertStringToTimestamp( s );\n  } else { throw e; }\n}","preventionTips":["Do not declare timestamp-bearing fields as TYPE_BINARY.","Decode binary data (string encoding, struct layout) before timestamp conversion.","Remember STORAGE_TYPE_BINARY_STRING is fine; only logical TYPE_BINARY is rejected.","Check meta.getType() in generic row-processing loops."],"tags":["kettle","pdi","type-conversion","timestamp","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"}