{"record":{"id":"59d6f3db11f4e463","repo":"pentaho/pentaho-kettle","slug":"comparing-values-can-not-be-done-with-data-type","errorCode":null,"errorMessage":" : Comparing values can not be done with data type : ","messagePattern":" : Comparing values can not be done with data type : ","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/core/row/value/ValueMetaBase.java","lineNumber":3769,"sourceCode":"        byte[] b1 = (byte[]) data1;\n        byte[] b2 = (byte[]) data2;\n\n        int length = b1.length < b2.length ? b1.length : b2.length;\n\n        cmp = b1.length - b2.length;\n        if ( cmp == 0 ) {\n          for ( int i = 0; i < length; i++ ) {\n            cmp = b1[ i ] - b2[ i ];\n            if ( cmp != 0 ) {\n              cmp = cmp < 0 ? -1 : 1;\n              break;\n            }\n          }\n        }\n\n        break;\n      default:\n        throw new KettleValueException( toString() + \" : Comparing values can not be done with data type : \"\n          + getType() );\n    }\n    return cmp;\n\n  }\n\n  /**\n   * Compare 2 values of the same data type\n   *\n   * @param data1\n   *          the first value\n   * @param meta2\n   *          the second value's metadata\n   * @param data2\n   *          the second value\n   * @return 0 if the values are equal, -1 if data1 is smaller than data2 and +1 if it's larger.\n   * @throws KettleValueException\n   *           In case we get conversion errors","sourceCodeStart":3751,"sourceCodeEnd":3787,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/core/row/value/ValueMetaBase.java#L3751-L3787","documentation":"ValueMetaBase.typeCompare() compares two values by switching on getType(); known types are String, Integer, Number, Date, BigNumber, Boolean, Binary. Any other type code (e.g. TYPE_NONE, -1, or a type from an unrecognized ValueMeta subclass) falls to the default branch and throws this KettleValueException. It means sorting/comparing was attempted on a value whose data type is not comparable.","triggerScenarios":"Calling compare(Object,Object), or any sort/group/merge that uses it, on a ValueMetaBase whose type is TYPE_NONE (0) or otherwise unhandled — typically a ValueMeta created without a valid type or with a type not mapped in typeCompare.","commonSituations":"Building ValueMeta with new ValueMeta(\"x\") and forgetting to set a type; passing TYPE_NONE fields into Sort Rows / Merge Join / Group By steps; custom ValueMeta implementations returning unsupported type codes; fields from plugins with types unknown to core comparison.","solutions":["Set a concrete comparable type on the value metadata before sorting/comparing (e.g. setType(ValueMetaInterface.TYPE_STRING)).","Filter out or convert TYPE_NONE / unsupported fields before steps that sort or compare rows.","Provide a custom Comparator via setComparator() on the ValueMeta so compare() bypasses the type switch.","Check plugin-supplied fields and register/convert their types to core Kettle types before comparison."],"exampleFix":"// before\nValueMetaInterface meta = new ValueMeta(\"x\"); // type = TYPE_NONE\nrows.sort(meta.compare(...)); // throws\n\n// after\nValueMetaInterface meta = new ValueMeta(\"x\", ValueMetaInterface.TYPE_STRING);\nif (meta.getType() == ValueMetaInterface.TYPE_NONE) {\n  meta.setType(ValueMetaInterface.TYPE_STRING);\n}","handlingStrategy":"validation","validationCode":"if (meta.getType() == ValueMetaInterface.TYPE_NONE) {\n  throw new IllegalStateException(\"Field \" + meta.toStringMeta() + \" has no comparable type\");\n}","typeGuard":"boolean isComparable(ValueMetaInterface m) {\n  switch (m.getType()) {\n    case ValueMetaInterface.TYPE_STRING:\n    case ValueMetaInterface.TYPE_INTEGER:\n    case ValueMetaInterface.TYPE_NUMBER:\n    case ValueMetaInterface.TYPE_DATE:\n    case ValueMetaInterface.TYPE_BIGNUMBER:\n    case ValueMetaInterface.TYPE_BOOLEAN:\n    case ValueMetaInterface.TYPE_BINARY:\n      return true;\n    default:\n      return false;\n  }\n}","tryCatchPattern":"try { rows.sort(comparatorUsingMeta); } catch (KettleValueException e) {\n  if (e.getMessage().contains(\"Comparing values can not be done\")) {\n    logger.logError(\"Non-comparable field type in sort: \" + e.getMessage());\n  }\n  throw e;\n}","preventionTips":["Always construct ValueMeta with an explicit type argument.","Scrub TYPE_NONE fields with a Select Values step before sort/group/merge.","Register custom comparators via setComparator() for plugin-specific types.","Run transformation metadata checks (transMeta.checkSteps) before execution."],"tags":["pdi","kettle","comparison","data-type"],"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"}