{"record":{"id":"61912ad47b76f673","repo":"prestodb/presto","slug":"invalid-function-argument-61912a","errorCode":"INVALID_FUNCTION_ARGUMENT","errorMessage":"INVALID_FUNCTION_ARGUMENT: e.getMessage()","messagePattern":"INVALID_FUNCTION_ARGUMENT: e\\.getMessage\\(\\)","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/operator/scalar/DateTimeFunctions.java","lineNumber":133,"sourceCode":"    {\n        // We do all calculation in UTC, as session.getStartTime() is in UTC\n        // and we need to have UTC millis for packDateTimeWithZone\n        long millis = UTC_CHRONOLOGY.millisOfDay().get(properties.getSessionStartTime());\n\n        // However, those UTC millis are pointing to the correct UTC timestamp\n        // Our TIME WITH TIME ZONE representation does use UTC 1970-01-01 representation\n        // So we have to hack here in order to get valid representation\n        // of TIME WITH TIME ZONE\n        millis -= valueToSessionTimeZoneOffsetDiff(properties.getSessionStartTime(), getDateTimeZone(properties.getTimeZoneKey()));\n\n        try {\n            return packDateTimeWithZone(millis, properties.getTimeZoneKey());\n        }\n        catch (NotSupportedException | TimeZoneNotSupportedException e) {\n            throw new PrestoException(NOT_SUPPORTED, e.getMessage(), e);\n        }\n        catch (IllegalArgumentException e) {\n            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, e.getMessage(), e);\n        }\n        catch (ArithmeticException e) {\n            throw new PrestoException(NUMERIC_VALUE_OUT_OF_RANGE, e.getMessage(), e);\n        }\n    }\n\n    @Description(\"current time without time zone\")\n    @ScalarFunction(\"localtime\")\n    @SqlType(StandardTypes.TIME)\n    public static long localTime(SqlFunctionProperties properties)\n    {\n        if (properties.isLegacyTimestamp()) {\n            long millis = UTC_CHRONOLOGY.millisOfDay().get(properties.getSessionStartTime());\n            return millis - valueToSessionTimeZoneOffsetDiff(properties.getSessionStartTime(), getDateTimeZone(properties.getTimeZoneKey()));\n        }\n        ISOChronology localChronology = getChronology(properties.getTimeZoneKey());\n        return localChronology.millisOfDay().get(properties.getSessionStartTime());\n    }","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/operator/scalar/DateTimeFunctions.java#L115-L151","documentation":"Presto's currentTime() (current_time SQL function) packs the session start time with the session time zone via packDateTimeWithZone. When that packing throws IllegalArgumentException (invalid millisecond/time-zone combination), the function rethrows it as a PrestoException with code INVALID_FUNCTION_ARGUMENT, carrying the underlying exception's message. It signals the runtime datetime value could not be represented as a TIME WITH TIME ZONE.","triggerScenarios":"Calling SELECT current_time() (or current_time) when packDateTimeWithZone(millis, properties.getTimeZoneKey()) throws IllegalArgumentException — e.g. an unresolvable or invalid session time zone key producing an unrepresentable millis-of-day value.","commonSituations":"Sessions started with a bogus or misconfigured session time zone; JVM/ICU tz database mismatches after upgrades; misconfigured server.time-zone or session SET TIME ZONE values.","solutions":["Check the session time zone (SELECT current_timezone()) and set a valid IANA zone with SET TIME ZONE 'UTC' or a valid region/city ID.","Verify the coordinator/worker JVM time-zone database is intact (not stripped in minimal containers); use a full JDK image.","If you control the code, ensure millis passed to packDateTimeWithZone is a valid millis-of-day; clamp to [0, 86400000).","Upgrade Presto if the zone key fails despite being a valid IANA ID (older tz database)."],"exampleFix":"// before (session)\nSET TIME ZONE 'PST8PDTX'; -- invalid id\n// after\nSET TIME ZONE 'America/Los_Angeles';","handlingStrategy":"validation","validationCode":"// Before relying on current_time, verify the session zone resolves:\nString tz = client.getSessionTimeZone(); // e.g. from SHOW SESSION or connection props\nif (tz == null || !isValidIanaId(tz)) {\n    client.execute(\"SET TIME ZONE 'UTC'\");\n}","typeGuard":"boolean isValidIanaId(String id) {\n    try { java.time.ZoneId.of(id); return true; }\n    catch (java.time.DateTimeException e) { return false; }\n}","tryCatchPattern":"// JDBC\ntry (Statement s = conn.createStatement()) {\n    try (ResultSet rs = s.executeQuery(\"SELECT current_time\")) { ... }\n} catch (SQLException e) {\n    if (e.getMessage().contains(\"INVALID_FUNCTION_ARGUMENT\")) {\n        conn.createStatement().execute(\"SET TIME ZONE 'UTC'\");\n    } else { throw e; }\n}","preventionTips":["Always configure a valid IANA session time zone (server config or JDBC sessionTimeZone).","Keep tzdata installed in coordinator/worker container images.","Run SELECT current_timezone() in health checks to detect bad zone config early.","Pin and update the JDK/tz database together with Presto upgrades."],"tags":["presto","sql-function","datetime","invalid-argument"],"backgroundTag":"invalid-function-arguments","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"}