apache/cassandra · error · InvalidRequestException

The floor on %s values cannot be computed for the %s duratio

Error message

The floor on %s values cannot be computed for the %s duration as precision is below 1 day

What it means

The date-truncation variant in TimeFcts (floor on SimpleDateType values) overrides validateDuration: a date value has only day granularity, so any duration containing a component below one day (i.e. getNanoseconds() != 0, which includes hours/minutes/seconds/ms/ns components stored as nanoseconds) makes the floor uncomputable and throws this error.

Source

Thrown at src/java/org/apache/cassandra/cql3/functions/TimeFcts.java:460

         }

         private FloorDateFunction(AbstractType<?> returnType,
                                   AbstractType<?>... argTypes)
         {
             super(returnType, argTypes);
         }

         protected ByteBuffer fromTimeInMillis(long timeInMillis)
         {
             return SimpleDateType.instance.fromTimeInMillis(timeInMillis);
         }

         @Override
         protected void validateDuration(Duration duration)
         {
             // Checks that the duration has no data below days.
             if (duration.getNanoseconds() != 0)
                 throw invalidRequest("The floor on %s values cannot be computed for the %s duration as precision is below 1 day",
                                      SimpleDateType.instance.asCQL3Type(), duration);
         }
     }

     /**
      * Function that rounds a time down to the closest multiple of a duration.
      */
     public static final NativeScalarFunction floorTime = new NativeScalarFunction("floor", TimeType.instance, TimeType.instance, DurationType.instance)
     {
         @Override
         protected boolean isPartialApplicationMonotonic(List<ByteBuffer> partialParameters)
         {
             return partialParameters.get(0) == UNRESOLVED && partialParameters.get(1) != UNRESOLVED;
         }

         @Override
         public ByteBuffer execute(Arguments arguments)
         {

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Use a whole-day duration such as 1d, 7d, or 1mo when flooring date values
  2. Cast/convert the date to a timestamp if sub-day rounding is actually needed, then floor the timestamp
  3. Guard the client-side duration parameter to disallow sub-day components for date flooring

Example fix

// before: sub-day duration on a date
SELECT floor(the_date, 12h) FROM t;
// after
datastax session.execute("SELECT floor(the_date, 1d) FROM t");
Defensive patterns

Strategy: validation

Validate before calling

function dateFloorDurationOk(dur) { return /^[1-9]\d*d$|^[1-9]\d*mo$|^[1-9]\d*y$/.test(dur); } // whole-day or larger only

Prevention

When it happens

Trigger: Calling the date floor function, e.g. floor(date_col, 12h) or floor(date_col, 30m) — any duration smaller than or not a whole multiple of 1 day on a date column.

Common situations: Users applying the same duration they used for timestamp flooring to a date column; assuming date supports hour-level rounding; query templating that reuses a sub-day duration parameter across timestamp and date columns.

Understand the failure class

Background: "invalid duration" / "failed to parse duration": why your timeout, interval, or TTL string is rejected and which formats each library accepts — this error's family across 32 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/bd9f21ed807544b8. Report an issue: GitHub.