{"record":{"id":"29f1452b9642fdf3","repo":"prestodb/presto","slug":"toepochmicros-is-not-supported-for-timestamp","errorCode":null,"errorMessage":"toEpochMicros is not supported for TIMESTAMP(","messagePattern":"toEpochMicros 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":191,"sourceCode":"    }\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    {\n        if (!isShort()) {\n            throw new UnsupportedOperationException(\n                    \"fromEpochComponents is not supported for TIMESTAMP(\" + precision + \")\");\n        }\n        if (nanos < 0 || nanos >= 1_000_000_000) {\n            throw new IllegalArgumentException(\"nanos must be in range [0, 999_999_999]: \" + nanos);\n        }\n        long scale = PRECISION_SCALE[precision];\n        return epochSecond * scale + nanos / (1_000_000_000L / scale);\n    }\n","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/type/TimestampType.java#L173-L209","documentation":"toEpochMicros converts the packed long TIMESTAMP value to epoch microseconds and is only valid for short precisions (p=0..6). Precisions 7-12 require a 128-bit representation and are unsupported here, so UnsupportedOperationException is thrown.","triggerScenarios":"Calling toEpochMicros(timestamp) on a TimestampType with precision 7 or higher (isShort() == false).","commonSituations":"Iceberg/partition-transform style code computing epoch micros on columns declared with high precision; connectors reading long-precision timestamps as longs.","solutions":["Check type.isShort() first and route long precisions to the 128-bit representation path.","Use TIMESTAMP(6) columns when microsecond helpers are needed.","Convert via LongTimestamp supporting APIs if high precision must be preserved."],"exampleFix":"// before\nlong micros = type.toEpochMicros(value);\n// after\nlong micros = type.isShort()\n        ? type.toEpochMicros(value)\n        : longTimestampToEpochMicros(value); // 128-bit path","handlingStrategy":"type-guard","validationCode":"if (!timestampType.isShort()) {\n    throw new IllegalStateException(\"toEpochMicros requires short precision, got \" + timestampType.getPrecision());\n}","typeGuard":"boolean supportsEpochMicros(TimestampType t) { return t.isShort(); }","tryCatchPattern":"try {\n    micros = type.toEpochMicros(packed);\n} catch (UnsupportedOperationException e) {\n    micros = longTimestampToEpochMicros(value); // 128-bit path\n}","preventionTips":["Call isShort() before any toEpochMicros/toEpochMillis helper.","Route long-precision values through the 128-bit representation API.","Document supported precisions where these helpers are exposed to plugin authors."],"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"}