pentaho/pentaho-kettle · error · RuntimeException

The function call decode requires more than 1 argument.

Error message

The function call decode requires more than 1 argument.

What it means

decode mimics Oracle's DECODE: it compares the first argument against subsequent pairs and returns the matching value (or a trailing default). It requires more than one argument; if called with only one (just the value to compare), this RuntimeException is thrown.

Solutions

  1. Call decode with at least 2 arguments: decode(value, pair-or-default...), e.g. decode(x, 'A', 1, 2).
  2. Add the search/result pairs you intended to compare against.
  3. If no pairs are needed, don't use decode at all - just use the value directly.

Example fix

// before
var r = decode(status); // throws
// after
var r = decode(status, 'A', 1, 'B', 2, 0);
Defensive patterns

Strategy: validation

Validate before calling

function safeDecode() {
  if (arguments.length < 2) return arguments[0];
  return decode.apply(null, arguments);
}

Try / catch

try {
  var r = decode(x, 'A', 1, 'B', 2, 0);
} catch (e) {
  var r = 0; // default when decode is unusable
}

Prevention

When it happens

Trigger: Calling decode(x) with a single argument in a JavaScript transformation step.

Common situations: Porting SQL DECODE expressions incorrectly, dropping the search/result pairs during refactoring.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at engine/src/main/java/org/pentaho/di/trans/steps/script/ScriptAddedFunctions.java:1499

      if ( ArgList.length >= 2 ) {
        if ( isNull( ArgList, new int[] { 0, 1 } ) ) {
          return null;
        } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {
          return undefinedValue;
        }
        Object objToCompare = ArgList[0];
        for ( int i = 1; i < ArgList.length - 1; i = i + 2 ) {
          if ( ArgList[i].equals( objToCompare ) ) {
            return ArgList[i + 1];
          }
        }
        if ( ArgList.length % 2 == 0 ) {
          return ArgList[ArgList.length - 1];
        } else {
          return objToCompare;
        }
      } else {
        throw new RuntimeException( "The function call decode requires more than 1 argument." );
      }
    } catch ( Exception e ) {
      throw new RuntimeException( "The function call decode is not valid : " + e.getMessage() );
    }
  }

  public static String replace( ScriptEngine actualContext, Bindings actualObject, Object[] ArgList,
    Object FunctionContext ) {
    try {
      if ( ArgList.length >= 2 && ( ArgList.length - 1 ) % 2 == 0 ) {
        if ( isNull( ArgList, new int[] { 0, 1 } ) ) {
          return null;
        } else if ( isUndefined( ArgList, new int[] { 0, 1 } ) ) {
          return (String) undefinedValue;
        }
        String objForReplace = (String) ArgList[0];
        for ( int i = 1; i < ArgList.length - 1; i = i + 2 ) {
          objForReplace = objForReplace.replaceAll( (String) ArgList[i], (String) ArgList[i + 1] );

View on GitHub (pinned to f3058517a1)