{"record":{"id":"1424d7be5720bd96","repo":"apache/flink","slug":"time-unit-not-recognized","errorCode":null,"errorMessage":"Time unit not recognized","messagePattern":"Time unit not recognized","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"flink-formats/flink-parquet/src/main/java/org/apache/flink/formats/parquet/row/ParquetRowDataWriter.java","lineNumber":540,"sourceCode":"\n    private void writeTimestamp(RecordConsumer recordConsumer, TimestampData timestampData) {\n        if (useInt64) {\n            recordConsumer.addLong(timestampToInt64(timestampData));\n        } else {\n            recordConsumer.addBinary(timestampToInt96(timestampData));\n        }\n    }\n\n    private Long convertInt64ToLong(long mills, long nanosOfMillisecond) {\n        switch (timeUnit) {\n            case NANOS:\n                return mills * NANOS_PER_MILLISECOND + nanosOfMillisecond;\n            case MICROS:\n                return mills * MICROS_PER_MILLISECOND + nanosOfMillisecond / NANOS_PER_MICROSECONDS;\n            case MILLIS:\n                return mills;\n            default:\n                throw new IllegalArgumentException(\"Time unit not recognized\");\n        }\n    }\n\n    private Long timestampToInt64(TimestampData timestampData) {\n        long mills = 0L;\n        long nanosOfMillisecond = 0L;\n        if (utcTimestamp) {\n            mills = timestampData.getMillisecond();\n            nanosOfMillisecond = timestampData.getNanoOfMillisecond();\n        } else {\n            Timestamp timestamp = timestampData.toTimestamp();\n            mills = timestamp.getTime();\n            nanosOfMillisecond = timestamp.getNanos() % NANOS_PER_MILLISECOND;\n        }\n        return convertInt64ToLong(mills, nanosOfMillisecond);\n    }\n\n    private Binary timestampToInt96(TimestampData timestampData) {","sourceCodeStart":522,"sourceCodeEnd":558,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-formats/flink-parquet/src/main/java/org/apache/flink/formats/parquet/row/ParquetRowDataWriter.java#L522-L558","documentation":"TimestampWriter.convertInt64ToLong switches on the writer's configured timeUnit (NANOS, MICROS, MILLIS) to scale a millisecond-based value. Any other value hits the default and throws IllegalArgumentException('Time unit not recognized') - in practice only reachable if the constructor was given an invalid unit.","triggerScenarios":"Constructing a TimestampWriter/ParquetRowDataWriter with a timestamp precision that maps to an unsupported TimeUnit, or passing null/unknown TimeUnit for TIMESTAMP columns.","commonSituations":"Very rare; a library-internal invariant break, e.g. a new time unit enum value in parquet-common not covered here, or custom code constructing the writer directly with a bogus unit.","solutions":["Use standard timestamp precisions (0-3 -> MILLIS, 4-6 -> MICROS, 7-9 -> NANOS) in the table schema","If constructing the writer manually, pass exactly one of TimeUnit.NANOS/MICROS/MILLIS","If hit after a parquet dependency upgrade, check for new TimeUnit enum values and pin the previous version"],"exampleFix":"// before\ntable DDL: ts TIMESTAMP(12)  -- unsupported precision mapping\n\n// after\ntable DDL: ts TIMESTAMP(6)   -- MICROS, supported","handlingStrategy":"validation","validationCode":"int precision = ((TimestampType) type).getPrecision();\nif (precision < 0 || precision > 9) throw new IllegalArgumentException(\"timestamp precision must be 0-9\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Declare TIMESTAMP(p) with p in 0..9 (0-3 millis, 4-6 micros, 7-9 nanos)","Only construct TimestampWriter with TimeUnit.{MILLIS,MICROS,NANOS}","On parquet dependency upgrades, re-run timestamp write tests"],"tags":["parquet","timestamp","time-unit","flink-sql"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}