Skip to content

Commit ee0af20

Browse files
committed
Avoid renaming timestamp in TS functions
1 parent de3dd41 commit ee0af20

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

x-pack/plugin/esql/qa/testFixtures/src/main/resources/tbucket.csv-spec

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -348,22 +348,34 @@ day_total:long | hour_med:double | h:datetime | message:keyword
348348
;
349349

350350

351-
tbucketWithTimezone
351+
tbucketWithTimezoneAndDuration
352+
required_capability: ts_command_v0
352353
required_capability: date_trunc_timezone_support
353354

354355
SET time_zone = "+05:00"\;
355-
FROM employees
356-
| RENAME hire_date as @timestamp
357-
| WHERE @timestamp >= "1980-01-01T00:00:00Z"
358-
| STATS by @timestamp, bucketHours = TBUCKET(3 hours), bucketDay = TBUCKET(1 day)
356+
TS k8s
357+
| WHERE @timestamp == "2024-05-10T00:04:49.000Z"
358+
| STATS by @timestamp, bucket = TBUCKET(3 hours)
359359
| SORT @timestamp
360-
| LIMIT 5
360+
| LIMIT 2
361361
;
362362

363-
@timestamp:date | bucketHours:date | bucketDay:date
364-
1985-02-18T00:00:00.000Z | 1985-02-17T22:00:00.000Z | 1985-02-17T19:00:00.000Z
365-
1985-02-24T00:00:00.000Z | 1985-02-23T22:00:00.000Z | 1985-02-23T19:00:00.000Z
366-
1985-05-13T00:00:00.000Z | 1985-05-12T22:00:00.000Z | 1985-05-12T19:00:00.000Z
367-
1985-07-09T00:00:00.000Z | 1985-07-08T22:00:00.000Z | 1985-07-08T19:00:00.000Z
368-
1985-09-17T00:00:00.000Z | 1985-09-16T22:00:00.000Z | 1985-09-16T19:00:00.000Z
363+
@timestamp:datetime | bucket:datetime
364+
2024-05-10T00:04:49.000Z | 2024-05-09T22:00:00.000Z
365+
;
366+
367+
tbucketWithTimezoneAndPeriod
368+
required_capability: ts_command_v0
369+
required_capability: date_trunc_timezone_support
370+
371+
SET time_zone = "+05:00"\;
372+
TS k8s
373+
| WHERE @timestamp == "2024-05-10T00:04:49.000Z"
374+
| STATS by @timestamp, bucket = TBUCKET(1 day)
375+
| SORT @timestamp
376+
| LIMIT 2
377+
;
378+
379+
@timestamp:datetime | bucket:datetime
380+
2024-05-10T00:04:49.000Z | 2024-05-09T19:00:00.000Z
369381
;

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/expression/function/scalar/date/DateTruncTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ public static List<DurationTestCaseData> makeTruncDurationTestCases() {
115115
new DurationTestCaseData(Duration.ofHours(3), "2020-01-01T05:30:00Z", "UTC", "2020-01-01T03:00:00Z"),
116116
new DurationTestCaseData(Duration.ofHours(3), "2020-01-01T05:30:00Z", "+01:00", "2020-01-01T05:00:00Z"),
117117
new DurationTestCaseData(Duration.ofMinutes(3 * 60), "2020-01-01T05:30:00Z", "+01:00", "2020-01-01T05:00:00Z"),
118+
new DurationTestCaseData(Duration.ofHours(6), "2024-03-01T00:30:00Z", "-03", "2024-02-29T21:00:00Z"),
119+
new DurationTestCaseData(Duration.ofHours(24), "2024-03-01T00:30:00Z", "-03", "2024-02-29T03:00:00Z"),
118120
new DurationTestCaseData(Duration.ofHours(5), "2020-01-01T05:30:00Z", "+01", "2020-01-01T01:00:00Z"),
119121

120122
///
@@ -165,6 +167,11 @@ public static List<PeriodTestCaseData> makeTruncPeriodTestCases() {
165167
new PeriodTestCaseData(Period.ofMonths(7), ts, "UTC", "2022-11-01T00:00:00.00Z"),
166168
new PeriodTestCaseData(Period.ofYears(5), ts, "UTC", "2021-01-01T00:00:00.00Z"),
167169

170+
///
171+
/// Timezones
172+
///
173+
new PeriodTestCaseData(Period.ofDays(1), "2024-03-01T00:30:00Z", "-03", "2024-02-29T03:00:00Z"),
174+
168175
///
169176
/// Timezone with DST (-5 to -4 at 2025-03-09T02:00:00-05, and -4 to -5 at 2025-11-02T02:00:00-04)
170177
///

0 commit comments

Comments
 (0)