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] PPL date modifier function does not work as expected #3725
The now() function retrieves the current instant as a LocalDateTime, but it constructs an ExprTimestampValue with the ZoneOffset.UTC. For example, if a query runs at 2025-06-02 13:19:00 in a JVM with the timezone America/Los_Angeles, the now() function incorrectly returns 2025-06-02 13:19:00 in UTC. Consequently, comparisons with @timestamp yield no results because all @timestamp values are considered later than 2025-06-02 13:19:00
Time zones in PPL/OpenSearch are only relevant during the creation of a date, time, or timestamp. Once the value is created, the time zone information is discarded, and the timestamp is treated as a literal without any associated zone.
For example, when you call now(), the timestamp is obtained in the JVM’s default time zone and converted to a LocalDateTime. If the JVM is set to UTC+8, now() at 13:00 results in the literal value July 2, 13:00. After this point, no time zone information is retained.
However, there are cases — such as type conversions or formatting—where a time zone must be supplied. In these situations, UTC is used as a neutral default time zone.
SPL2 uses unix time to circumvent the handling of time zone.
However, there are still timezone involved in our representation of timestamps. In your example, for the DSL to return the expected results, there is a big assumption: the date/time stored in OpenSearch is in UTC time. Is there already such agreement? If so, we can also convert the time to UTC when storing and reading from OpenSearch.
In the current implementation, the assumption is the date/time stored in OpenSearch are in JVM'm timezone. Therefore, 13:00 UTC+8 is stored as 13:00 directly.
In your example, for the DSL to return the expected results, there is a big assumption: the date/time stored in OpenSearch is in UTC time. Is there already such agreement? If so, we can also convert the time to UTC when storing and reading from OpenSearch.
Activity
penghuo commentedon Jun 2, 2025
RCA
The now() function retrieves the current instant as a LocalDateTime, but it constructs an ExprTimestampValue with the ZoneOffset.UTC. For example, if a query runs at 2025-06-02 13:19:00 in a JVM with the timezone America/Los_Angeles, the now() function incorrectly returns 2025-06-02 13:19:00 in UTC. Consequently, comparisons with @timestamp yield no results because all @timestamp values are considered later than 2025-06-02 13:19:00
penghuo commentedon Jun 13, 2025
Relate to #3599
model-collapse commentedon Jun 27, 2025
This should be a production decision, let's involve more ppl to discuss.
yuancu commentedon Jul 2, 2025
I'm a little confused why is the result of the DSL desired.
2025-06-02 13:19:00Shouldn't it return an empty list?
Another test I tried locally
Time: Jul 2, 15:58, Shanghai Time (Both client & JVM)
Data
PPL:
source=t0001 | where @timestamp >= date_sub(now(), INTERVAL 1 DAY) and @timestamp <= now()PPL result:
{ "schema": [ { "name": "@timestamp", "type": "timestamp" } ], "datarows": [ [ "2025-07-02 14:00:00" ], [ "2025-07-02 15:00:00" ] ], "total": 2, "size": 2 }DSL:
{ "query": { "range" : { "@timestamp" : { "gte" : "now-1d", "lte" : "now" } } } }DSL result:
{ "hits": { "total": { "value": 0, "relation": "eq" }, "hits": [] } }Intuitively, the result of PPL is correct.
About the UTC in
ExprTimestampValueTime zones in PPL/OpenSearch are only relevant during the creation of a date, time, or timestamp. Once the value is created, the time zone information is discarded, and the timestamp is treated as a literal without any associated zone.
For example, when you call
now(), the timestamp is obtained in the JVM’s default time zone and converted to aLocalDateTime. If the JVM is set to UTC+8,now()at 13:00 results in the literal value July 2, 13:00. After this point, no time zone information is retained.However, there are cases — such as type conversions or formatting—where a time zone must be supplied. In these situations, UTC is used as a neutral default time zone.
penghuo commentedon Jul 2, 2025
In OpenSearch DSL, If we agree on following 2 concept
Then we can explain why 1st query return results, and 2nd query return empty results.
run query in PST 2025-06-02 13:19:00 (UTC 2025-06-02 20:19:00), it return
| @timestamp
-- | --
1 | 2025-06-02T14:00:00
2 | 2025-06-02T15:00:00
3 | 2025-06-02T16:00:00
Run query in Jul 2, 15:58, Shanghai Time (UTC 2025-07-02 07:58:00), it should return empty results.
Similaly in SPL, now() function is represented in UNIX time, or in seconds since Epoch time.
yuancu commentedon Jul 3, 2025
Thank you for the explanation. I get it now.
SPL2 uses unix time to circumvent the handling of time zone.
However, there are still timezone involved in our representation of timestamps. In your example, for the DSL to return the expected results, there is a big assumption: the date/time stored in OpenSearch is in UTC time. Is there already such agreement? If so, we can also convert the time to UTC when storing and reading from OpenSearch.
In the current implementation, the assumption is the date/time stored in OpenSearch are in JVM'm timezone. Therefore,
13:00 UTC+8is stored as13:00directly.penghuo commentedon Jul 3, 2025
This is not assumption, Internally, dates are converted to UTC (if the time-zone is specified) and stored as a long number representing milliseconds-since-the-epoch.
yuancu commentedon Jul 11, 2025
@penghuo Is the solution in #3854 acceptable? It returns UTC time for almost all now-like functions.