pentaho/pentaho-kettle · error · KettleValueException

The 'sqrt' function only works on numeric data.

Error message

The 'sqrt' function only works on numeric data.

What it means

ValueDataUtil.sqrt() only implements TYPE_NUMBER, TYPE_INTEGER, and TYPE_BIGNUMBER. Any other value type (string, date, boolean, binary) hits the switch's default branch and throws this KettleValueException. It signals that the field passed to SQRT is not numeric.

Solutions

  1. Convert the field to a numeric type before SQRT (Select values step: String -> Number/Integer)
  2. Fix the input step's type mapping (Text file input / Excel input column type) so the field is read as numeric
  3. If the value is a numeric string, use a 'String cut/Replace' + conversion or 'If field value is null'/calculator conversion to Number first
  4. Check the Calculator step's field A selection — a non-numeric field was probably picked

Example fix

// before
ValueMetaInterface metaA = new ValueMetaString("amount");
Object r = ValueDataUtil.sqrt(metaA, dataA); // throws
// after
ValueMetaInterface metaA = new ValueMetaNumber("amount");
Object numeric = ValueDataUtil.convertData(new ValueMetaString("amount"), dataA, metaA);
Object r = ValueDataUtil.sqrt(metaA, numeric);
Defensive patterns

Strategy: type-guard

Validate before calling

int t = metaA.getType();
if (t == ValueMetaInterface.TYPE_NUMBER || t == ValueMetaInterface.TYPE_INTEGER || t == ValueMetaInterface.TYPE_BIGNUMBER) {
  result = ValueDataUtil.sqrt(metaA, dataA);
} else {
  // convert first
  ValueMetaInterface numMeta = new ValueMetaNumber(metaA.getName());
  Object numData = ValueDataUtil.convertData(metaA, dataA, numMeta);
  result = ValueDataUtil.sqrt(numMeta, numData);
}

Type guard

boolean isNumericMeta(ValueMetaInterface meta) {
  if (meta == null) return false;
  int t = meta.getType();
  return t == ValueMetaInterface.TYPE_NUMBER
    || t == ValueMetaInterface.TYPE_INTEGER
    || t == ValueMetaInterface.TYPE_BIGNUMBER;
}

Try / catch

try {
  result = ValueDataUtil.sqrt(metaA, dataA);
} catch (KettleValueException e) {
  if (e.getMessage().contains("only works on numeric data")) {
    logError("Non-numeric field " + metaA.getName() + " (type=" + metaA.getTypeDesc() + ") passed to SQRT");
  }
  throw e; // type errors are configuration bugs, do not swallow
}

Prevention

When it happens

Trigger: ValueDataUtil.sqrt(metaA, dataA) (or SQRT in a Calculator/Formula step) where metaA.getType() is not TYPE_NUMBER, TYPE_INTEGER, or TYPE_BIGNUMBER — most commonly a String field.

Common situations: CSV/Excel inputs read entirely as strings, fields typed as String after a text-file input step, forgetting a 'Select values' / type-conversion step before the Calculator, boolean or date columns mistakenly wired into SQRT.

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


AI-assisted analysis of pentaho/pentaho-kettle@f3058517a1 (2026-09-13). Data as JSON: /api/errors/0e6d0c5287662fc8. Report an issue: GitHub.

Appendix: source

Thrown at core/src/main/java/org/pentaho/di/core/row/ValueDataUtil.java:946

        if ( num >= 0 ) {
          return new Double( Math.sqrt( num.doubleValue() ) );
        }
        throw new KettleValueException( valueNotNegative( num ) );
      case ValueMetaInterface.TYPE_INTEGER:
        num = metaA.getNumber( dataA );
        if ( num >= 0 ) {
          return new Long( Math.round( Math.sqrt( num.doubleValue() ) ) );
        }
        throw new KettleValueException( valueNotNegative( num ) );
      case ValueMetaInterface.TYPE_BIGNUMBER:
        num = metaA.getNumber( dataA );
        if ( num >= 0 ) {
          return BigDecimal.valueOf( Math.sqrt( num.doubleValue() ) );
        }
        throw new KettleValueException( valueNotNegative( num ) );

      default:
        throw new KettleValueException( "The 'sqrt' function only works on numeric data." );
    }
  }

  private static String valueNotNegative( final Double num ) {
    return "The value: [" + num + "] is a negative number. "
      + "The 'sqrt' function only works with non-negative numbers.";
  }

  /**
   * 100 * A / B
   *
   * @param metaA
   * @param dataA
   * @param metaB
   * @param dataB
   * @return
   * @throws KettleValueException
   */

View on GitHub (pinned to f3058517a1)