Skip to content

Commit f95c2a8

Browse files
committed
Add capability and YAML tests for request and SET time_zone parameters
1 parent 8172161 commit f95c2a8

File tree

2 files changed

+193
-0
lines changed

2 files changed

+193
-0
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlCapabilities.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,6 +1516,11 @@ public enum Cap {
15161516
*/
15171517
FIX_FILTER_ORDINALS,
15181518

1519+
/**
1520+
* "time_zone" parameter in request body and in {@code SET "time_zone"="x"}
1521+
*/
1522+
GLOBAL_TIMEZONE_PARAMETER(Build.current().isSnapshot()),
1523+
15191524
;
15201525

15211526
private final boolean enabled;
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
---
2+
setup:
3+
- requires:
4+
capabilities:
5+
- method: POST
6+
path: /_query
7+
parameters: [ ]
8+
capabilities: [ global_timezone_parameter ]
9+
test_runner_features: [ capabilities ]
10+
reason: "Check timezone capability"
11+
- do:
12+
indices.create:
13+
index: logs
14+
body:
15+
mappings:
16+
properties:
17+
"@timestamp":
18+
type: date
19+
20+
- do:
21+
bulk:
22+
index: tzs
23+
refresh: true
24+
body:
25+
- { "index": { } }
26+
- { "@timestamp": "2025-05-31T00:00:00Z" }
27+
- { "index": { } }
28+
- { "@timestamp": "2025-05-31T01:00:00Z" }
29+
- { "index": { } }
30+
- { "@timestamp": "2025-05-31T22:00:00Z" }
31+
- { "index": { } }
32+
- { "@timestamp": "2025-05-31T23:00:00Z" }
33+
34+
---
35+
Default UTC:
36+
- do:
37+
esql.query:
38+
body:
39+
query: |
40+
FROM tzs
41+
| EVAL
42+
hour=DATE_EXTRACT("hour_of_day", @timestamp),
43+
day_name=DAY_NAME(@timestamp),
44+
month_name=MONTH_NAME(@timestamp)
45+
| SORT @timestamp ASC
46+
| LIMIT 5
47+
48+
- length: { columns: 4 }
49+
- match: { columns.0.name: "@timestamp" }
50+
- match: { columns.1.name: "hour" }
51+
- match: { columns.2.name: "day_name" }
52+
- match: { columns.3.name: "month_name" }
53+
54+
- length: { values: 4 }
55+
- match: { values.0.0: "2025-05-31T00:00:00.000Z" }
56+
- match: { values.0.1: 0 }
57+
- match: { values.0.2: "Saturday" }
58+
- match: { values.0.3: "May" }
59+
- match: { values.1.0: "2025-05-31T01:00:00.000Z" }
60+
- match: { values.1.1: 1 }
61+
- match: { values.1.2: "Saturday" }
62+
- match: { values.1.3: "May" }
63+
- match: { values.2.0: "2025-05-31T22:00:00.000Z" }
64+
- match: { values.2.1: 22 }
65+
- match: { values.2.2: "Saturday" }
66+
- match: { values.2.3: "May" }
67+
- match: { values.3.0: "2025-05-31T23:00:00.000Z" }
68+
- match: { values.3.1: 23 }
69+
- match: { values.3.2: "Saturday" }
70+
- match: { values.3.3: "May" }
71+
72+
---
73+
Paris tz with SET:
74+
- do:
75+
esql.query:
76+
body:
77+
query: |
78+
SET time_zone="Europe/Paris";
79+
FROM tzs
80+
| EVAL
81+
hour=DATE_EXTRACT("hour_of_day", @timestamp),
82+
day_name=DAY_NAME(@timestamp),
83+
month_name=MONTH_NAME(@timestamp)
84+
| SORT @timestamp ASC
85+
| LIMIT 5
86+
87+
- length: { columns: 4 }
88+
- match: { columns.0.name: "@timestamp" }
89+
- match: { columns.1.name: "hour" }
90+
- match: { columns.2.name: "day_name" }
91+
- match: { columns.3.name: "month_name" }
92+
93+
- length: { values: 4 }
94+
- match: { values.0.0: "2025-05-31T00:00:00.000Z" }
95+
- match: { values.0.1: 2 }
96+
- match: { values.0.2: "Saturday" }
97+
- match: { values.0.3: "May" }
98+
- match: { values.1.0: "2025-05-31T01:00:00.000Z" }
99+
- match: { values.1.1: 3 }
100+
- match: { values.1.2: "Saturday" }
101+
- match: { values.1.3: "May" }
102+
- match: { values.2.0: "2025-05-31T22:00:00.000Z" }
103+
- match: { values.2.1: 0 }
104+
- match: { values.2.2: "Sunday" }
105+
- match: { values.2.3: "June" }
106+
- match: { values.3.0: "2025-05-31T23:00:00.000Z" }
107+
- match: { values.3.1: 1 }
108+
- match: { values.3.2: "Sunday" }
109+
- match: { values.3.3: "June" }
110+
111+
---
112+
Paris tz with request parameter:
113+
- do:
114+
esql.query:
115+
body:
116+
time_zone: "Europe/Paris"
117+
query: |
118+
FROM tzs
119+
| EVAL
120+
hour=DATE_EXTRACT("hour_of_day", @timestamp),
121+
day_name=DAY_NAME(@timestamp),
122+
month_name=MONTH_NAME(@timestamp)
123+
| SORT @timestamp ASC
124+
| LIMIT 5
125+
126+
- length: { columns: 4 }
127+
- match: { columns.0.name: "@timestamp" }
128+
- match: { columns.1.name: "hour" }
129+
- match: { columns.2.name: "day_name" }
130+
- match: { columns.3.name: "month_name" }
131+
132+
- length: { values: 4 }
133+
- match: { values.0.0: "2025-05-31T00:00:00.000Z" }
134+
- match: { values.0.1: 2 }
135+
- match: { values.0.2: "Saturday" }
136+
- match: { values.0.3: "May" }
137+
- match: { values.1.0: "2025-05-31T01:00:00.000Z" }
138+
- match: { values.1.1: 3 }
139+
- match: { values.1.2: "Saturday" }
140+
- match: { values.1.3: "May" }
141+
- match: { values.2.0: "2025-05-31T22:00:00.000Z" }
142+
- match: { values.2.1: 0 }
143+
- match: { values.2.2: "Sunday" }
144+
- match: { values.2.3: "June" }
145+
- match: { values.3.0: "2025-05-31T23:00:00.000Z" }
146+
- match: { values.3.1: 1 }
147+
- match: { values.3.2: "Sunday" }
148+
- match: { values.3.3: "June" }
149+
150+
---
151+
Set overrides request parameter:
152+
- do:
153+
esql.query:
154+
body:
155+
time_zone: "Europe/Paris"
156+
query: |
157+
SET time_zone="+04:00";
158+
FROM tzs
159+
| EVAL
160+
hour=DATE_EXTRACT("hour_of_day", @timestamp),
161+
day_name=DAY_NAME(@timestamp),
162+
month_name=MONTH_NAME(@timestamp)
163+
| SORT @timestamp ASC
164+
| LIMIT 5
165+
166+
- length: { columns: 4 }
167+
- match: { columns.0.name: "@timestamp" }
168+
- match: { columns.1.name: "hour" }
169+
- match: { columns.2.name: "day_name" }
170+
- match: { columns.3.name: "month_name" }
171+
172+
- length: { values: 4 }
173+
- match: { values.0.0: "2025-05-31T00:00:00.000Z" }
174+
- match: { values.0.1: 4 }
175+
- match: { values.0.2: "Saturday" }
176+
- match: { values.0.3: "May" }
177+
- match: { values.1.0: "2025-05-31T01:00:00.000Z" }
178+
- match: { values.1.1: 5 }
179+
- match: { values.1.2: "Saturday" }
180+
- match: { values.1.3: "May" }
181+
- match: { values.2.0: "2025-05-31T22:00:00.000Z" }
182+
- match: { values.2.1: 2 }
183+
- match: { values.2.2: "Sunday" }
184+
- match: { values.2.3: "June" }
185+
- match: { values.3.0: "2025-05-31T23:00:00.000Z" }
186+
- match: { values.3.1: 3 }
187+
- match: { values.3.2: "Sunday" }
188+
- match: { values.3.3: "June" }

0 commit comments

Comments
 (0)