{"record":{"id":"bce471f04efbc19f","repo":"prestodb/presto","slug":"numeric-value-out-of-range-bce471","errorCode":"NUMERIC_VALUE_OUT_OF_RANGE","errorMessage":"NUMERIC_VALUE_OUT_OF_RANGE: e.getMessage()","messagePattern":"NUMERIC_VALUE_OUT_OF_RANGE: 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":136,"sourceCode":"        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    }\n\n    @Description(\"current time zone\")\n    @ScalarFunction(\"current_timezone\")","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/operator/scalar/DateTimeFunctions.java#L118-L154","documentation":"The same currentTime() function also catches ArithmeticException from packDateTimeWithZone (e.g. overflow while packing millis into the packed datetime-with-zone representation) and rethrows it as PrestoException NUMERIC_VALUE_OUT_OF_RANGE. It means the computed time value overflowed the range representable by Presto's packed long encoding.","triggerScenarios":"SELECT current_time() when millis derived from the session start time overflows during packDateTimeWithZone arithmetic (ArithmeticException from Joda-time/long packing).","commonSituations":"Corrupted or wildly out-of-range sessionStartTime in properties; clock misconfiguration on the coordinator; synthetic/test harnesses injecting extreme values.","solutions":["Check coordinator/worker system clock sanity (NTP-synced); restart the coordinator if sessionStartTime is corrupted.","Re-run the query in a new session; a fresh session start time may avoid the bad value.","Validate the JVM tz/Joda-time setup, since chronology arithmetic overflow often stems from bad zone data.","If in a test harness, pass a realistic sessionStartTime within [0, 86400000) millis-of-day."],"exampleFix":"// before (test harness)\nprops.setSessionStartTime(Long.MAX_VALUE);\n// after\nprops.setSessionStartTime(System.currentTimeMillis());","handlingStrategy":"try-catch","validationCode":"// Ensure clocks are sane before issuing time queries:\nlong skew = Math.abs(System.currentTimeMillis() - serverReportedMillis);\nif (skew > 86_400_000L) throw new IllegalStateException(\"coordinator clock out of range\");","typeGuard":null,"tryCatchPattern":"catch (SQLException e) {\n    if (e.getMessage().contains(\"NUMERIC_VALUE_OUT_OF_RANGE\")) {\n        // retry with a fresh session / recalibrate clock, then re-run\n        reconnect();\n    } else { throw e; }\n}","preventionTips":["NTP-sync all Presto nodes.","Restart coordinators after clock drift alarms.","Never inject sentinel time values (Long.MAX_VALUE, -1) in test harnesses.","Monitor JVM chronology/tz data health after upgrades."],"tags":["presto","sql-function","datetime","numeric-overflow"],"backgroundTag":"numeric-value-out-of-range","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"}