pentaho/pentaho-kettle · error · KettleValueException

Function DAT2STR only works on a date

Error message

Function DAT2STR only works on a date

What it means

Guard in the legacy Value dat2str() function: the value's type is not VALUE_TYPE_DATE, so the date-to-string conversion is refused. The input at fault is the current Value whose getType() returned something other than Date.

Solutions

  1. Convert the value to a Date first (e.g. str2dat) before calling DAT2STR
  2. Fix the upstream step so the field is produced as a Date type
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at core/src/main/java/org/pentaho/di/compatibility/Value.java:3119 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at core/src/main/java/org/pentaho/di/compatibility/Value.java:3119

      if ( getType() == VALUE_TYPE_DATE ) {
        SimpleDateFormat df = new SimpleDateFormat();

        DateFormatSymbols dfs = new DateFormatSymbols();
        if ( arg1 != null ) {
          dfs.setLocalPatternChars( arg1 );
        }
        if ( arg0 != null ) {
          df.applyPattern( arg0 );
        }
        try {
          setValue( df.format( getDate() ) );
        } catch ( Exception e ) {
          setType( VALUE_TYPE_STRING );
          setNull();
          throw new KettleValueException( "TO_CHAR Couldn't convert Date to String " + e.toString() );
        }
      } else {
        throw new KettleValueException( "Function DAT2STR only works on a date" );
      }
    }

    return this;
  }

  // implement the TO_DATE function, arguments in args[]
  public Value num2dat() throws KettleValueException {
    if ( isNull() ) {
      setType( VALUE_TYPE_DATE );
    } else {
      if ( isNumeric() ) {
        setValue( new Date( getInteger() ) );
        setLength( -1, -1 );
      } else {
        throw new KettleValueException( "Function NUM2DAT only works on a number" );
      }
    }

View on GitHub (pinned to f3058517a1)