prestodb/presto · error · PrestoException

INVALID_FUNCTION_ARGUMENT

INVALID_FUNCTION_ARGUMENT

Error message

Failed to tokenize string [%s] at offset [%d]

What it means

DateFormatParser converts a Teradata-style format string into a JSR-310 DateTimeFormatter. When a token cannot be mapped to a known DateFormat symbol, it throws INVALID_FUNCTION_ARGUMENT identifying the offending token and its offset.

Source

Thrown at presto-teradata-functions/src/main/java/com/facebook/presto/teradata/functions/dateformat/DateFormatParser.java:102

                    break;
                case DateFormat.MI:
                    builder.appendValue(MINUTE_OF_HOUR, mode.getMinTwoPositionFieldWidth(), 2, NOT_NEGATIVE);
                    break;
                case DateFormat.MM:
                    builder.appendValue(MONTH_OF_YEAR, mode.getMinTwoPositionFieldWidth(), 2, NOT_NEGATIVE);
                    break;
                case DateFormat.SS:
                    builder.appendValue(SECOND_OF_MINUTE, mode.getMinTwoPositionFieldWidth(), 2, NOT_NEGATIVE);
                    break;
                case DateFormat.YY:
                    builder.appendValueReduced(YEAR, 2, 2, 2000);
                    break;
                case DateFormat.YYYY:
                    builder.appendValue(YEAR, 4);
                    break;
                case DateFormat.UNRECOGNIZED:
                default:
                    throw new PrestoException(
                            StandardErrorCode.INVALID_FUNCTION_ARGUMENT,
                            String.format("Failed to tokenize string [%s] at offset [%d]", token.getText(), token.getCharPositionInLine()));
            }
        }
        try {
            // Append default values(0) for time fields(HH24, HH, MI, SS) because JSR-310 does not accept bare Date value as DateTime

            if (formatContainsHourOfAMPM) {
                // At the moment format does not allow to include AM/PM token, thus it was never possible to specify PM hours using 'HH' token in format
                // Keep existing behaviour by defaulting to 0(AM) for AMPM_OF_DAY if format string contains 'HH'
                builder.parseDefaulting(HOUR_OF_AMPM, 0)
                        .parseDefaulting(AMPM_OF_DAY, 0);
            }
            else {
                builder.parseDefaulting(HOUR_OF_DAY, 0);
            }

            return builder.parseDefaulting(MINUTE_OF_HOUR, 0)

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Correct the format string to use supported Teradata tokens (YYYY, MM, DD, HH24, MI, SS, etc.)
  2. Quote literal text in the format string where supported
  3. Check the offending token/offset in the message and replace it
  4. Fallback to Presto's native date_format format syntax

Example fix

// before
date_format(ts, 'YYYY-MM-DD HH12:MI:SS TZ')
// after
date_format(ts, 'YYYY-MM-DD HH24:MI:SS')
Defensive patterns

Strategy: validation

Validate before calling

Set<String> supported = Set.of("YYYY","YY","MM","DDD","DD","HH24","HH","MI","SS","FF6","T","TZ"); // verify each token in the format string is in DateFormat before calling

Try / catch

try { return teradataDateFormat(ts, format); } catch (PrestoException e) { if (StandardErrorCode.INVALID_FUNCTION_ARGUMENT.toErrorCode().equals(e.getErrorCode())) { log.warn("Unsupported format token: " + format); return fallbackFormat(ts, format); } throw e; }

Prevention

When it happens

Trigger: Calling date_format/date_parse (teradata functions) with an unrecognized format specifier, e.g. 'YYYY-MM-QQ' where 'QQ' has no DateFormat mapping.

Common situations: Users porting Oracle/Teradata TO_CHAR format strings verbatim, using unsupported tokens (quarters, text literals unquoted, mixed-case specifiers).

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/11b4d791aca0eb80. Report an issue: GitHub.