{"record":{"id":"a7c491283649ac13","repo":"apache/cassandra","slug":"the-floor-cannot-be-computed-for-the-s-duration-a","errorCode":null,"errorMessage":"The floor cannot be computed for the %s duration as precision is below 1 millisecond","messagePattern":"The floor cannot be computed for the (.+?) duration as precision is below 1 millisecond","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/functions/TimeFcts.java","lineNumber":348,"sourceCode":"          * @param arguments the function arguments\n          * @return the time to use as the starting time\n          */\n         private long getStartingTime(Arguments arguments)\n         {\n             if (arguments.size() == 3)\n                 return arguments.getAsLong(2);\n\n             return ZERO;\n         }\n\n         /**\n          * Validates that the duration has the correct precision.\n          * @param duration the duration to validate.\n          */\n         protected void validateDuration(Duration duration)\n         {\n             if (!duration.hasMillisecondPrecision())\n                 throw invalidRequest(\"The floor cannot be computed for the %s duration as precision is below 1 millisecond\", duration);\n         }\n\n         /**\n          * Serializes the specified time.\n          *\n          * @param timeInMillis the time in milliseconds\n          * @return the serialized time\n          */\n         protected abstract ByteBuffer fromTimeInMillis(long timeInMillis);\n     }\n\n    /**\n     * Function that rounds a timestamp down to the closest multiple of a duration.\n     */\n     public static final class FloorTimestampFunction extends FloorFunction\n     {\n         public static FloorTimestampFunction newInstance()\n         {","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/functions/TimeFcts.java#L330-L366","documentation":"The timeFloor-family functions in TimeFcts (floor timestamps to a duration multiple) require the rounding duration to have at least millisecond precision. validateDuration checks Duration.hasMillisecondPrecision(); a duration whose smallest unit is finer than 1ms or that is purely sub-millisecond (e.g. 500nanoseconds) cannot be floored and throws this error. Note Cassandra's Duration type can encode months/days/nanoseconds, and nanosecond-only components fail this check.","triggerScenarios":"SELECT systemTimeFct-style floor(now, 500ns) — i.e. calling TimeFcts floor functions (via CQL like FloorTimestamp with a duration argument) with a duration literal composed below 1ms, e.g. 1microsecond or 500nanoseconds.","commonSituations":"Users constructing duration parameters programmatically from fine-grained timers; misreading duration syntax (w/d/h/m/s vs ns); porting sub-millisecond interval logic from other systems.","solutions":["Use a duration of at least 1 millisecond, e.g. 1ms, 10ms, 1s","If sub-ms rounding is needed, do the rounding in application code instead of CQL","Validate duration inputs in client code before sending (reject durations with nanosecond-only components)"],"exampleFix":"// before: below 1ms precision\nSELECT floor(toTimestamp(now()), 500ns) FROM t;\n// after\ndatastax session.execute(\"SELECT floor(toTimestamp(now()), 1ms) FROM t\");","handlingStrategy":"validation","validationCode":"function floorDurationOk(durMs) { return durMs >= 1; } // reject durations below 1 millisecond before sending","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only use durations >= 1ms with floor/round time functions","Validate user-supplied duration parameters client-side","Remember Cassandra duration units: y/mo/w/d/h/m/s/ms/ns — avoid ns components for flooring"],"tags":["cql","time-functions","duration"],"backgroundTag":"invalid-duration-format","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}