{"record":{"id":"48967e5df733e04e","repo":"prestodb/presto","slug":"seconds-field-of-timestamp-exceeds-maximum-support","errorCode":null,"errorMessage":"seconds field of timestamp exceeds maximum supported value, secondsWithBase: %s unitsPerSecond: %s.","messagePattern":"seconds field of timestamp exceeds maximum supported value, secondsWithBase: (.+?) unitsPerSecond: (.+?)\\.","errorType":"exception","errorClass":"TimestampOutOfBoundsException","httpStatus":null,"severity":"error","filePath":"presto-orc/src/main/java/com/facebook/presto/orc/reader/ApacheHiveTimestampDecoder.java","lineNumber":59,"sourceCode":"        // Truncate nanos to required units (millis / micros)\n        long truncatedNanos = nanos / options.getNanosPerUnit();\n        return getValueWithNanos(enableMicroPrecision, value, truncatedNanos);\n    }\n\n    private static long getSecondsInRequiredUnits(boolean enableMicroPrecision, long secondsWithBase, long unitsPerSecond)\n    {\n        if (!enableMicroPrecision) {\n            // This can overflow/underflow, but to maintain backward compatibility this is not bounds checked.\n            return secondsWithBase * unitsPerSecond;\n        }\n        try {\n            // Overflow/underflow is detected and the code will raise error.\n            return Math.multiplyExact(secondsWithBase, unitsPerSecond);\n        }\n        catch (ArithmeticException e) {\n            String errorMessage = String.format(\"seconds field of timestamp exceeds maximum supported value, secondsWithBase: %s unitsPerSecond: %s.\",\n                    secondsWithBase, unitsPerSecond);\n            throw new TimestampOutOfBoundsException(errorMessage, e);\n        }\n    }\n\n    // Add truncated nanos to seconds value\n    private static long getValueWithNanos(boolean enableMicroPrecision, long value, long truncatedNanos)\n    {\n        if (!enableMicroPrecision) {\n            // This can overflow/underflow, but to maintain backward compatibility this is not bounds checked.\n            return value + truncatedNanos;\n        }\n        try {\n            // Overflow/underflow is detected and the code will raise error.\n            return Math.addExact(value, truncatedNanos);\n        }\n        catch (ArithmeticException e) {\n            String errorMessage = String.format(\"Timestamp exceeds maximum supported value, value: %s truncatedNanos: %s.\",\n                    value, truncatedNanos);\n            throw new TimestampOutOfBoundsException(errorMessage, e);","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-orc/src/main/java/com/facebook/presto/orc/reader/ApacheHiveTimestampDecoder.java#L41-L77","documentation":"Thrown by ApacheHiveTimestampDecoder.getSecondsInRequiredUnits when Math.multiplyExact overflows while converting seconds (plus base seconds) to the internal unit scale. This means the TIMESTAMP's seconds field is beyond the range representable in a Presto long. The ArithmeticException is rethrown as a TimestampOutOfBoundsException with the offending values.","triggerScenarios":"Decoding an ORC TIMESTAMP whose secondsWithBase * unitsPerSecond exceeds Long.MAX_VALUE/MIN_VALUE — i.e. seconds values far outside year-range Presto supports (roughly years ±290 with micro precision much narrower).","commonSituations":"ORC files containing extreme timestamps (year 10000+, or ancient dates) written by other systems; wrong baseSeconds/options configuration causing double-counting; decimal-style streams misread as timestamps.","solutions":["Clamp or reject out-of-range timestamp values at write time so files stay within Presto's supported range.","Sanitize the source data (e.g. in the producing ETL) to valid date ranges before writing ORC.","Catch TimestampOutOfBoundsException in the reader pipeline and treat the row as null/error per policy.","If the value is legitimate, store it as VARCHAR or a scaled type instead of TIMESTAMP."],"exampleFix":"// before\nlong ts = seconds; // year 12000, overflows on decode\n// after\nif (secondsWithBase > MAX_SUPPORTED_SECONDS) { secondsWithBase = MAX_SUPPORTED_SECONDS; }","handlingStrategy":"validation","validationCode":"// reject seconds outside Presto's supported range before writing/reading\nif (secondsWithBase > MAX_SECONDS || secondsWithBase < MIN_SECONDS) throw new IllegalArgumentException(\"timestamp out of range\");","typeGuard":null,"tryCatchPattern":"try { ts = decode(...); } catch (TimestampOutOfBoundsException e) { ts = null; /* or map to error row */ }","preventionTips":["Clamp timestamps to a sane range (e.g. 1900-9999) in ETL","Never store extreme epoch values as TIMESTAMP; use BIGINT if needed","Document the supported timestamp range for downstream producers"],"tags":["orc","timestamp","overflow","presto"],"backgroundTag":"timestamp-overflow","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"}