{"record":{"id":"11b4d791aca0eb80","repo":"prestodb/presto","slug":"invalid-function-argument-11b4d7","errorCode":"INVALID_FUNCTION_ARGUMENT","errorMessage":"Failed to tokenize string [%s] at offset [%d]","messagePattern":"Failed to tokenize string \\[(.+?)\\] at offset \\[(.+?)\\]","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-teradata-functions/src/main/java/com/facebook/presto/teradata/functions/dateformat/DateFormatParser.java","lineNumber":102,"sourceCode":"                    break;\n                case DateFormat.MI:\n                    builder.appendValue(MINUTE_OF_HOUR, mode.getMinTwoPositionFieldWidth(), 2, NOT_NEGATIVE);\n                    break;\n                case DateFormat.MM:\n                    builder.appendValue(MONTH_OF_YEAR, mode.getMinTwoPositionFieldWidth(), 2, NOT_NEGATIVE);\n                    break;\n                case DateFormat.SS:\n                    builder.appendValue(SECOND_OF_MINUTE, mode.getMinTwoPositionFieldWidth(), 2, NOT_NEGATIVE);\n                    break;\n                case DateFormat.YY:\n                    builder.appendValueReduced(YEAR, 2, 2, 2000);\n                    break;\n                case DateFormat.YYYY:\n                    builder.appendValue(YEAR, 4);\n                    break;\n                case DateFormat.UNRECOGNIZED:\n                default:\n                    throw new PrestoException(\n                            StandardErrorCode.INVALID_FUNCTION_ARGUMENT,\n                            String.format(\"Failed to tokenize string [%s] at offset [%d]\", token.getText(), token.getCharPositionInLine()));\n            }\n        }\n        try {\n            // Append default values(0) for time fields(HH24, HH, MI, SS) because JSR-310 does not accept bare Date value as DateTime\n\n            if (formatContainsHourOfAMPM) {\n                // 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\n                // Keep existing behaviour by defaulting to 0(AM) for AMPM_OF_DAY if format string contains 'HH'\n                builder.parseDefaulting(HOUR_OF_AMPM, 0)\n                        .parseDefaulting(AMPM_OF_DAY, 0);\n            }\n            else {\n                builder.parseDefaulting(HOUR_OF_DAY, 0);\n            }\n\n            return builder.parseDefaulting(MINUTE_OF_HOUR, 0)","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-teradata-functions/src/main/java/com/facebook/presto/teradata/functions/dateformat/DateFormatParser.java#L84-L120","documentation":"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.","triggerScenarios":"Calling date_format/date_parse (teradata functions) with an unrecognized format specifier, e.g. 'YYYY-MM-QQ' where 'QQ' has no DateFormat mapping.","commonSituations":"Users porting Oracle/Teradata TO_CHAR format strings verbatim, using unsupported tokens (quarters, text literals unquoted, mixed-case specifiers).","solutions":["Correct the format string to use supported Teradata tokens (YYYY, MM, DD, HH24, MI, SS, etc.)","Quote literal text in the format string where supported","Check the offending token/offset in the message and replace it","Fallback to Presto's native date_format format syntax"],"exampleFix":"// before\ndate_format(ts, 'YYYY-MM-DD HH12:MI:SS TZ')\n// after\ndate_format(ts, 'YYYY-MM-DD HH24:MI:SS')","handlingStrategy":"validation","validationCode":"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","typeGuard":null,"tryCatchPattern":"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; }","preventionTips":["Validate the Teradata format string against supported tokens before use","Quote literal characters in format strings","Test format strings against the DateFormat enum when upgrading"],"tags":["teradata","date-format","invalid-function-argument","parsing"],"backgroundTag":"invalid-date-format-string","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}