{"record":{"id":"228be656de1b22e8","repo":"pentaho/pentaho-kettle","slug":"function-sign-only-works-with-a-number","errorCode":null,"errorMessage":"Function SIGN only works with a number","messagePattern":"Function SIGN 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":2848,"sourceCode":"      }\n    } else if ( isNumber() ) {\n      if ( getNumber() > 0 ) {\n        value.setNumber( 1.0 );\n      } else if ( getNumber() < 0 ) {\n        value.setNumber( -1.0 );\n      } else {\n        value.setNumber( 0.0 );\n      }\n    } else if ( isInteger() ) {\n      if ( getInteger() > 0 ) {\n        value.setInteger( 1 );\n      } else if ( getInteger() < 0 ) {\n        value.setInteger( -1 );\n      } else {\n        value.setInteger( 0 );\n      }\n    } else {\n      throw new KettleValueException( \"Function SIGN only works with a number\" );\n    }\n\n    return this;\n  }\n\n  // implement the SIN function, arguments in args[]\n  public Value sin() throws KettleValueException {\n    if ( isNull() ) {\n      return this;\n    }\n    if ( isNumeric() ) {\n      setValue( Math.sin( getNumber() ) );\n    } else {\n      throw new KettleValueException( \"Function SIN only works with a number\" );\n    }\n\n    return this;\n  }","sourceCodeStart":2830,"sourceCodeEnd":2866,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/compatibility/Value.java#L2830-L2866","documentation":"Thrown by Value.sign() when the value is not numeric. SIGN returns -1, 0, or 1 as an Integer and is only defined for numeric types; the guard throws KettleValueException otherwise. Null values are returned unchanged before the check.","triggerScenarios":"Calling value.sign() on a Value typed as String, Date, Boolean, or Binary.","commonSituations":"Sign of a field that was ingested as String from a flat file; using SIGN on a Boolean column; metadata mis-typing after a database schema change.","solutions":["Check value.isNumeric() before calling sign().","Re-type the field as Number/Integer in the input or a 'Select values' step.","Convert string data to a number before applying SIGN.","Wrap in try/catch on KettleValueException with an error-handling hop."],"exampleFix":"// before\nint s = value.sign().getInteger(); // throws for String-typed value\n// after\nint s = value.isNumeric() ? value.sign().getInteger() : 0;","handlingStrategy":"type-guard","validationCode":"if (!value.isNumeric()) { throw new IllegalArgumentException(\"SIGN requires a numeric value\"); }","typeGuard":"boolean signSafe(Value v) { return v != null && v.isNumeric(); }","tryCatchPattern":"try { int s = value.sign().getInteger(); } catch (KettleValueException e) { s = 0; }","preventionTips":["Type sign-target columns as numeric at ingestion","Use isNumeric() before SIGN in scripts","Avoid applying math functions to Boolean flags"],"tags":["kettle","type-mismatch","math"],"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"}