{"record":{"id":"ad843f6c1b3370f5","repo":"pentaho/pentaho-kettle","slug":"function-sin-only-works-with-a-number","errorCode":null,"errorMessage":"Function SIN only works with a number","messagePattern":"Function SIN 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":2862,"sourceCode":"      } 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  }\n\n  // implement the SQRT function, arguments in args[]\n  public Value sqrt() throws KettleValueException {\n    if ( isNull() ) {\n      return this;\n    }\n    if ( isNumeric() ) {\n      setValue( Math.sqrt( getNumber() ) );\n    } else {\n      throw new KettleValueException( \"Function SQRT only works with a number\" );\n    }\n\n    return this;\n  }","sourceCodeStart":2844,"sourceCodeEnd":2880,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/core/src/main/java/org/pentaho/di/compatibility/Value.java#L2844-L2880","documentation":"Thrown by Value.sin() when the value is not numeric. SIN computes Math.sin(getNumber()) and the isNumeric() guard rejects String, Date, Boolean, and Binary values with KettleValueException. Nulls return early without error.","triggerScenarios":"Calling value.sin() on a non-numeric Value type, typically a String angle value read from a text source.","commonSituations":"Trigonometry on a column typed as String; degree/angle data ingested as text; field metadata changed upstream.","solutions":["Guard with value.isNumeric() before calling sin().","Convert the angle field to Number (e.g. StringToNumber step or Value constructor with a double).","Fix the input step's field type metadata.","Catch KettleValueException and handle the non-numeric branch."],"exampleFix":"// before\nValue s = value.sin(); // throws for String-typed value\n// after\nValue s = value.isNumeric() ? value.sin() : new Value(value.getName(), Math.sin(Double.parseDouble(value.getString())));","handlingStrategy":"type-guard","validationCode":"if (!value.isNumeric()) { throw new IllegalArgumentException(\"SIN requires a numeric angle\"); }","typeGuard":"boolean sinSafe(Value v) { return v != null && v.isNumeric(); }","tryCatchPattern":"try { result = value.sin(); } catch (KettleValueException e) { result = null; }","preventionTips":["Convert angle strings to numbers before trig functions","Keep trig inputs as Number type through the transformation","Check isNull() first — nulls silently pass through"],"tags":["kettle","type-mismatch","trigonometry"],"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"}