{"record":{"id":"d3246bf2da9524d2","repo":"pentaho/pentaho-kettle","slug":"function-log-only-works-with-a-number","errorCode":null,"errorMessage":"Function LOG only works with a number","messagePattern":"Function LOG only works with a number","errorType":"exception","errorClass":"KettleValueException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/pentaho/di/compatibility/Value.java","lineNumber":2528,"sourceCode":"\n    if ( getType() == VALUE_TYPE_STRING ) {\n      setValue( (double) getString().length() );\n    } else {\n      throw new KettleValueException( \"Function LENGTH only works with a string\" );\n    }\n    return this;\n  }\n\n  // implement the LOG function, arguments in args[]\n  public Value log() throws KettleValueException {\n    if ( isNull() ) {\n      return this;\n    }\n\n    if ( isNumeric() ) {\n      setValue( Math.log( getNumber() ) );\n    } else {\n      throw new KettleValueException( \"Function LOG only works with a number\" );\n    }\n\n    return this;\n  }\n\n  // implement the LOWER function, arguments in args[]\n  public Value lower() {\n    if ( isNull() ) {\n      setType( VALUE_TYPE_STRING );\n    } else {\n      setValue( getString().toLowerCase() );\n    }\n\n    return this;\n  }\n\n  // implement the LPAD function: left pad strings or numbers...\n  public Value lpad( Value len ) {","sourceCodeStart":2510,"sourceCodeEnd":2546,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/compatibility/Value.java#L2510-L2546","documentation":"The log() method of Kettle's legacy Value class computes the natural logarithm via Math.log. It throws this KettleValueException when the Value is not numeric, since Math.log requires a double. Additionally, callers should remember Math.log is undefined for values <= 0 (NaN), though the type check itself only rejects non-numeric types.","triggerScenarios":"Calling Value.log() on a String/Date/Boolean-typed Value - e.g. taking the log of a measurement field read as text.","commonSituations":"Log-scale calculations where the input column from CSV/Excel was not detected as numeric; intermediate fields converted to String for formatting and never converted back.","solutions":["Convert the Value to Number before calling log() (setType(VALUE_TYPE_NUMBER))","Fix the input/conversion steps so the field stays numeric","Guard with isNumeric() (and consider validating value > 0) before the call"],"exampleFix":"// before\nValue result = value.log(); // value is a String\n// after\nif (!value.isNumeric()) {\n  value.setType(Value.VALUE_TYPE_NUMBER);\n}\nValue result = value.log();","handlingStrategy":"type-guard","validationCode":"if (value == null || !value.isNumeric()) {\n  throw new IllegalArgumentException(\"LOG requires a numeric value, got type \" + (value == null ? \"null\" : value.getType()));\n}\n// also consider domain: Math.log is undefined for values <= 0\nif (value.getNumber() <= 0) {\n  throw new IllegalArgumentException(\"LOG requires a positive value\");\n}","typeGuard":"boolean isPositiveNumeric(Value v) { return v != null && v.isNumeric() && v.getNumber() > 0; }","tryCatchPattern":"try {\n  result = value.log();\n} catch (KettleValueException e) {\n  value.setType(Value.VALUE_TYPE_NUMBER);\n  result = value.log();\n}","preventionTips":["Convert measurement fields to Number before logarithmic calculations","Check isNumeric() and value > 0 before calling log()","Avoid passing formatted/String intermediate fields into log-scale math","Verify auto-detected column types when input file formats change"],"tags":["kettle","numeric-type","math-function","runtime-type-check"],"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"}