{"record":{"id":"717a85bdd5df4bca","repo":"prestodb/presto","slug":"fromepochcomponents-is-not-supported-for-timestamp","errorCode":null,"errorMessage":"fromEpochComponents is not supported for TIMESTAMP(","messagePattern":"fromEpochComponents 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":200,"sourceCode":"        }\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\n    private static TimeUnit toTimeUnit(int precision)\n    {\n        // Exact-precision checks: DEFAULT_PRECISION (3) stores epoch-millis; MAX_SHORT_PRECISION (6)\n        // stores epoch-micros. Other precisions have no direct TimeUnit mapping.\n        if (precision == DEFAULT_PRECISION) {\n            return MILLISECONDS;\n        }\n        if (precision == MAX_SHORT_PRECISION) {\n            return MICROSECONDS;","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/type/TimestampType.java#L182-L218","documentation":"fromEpochComponents builds a packed long TIMESTAMP value from epoch seconds plus a nanos fraction, which only fits the 64-bit representation for short precisions (p=0..6). For precisions 7-12 (isShort() == false) it throws UnsupportedOperationException.","triggerScenarios":"Calling fromEpochComponents(epochSecond, nanos) on a TimestampType with precision 7-12.","commonSituations":"Partition-transform adjustment code or connectors synthesizing timestamp values from component fields when the target column uses long precision.","solutions":["Guard with isShort() before constructing and fall back to the 128-bit builder for long precisions.","Target a TIMESTAMP(6) or lower column instead.","Compose the value via LongTimestamp/long timestamp write APIs for p=7-12."],"exampleFix":"// before\nlong packed = type.fromEpochComponents(epochSecond, nanos);\n// after\nlong packed = type.isShort()\n        ? type.fromEpochComponents(epochSecond, nanos)\n        : buildLongTimestamp(type, epochSecond, nanos);","handlingStrategy":"type-guard","validationCode":"if (!timestampType.isShort()) {\n    throw new IllegalStateException(\"fromEpochComponents requires short precision, got \" + timestampType.getPrecision());\n}","typeGuard":"boolean canBuildPackedTimestamp(TimestampType t) { return t.isShort(); }","tryCatchPattern":"try {\n    packed = type.fromEpochComponents(epochSecond, nanos);\n} catch (UnsupportedOperationException e) {\n    packed = buildLongTimestamp(type, epochSecond, nanos);\n}","preventionTips":["Verify isShort() before building packed values.","Use the LongTimestamp write path for p=7-12 columns.","Keep a shared helper that dispatches short vs long timestamp construction."],"tags":["presto","unsupported-operation","timestamp-precision"],"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"}