pentaho/pentaho-kettle · error · KettleValueException
Function MOD only works with numeric data
Error message
Function MOD only works with numeric data
What it means
Thrown by Value.mod() in Pentaho Kettle's legacy compatibility Value class when the MOD function is called on a value whose type is not numeric. The class deliberately guards each mathematical function with an isNumeric() check and throws KettleValueException instead of silently producing garbage. The value's type must be Number or Integer (or BigNumber) before MOD is applied.
Solutions
- Check the value's type before calling mod(): only call it when value.isNumeric() is true.
- Convert the value to numeric first, e.g. value.convertToNumber() or read the field with the correct Number/Integer type in the input step.
- Fix the field metadata in the input or a 'Select values' step so the column is typed as Number/Integer.
- Wrap the call in try/catch for KettleValueException and handle the non-numeric branch explicitly.
Example fix
// before
Value result = value.mod(divisor); // throws if value is a String
// after
if (value.isNumeric()) {
Value result = value.mod(divisor);
} else {
Value num = new Value(value.getName(), value.getNumber()); // or convert type upstream
} Defensive patterns
Strategy: type-guard
Validate before calling
if (!value.isNumeric()) { throw new IllegalArgumentException(value.getName() + " is not numeric; cannot MOD"); } Type guard
boolean modSafe(Value v) { return v != null && (v.isNull() || v.isNumeric()); } Try / catch
try { result = value.mod(divisor); } catch (KettleValueException e) { log.error("MOD on non-numeric: " + e.getMessage()); result = null; } Prevention
- Always type numeric columns as Number/Integer in input steps
- Call isNumeric() before any math function on Value
- Keep transformations' field metadata consistent end-to-end
When it happens
Trigger: Calling value.mod(otherValue) (or the MOD function in a Kettle formula/script step) when the receiving Value has a String, Date, Boolean, or Binary type rather than a numeric type.
Common situations: A CSV/text input field was auto-detected or typed as String but the transformation applies MOD; a field's metadata was changed in a Select Values step; users pass date or boolean columns into a calculator formula.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- The input field for stats calc #
- BaseStep.SafeMode.Exception.MixingTypes
- DynamicSQLRow.Exception.TemplateReturnDataTypeError
- ElasticSearchBulk.Error.NoJsonFieldFormat
- Error parsing field #
AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13).
Data as JSON: /api/errors/379e2569c98ed1cb.
Report an issue: GitHub.
Appendix: source
Thrown at core/src/main/java/org/pentaho/di/compatibility/Value.java:2648
return mod( (double) arg );
}
public Value mod( byte arg ) throws KettleValueException {
return mod( (double) arg );
}
public Value mod( double arg0 ) throws KettleValueException {
if ( isNull() ) {
return this;
}
if ( isNumeric() ) {
double n1 = getNumber();
double n2 = arg0;
setValue( n1 - ( n2 * Math.floor( n1 / n2 ) ) );
} else {
throw new KettleValueException( "Function MOD only works with numeric data" );
}
return this;
}
// implement the NVL function, arguments in args[]
public Value nvl( Value alt ) {
if ( isNull() ) {
setValue( alt );
}
return this;
}
// implement the POWER function, arguments in args[]
public Value power( BigDecimal arg ) throws KettleValueException {
return power( new Value( "tmp", arg ) );
}
View on GitHub (pinned to f3058517a1)