Skip to content

Conversation

@ivancea
Copy link
Contributor

@ivancea ivancea commented Oct 31, 2025

Timezone settings (Both the request parameter and the SET setting) are snapshot-only.

Add timezone support to DATE_TRUNC, BUCKET and TBUCKET.

The current timezone is already in the Configuration. This PR:

  • Uses the configuration ZoneId from those functions
  • Adds unit tests for edge cases
    • As BUCKET and TBUCKET depend on DATE_TRUNC, DATE_TRUNC tests are reused
  • Fixed Rounding for date intervals with variable timezones not taking the amount of units (e.g. 5 days) into account
  • Adds CSV tests for common cases

For reviewers

Please take a good look at the expected results of DATE_TRUNC in DateTruncTests, and comment any interesting or edge case you can think of!

ivancea and others added 27 commits October 17, 2025 12:51
# Conflicts:
#	x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/EsqlTestUtils.java
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java
#	x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/CsvTests.java
#	x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/DateFormatTests.java
# Conflicts:
#	x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/EsqlTestUtils.java
# Conflicts:
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/EsqlFunctionRegistry.java
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/grouping/TBucket.java
@ivancea ivancea added >feature Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) :Analytics/ES|QL AKA ESQL labels Oct 31, 2025
ivancea and others added 6 commits November 7, 2025 17:25
Copy link
Contributor

@bpintea bpintea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
Could we add some REST tests with timezones set as JSON field / query parameter and maybe compare with another run of same query SETting it?

/**
* Support timezones in DATE_TRUNC and dependent functions.
*/
DATE_TRUNC_TIMEZONE_SUPPORT(Build.current().isSnapshot()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you could also have:

Suggested change
DATE_TRUNC_TIMEZONE_SUPPORT(Build.current().isSnapshot()),
DATE_TRUNC_TIMEZONE_SUPPORT(SET_COMMAND.isEnabled()),

if you want to link them. But then you could also introduce two caps, if you want to isolate the SET-related logic. Just some thoughts, it can stay as is.

@ivancea
Copy link
Contributor Author

ivancea commented Nov 10, 2025

@bpintea Tests for request/SET settings were added here, if that's what you mean: https://github.com/elastic/elasticsearch/pull/136748/files#diff-8e410478016b271c9f44f50aa2d9e5f911135694d0ac6a733e2bce7d219d23e4

Do you think that's enough, or are you thinking of some other case? Thanks!

@bpintea
Copy link
Contributor

bpintea commented Nov 10, 2025

My idea was to add some x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/RestEsqlIT.java tests that would run the same query twice:

and then comparing the results. For some randomized TZs.
But maybe we have tests already that insure that the Configuration ends up with the same TZ value already.

Copy link
Contributor

@luigidellaquila luigidellaquila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ivancea
Copy link
Contributor Author

ivancea commented Nov 12, 2025

@bpintea Nice idea; just added a test comparing the setting methods (+ the bucket/date_trunc/tbucket functions for extra checks)

@ivancea ivancea merged commit 8a7f820 into elastic:main Nov 14, 2025
34 checks passed
@ivancea ivancea deleted the esql-datetrunc-timezone branch November 14, 2025 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/ES|QL AKA ESQL >feature Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v9.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants