{"record":{"id":"0ec372d5b1866e58","repo":"prestodb/presto","slug":"toepochmillis-is-not-supported-for-timestamp","errorCode":null,"errorMessage":"toEpochMillis is not supported for TIMESTAMP(","messagePattern":"toEpochMillis is not supported for TIMESTAMP\\(","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/type/TimestampType.java","lineNumber":180,"sourceCode":"    // Floor modulo handles negative (pre-1970) timestamps correctly; Java % does not.\n    public int getNanos(long timestamp)\n    {\n        long fractional = floorMod(timestamp, PRECISION_SCALE[precision]);\n        long scale = PRECISION_SCALE[precision];\n        // For p <= 9, scale <= 1e9: multiply up to nanoseconds.\n        // For p > 9, scale > 1e9: dividing avoids integer overflow; scale is always a multiple of 1e9.\n        if (scale <= 1_000_000_000L) {\n            return (int) (fractional * (1_000_000_000L / scale));\n        }\n        return (int) (fractional / (scale / 1_000_000_000L));\n    }\n\n    // Supported for all short precisions (p=0 through p=6, i.e. isShort()==true).\n    // Long precisions (p=7-12) require a 128-bit representation and are not yet supported.\n    public long toEpochMillis(long timestamp)\n    {\n        if (!isShort()) {\n            throw new UnsupportedOperationException(\n                    \"toEpochMillis is not supported for TIMESTAMP(\" + precision + \")\");\n        }\n        return getEpochSecond(timestamp) * 1_000L + getNanos(timestamp) / 1_000_000;\n    }\n\n    // Supported for all short precisions (p=0 through p=6, i.e. isShort()==true).\n    // Long precisions (p=7-12) require a 128-bit representation and are not yet supported.\n    public long toEpochMicros(long timestamp)\n    {\n        if (!isShort()) {\n            throw new UnsupportedOperationException(\n                    \"toEpochMicros is not supported for TIMESTAMP(\" + precision + \")\");\n        }\n        return getEpochSecond(timestamp) * 1_000_000L + getNanos(timestamp) / 1_000;\n    }\n\n    public long fromEpochComponents(long epochSecond, int nanos)\n    {","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/type/TimestampType.java#L162-L198","documentation":"toEpochMillis converts the packed long representation of a TIMESTAMP to epoch milliseconds, but only short precisions (p=0..6) fit in the 64-bit representation. Long precisions (p=7-12) need 128-bit storage, so calling this helper on them throws UnsupportedOperationException.","triggerScenarios":"Calling toEpochMillis(timestamp) on a TimestampType instance with precision 7 through 12 (isShort() == false).","commonSituations":"Connector/reader code that assumes all TIMESTAMP values are longs, encountering new long-precision columns introduced by newer type-system support.","solutions":["Guard with type.isShort() before calling and handle long precisions separately.","Migrate the column to a short precision (e.g. TIMESTAMP(6)) if millisecond conversion is needed.","Await/use the 128-bit (LongTimestamp) API path for p=7-12 values."],"exampleFix":"// before\nlong ms = type.toEpochMillis(block.getLong(position));\n// after\nif (!type.isShort()) {\n    throw new UnsupportedOperationException(\"Use 128-bit path for \" + type.getDisplayName());\n}\nlong ms = type.toEpochMillis(block.getLong(position));","handlingStrategy":"type-guard","validationCode":"if (!timestampType.isShort()) {\n    throw new IllegalStateException(\"toEpochMillis requires short precision, got \" + timestampType.getPrecision());\n}","typeGuard":"boolean supportsEpochMillis(TimestampType t) { return t.isShort(); }","tryCatchPattern":"try {\n    ms = type.toEpochMillis(packed);\n} catch (UnsupportedOperationException e) {\n    ms = convertLongTimestampToMillis(packedLongTimestamp); // 128-bit fallback\n}","preventionTips":["Gate all epoch-helper calls behind isShort().","Keep short/long timestamp handling in separate code paths.","Add tests covering precision 7 to catch regressions early."],"tags":["presto","unsupported-operation","timestamp-precision","overflow"],"backgroundTag":"unsupported-operation","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"}