You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Span millisecond incorrectly converted to microsecond interval #4550
When using span=X milliseconds in timechart commands, the span unit is incorrectly converted to IntervalUnit.MICROSECOND by PlanUtils.spanUnitToIntervalUnit(). The root cause is that the IntervalUnit enum does not include a MILLISECOND value, only MICROSECOND.
How can one reproduce the bug?
Steps to reproduce the behavior:
Execute a PPL query with timechart using millisecond span: source=logs | timechart span=500ms count()
The span calculation will use microsecond interval unit instead of millisecond, causing incorrect time bucketing.
What is the expected behavior?
IntervalUnit enum should include a MILLISECOND value
PlanUtils should correctly convert between SpanUnit.MILLISECOND and IntervalUnit.MILLISECOND
Do you have any additional context?
Impact: This bug also blocks the implementation of millisecond support in the timechart per_* functions (per_second, per_minute, per_hour, per_day). The per_* function transformation logic calculates span width in seconds instead of millisecond, leading to incorrect results when a millisecond span is used.
I think the missing support for MILLISECOND in IntervalUnit only contributes to part of the problem. The implementation of per functions is also flawed in handling units below seconds:
$$\frac{\text{rate in seconds}}{\text{span length in seconds}}$$
in which the span length in seconds is computed with TIMESTAMPDIFF function. However, TIMESTAMPDIFF only returns bigint, rendering a millisecond in second returning 0. I'll try to fix it by making the computation in milliseconds.
Activity
yuancu commentedon Oct 27, 2025
I think the missing support for
MILLISECONDinIntervalUnitonly contributes to part of the problem. The implementation of per functions is also flawed in handling units below seconds:In the below snippets:
It calculates the per-results as:
in which the span length in seconds is computed with TIMESTAMPDIFF function. However, TIMESTAMPDIFF only returns bigint, rendering a millisecond in second returning 0. I'll try to fix it by making the computation in milliseconds.