{"record":{"id":"732a800f4ac3e996","repo":"prestodb/presto","slug":"unsupported-precision-for-timeunit-conversion-tim","errorCode":null,"errorMessage":"Unsupported precision for TimeUnit conversion: TIMESTAMP(","messagePattern":"Unsupported precision for TimeUnit conversion: TIMESTAMP\\(","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/type/TimestampType.java","lineNumber":220,"sourceCode":"        }\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;\n        }\n        throw new UnsupportedOperationException(\n                \"Unsupported precision for TimeUnit conversion: TIMESTAMP(\" + precision + \")\");\n    }\n}\n","sourceCodeStart":202,"sourceCodeEnd":224,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/type/TimestampType.java#L202-L224","documentation":"The private toTimeUnit helper maps a TIMESTAMP precision to a java.util.concurrent.TimeUnit, but only the default precision (3 -> MILLISECONDS) and MAX_SHORT_PRECISION (6 -> MICROSECONDS) have a TimeUnit equivalent. Any other precision cannot be expressed as a TimeUnit, so UnsupportedOperationException is thrown.","triggerScenarios":"Indirectly triggered by getObjectValue (and other helpers) on a TimestampType whose precision is neither 3 nor 6 — e.g. TIMESTAMP(0) or TIMESTAMP(9).","commonSituations":"Client materialization of TIMESTAMP(0) columns (a common schema choice) through getObjectValue; code hitting this after schemas changed precision.","solutions":["Avoid getObjectValue for non-3/6 precisions; use getLong plus explicit conversion.","Change the column to TIMESTAMP(3) or TIMESTAMP(6) if an Object/TimeUnit-based representation is required.","Convert manually using getEpochSecond/getNanos instead of relying on TimeUnit mapping."],"exampleFix":"// before\nObject v = type.getObjectValue(props, block, pos); // TIMESTAMP(0)\n// after\nlong epochSecond = type.getEpochSecond(type.getLong(block, pos));\nint nanos = type.getNanos(type.getLong(block, pos));","handlingStrategy":"validation","validationCode":"if (!(type.getPrecision() == 3 || type.getPrecision() == 6)) {\n    throw new IllegalStateException(\"TimeUnit mapping only supports TIMESTAMP(3)/(6): \" + type.getPrecision());\n}","typeGuard":"boolean hasTimeUnitMapping(TimestampType t) { return t.getPrecision() == 3 || t.getPrecision() == 6; }","tryCatchPattern":"try {\n    value = type.getObjectValue(props, block, pos);\n} catch (UnsupportedOperationException e) {\n    value = manualEpochConversion(type.getLong(block, pos));\n}","preventionTips":["Do not rely on getObjectValue/TimeUnit for precisions other than 3 and 6.","Use getEpochSecond/getNanos for explicit unit conversions.","Standardize column precision on 3 or 6 in schemas clients materialize as objects."],"tags":["presto","unsupported-operation","timeunit","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"}