Skip to content

Commit 78207eb

Browse files
committed
Additional support for docs for ES|QL operators and version-specific differentiation (elastic#125251)
This PR was originally focused on improving support for Kibana docs, in particular the missing operator docs, but it has expanded to cover a bunch of related things: * Primarily the main work was to improve operators support. ESQL generated docs cover all functions and most operators for which their is a clear operator class and test class. However, some are built-in behaviour and need additional support. This PR adds more generated content for those operators. * Various specific operators requested by Kibana: Cast & null-predicates, and in particular the addition of examples * Two functions without examples: mv_append and to_date_nanos * Many small visual document cleanups (spelling, grammar, capitalization, etc.) * Initial support for `applies_to` for multi-version differentiation. This last point requires more work, as it is not yet agreed on just how we want this to look. We'll probably need to do refinements in followup PR. Consider the version in this PR as a first step into how this could look.
1 parent 959469a commit 78207eb

File tree

27 files changed

+1075
-116
lines changed

27 files changed

+1075
-116
lines changed

docs/reference/query-languages/esql/_snippets/operators/examples/cast.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
% This is generated by ESQL's AbstractFunctionTestCase. Do no edit it. See ../README.md for how to regenerate it.
2+
13
**Example**
24

35
```esql

docs/reference/query-languages/esql/_snippets/operators/examples/predicates.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
% This is generated by ESQL's AbstractFunctionTestCase. Do no edit it. See ../README.md for how to regenerate it.
2+
13
**Examples**
24

35
```esql

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ emp_no:integer | languages:integer | height:double
218218
convertToDatePeriod
219219
required_capability: cast_string_literal_to_temporal_amount
220220
//tag::castToDatePeriod[]
221-
row x = "2024-01-01"::datetime | eval y = x + "3 DAYS"::date_period, z = x - to_dateperiod("3 days");
221+
ROW x = "2024-01-01"::datetime
222+
| EVAL y = x + "3 DAYS"::date_period, z = x - TO_DATEPERIOD("3 days");
222223
//end::castToDatePeriod[]
223224

224225
//tag::castToDatePeriod-result[]
@@ -230,7 +231,8 @@ x:datetime |y:datetime |z:datetime
230231
convertToTimeDuration
231232
required_capability: cast_string_literal_to_temporal_amount
232233
//tag::castToTimeDuration[]
233-
row x = "2024-01-01"::datetime | eval y = x + "3 hours"::time_duration, z = x - to_timeduration("3 hours");
234+
ROW x = "2024-01-01"::datetime
235+
| EVAL y = x + "3 hours"::time_duration, z = x - TO_TIMEDURATION("3 hours");
234236
//end::castToTimeDuration[]
235237

236238
//tag::castToTimeDuration-result[]

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ null
344344

345345
docsDateDiff#[skip:-8.12.99, reason:date_diff added in 8.13]
346346
// tag::docsDateDiff[]
347-
ROW date1 = TO_DATETIME("2023-12-02T11:00:00.000Z"), date2 = TO_DATETIME("2023-12-02T11:00:00.001Z")
347+
ROW date1 = TO_DATETIME("2023-12-02T11:00:00.000Z"),
348+
date2 = TO_DATETIME("2023-12-02T11:00:00.001Z")
348349
| EVAL dd_ms = DATE_DIFF("microseconds", date1, date2)
349350
// end::docsDateDiff[]
350351
;
@@ -425,12 +426,12 @@ evalDateDiffYearForDocs
425426
required_capability: date_diff_year_calendarial
426427

427428
// tag::evalDateDiffYearForDocs[]
428-
ROW end_23=TO_DATETIME("2023-12-31T23:59:59.999Z"),
429-
start_24=TO_DATETIME("2024-01-01T00:00:00.000Z"),
430-
end_24=TO_DATETIME("2024-12-31T23:59:59.999")
431-
| EVAL end23_to_start24=DATE_DIFF("year", end_23, start_24)
432-
| EVAL end23_to_end24=DATE_DIFF("year", end_23, end_24)
433-
| EVAL start_to_end_24=DATE_DIFF("year", start_24, end_24)
429+
ROW end_23 = TO_DATETIME("2023-12-31T23:59:59.999Z"),
430+
start_24 = TO_DATETIME("2024-01-01T00:00:00.000Z"),
431+
end_24 = TO_DATETIME("2024-12-31T23:59:59.999")
432+
| EVAL end23_to_start24 = DATE_DIFF("year", end_23, start_24)
433+
| EVAL end23_to_end24 = DATE_DIFF("year", end_23, end_24)
434+
| EVAL start_to_end_24 = DATE_DIFF("year", start_24, end_24)
434435
// end::evalDateDiffYearForDocs[]
435436
;
436437

@@ -1002,7 +1003,8 @@ date:date | year:long
10021003
docsDateExtractBusinessHours
10031004
// tag::docsDateExtractBusinessHours[]
10041005
FROM sample_data
1005-
| WHERE DATE_EXTRACT("hour_of_day", @timestamp) < 9 AND DATE_EXTRACT("hour_of_day", @timestamp) >= 17
1006+
| WHERE DATE_EXTRACT("hour_of_day", @timestamp) < 9
1007+
AND DATE_EXTRACT("hour_of_day", @timestamp) >= 17
10061008
// end::docsDateExtractBusinessHours[]
10071009
;
10081010

@@ -1214,16 +1216,20 @@ required_capability: agg_values
12141216
mvAppendDates
12151217
required_capability: fn_mv_append
12161218

1219+
// tag::mv_append_date[]
12171220
FROM employees
12181221
| WHERE emp_no == 10039 OR emp_no == 10040
12191222
| SORT emp_no
1220-
| EVAL dates = mv_append(birth_date, hire_date)
1223+
| EVAL dates = MV_APPEND(birth_date, hire_date)
12211224
| KEEP emp_no, birth_date, hire_date, dates
1225+
// end::mv_append_date[]
12221226
;
12231227

1228+
// tag::mv_append_date-result[]
12241229
emp_no:integer | birth_date:date | hire_date:date | dates:date
12251230
10039 | 1959-10-01T00:00:00Z | 1988-01-19T00:00:00Z | [1959-10-01T00:00:00Z, 1988-01-19T00:00:00Z]
12261231
10040 | null | 1993-02-14T00:00:00Z | null
1232+
// end::mv_append_date-result[]
12271233
;
12281234

12291235

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,11 +619,19 @@ date nanos less than
619619
required_capability: to_date_nanos
620620
required_capability: date_nanos_binary_comparison
621621

622-
FROM date_nanos | WHERE MV_MIN(nanos) < TO_DATE_NANOS("2023-10-23T12:27:28.948Z") AND millis > "2000-01-01" | SORT nanos DESC;
622+
// tag::to_date_nanos[]
623+
FROM date_nanos
624+
| WHERE MV_MIN(nanos) < TO_DATE_NANOS("2023-10-23T12:27:28.948Z")
625+
AND millis > "2000-01-01"
626+
| SORT nanos DESC
627+
// end::to_date_nanos[]
628+
;
623629

630+
// tag::to_date_nanos-result[]
624631
millis:date | nanos:date_nanos | num:long
625632
2023-10-23T12:15:03.360Z | 2023-10-23T12:15:03.360103847Z | 1698063303360103847
626633
2023-10-23T12:15:03.360Z | 2023-10-23T12:15:03.360103847Z | 1698063303360103847
634+
// end::to_date_nanos-result[]
627635
;
628636

629637
date nanos less than, no mv min

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,8 @@ beta | 127.0.0.1
548548
ipPrefix
549549
required_capability: fn_ip_prefix
550550
//tag::ipPrefix[]
551-
row ip4 = to_ip("1.2.3.4"), ip6 = to_ip("fe80::cae2:65ff:fece:feb9")
552-
| eval ip4_prefix = ip_prefix(ip4, 24, 0), ip6_prefix = ip_prefix(ip6, 0, 112);
551+
ROW ip4 = to_ip("1.2.3.4"), ip6 = TO_IP("fe80::cae2:65ff:fece:feb9")
552+
| EVAL ip4_prefix = IP_PREFIX(ip4, 24, 0), ip6_prefix = IP_PREFIX(ip6, 0, 112);
553553
//end::ipPrefix[]
554554

555555
//tag::ipPrefix-result[]

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ base: double | value: double | s:double
237237
;
238238

239239
logofNegativeValue#[skip:-8.12.99,reason:new scalar function added in 8.13]
240-
row base = 2.0, value = -2
240+
ROW base = 2.0, value = -2
241241
| EVAL s = LOG(base, value);
242242

243243
warning:Line 2:12: evaluation of [LOG(base, value)] failed, treating result as null. Only first 20 failures recorded.
@@ -248,7 +248,7 @@ base: double | value: integer | s:double
248248
;
249249

250250
logofNegativeBase#[skip:-8.12.99,reason:new scalar function added in 8.13]
251-
row base = -2, value = 2.0
251+
ROW base = -2, value = 2.0
252252
| EVAL s = LOG(base, value);
253253

254254
warning:Line 2:12: evaluation of [LOG(base, value)] failed, treating result as null. Only first 20 failures recorded.
@@ -259,7 +259,7 @@ base: integer | value: double | s:double
259259
;
260260

261261
logofBaseOne#[skip:-8.12.99,reason:new scalar function added in 8.13]
262-
row base = 1, value = 2
262+
ROW base = 1, value = 2
263263
| EVAL s = LOG(base, value);
264264

265265
warning:Line 2:12: evaluation of [LOG(base, value)] failed, treating result as null. Only first 20 failures recorded.
@@ -270,7 +270,7 @@ base: integer | value: integer | s:double
270270
;
271271

272272
logofZero#[skip:-8.12.99,reason:new scalar function added in 8.13]
273-
row base = 2.0, value = 0.0
273+
ROW base = 2.0, value = 0.0
274274
| EVAL s = LOG(base, value);
275275

276276
warning:Line 2:12: evaluation of [LOG(base, value)] failed, treating result as null. Only first 20 failures recorded.
@@ -281,7 +281,7 @@ base:double | value:double | s:double
281281
;
282282

283283
logofNegativeZero#[skip:-8.12.99,reason:new scalar function added in 8.13]
284-
row base = 2.0, value = -0.0
284+
ROW base = 2.0, value = -0.0
285285
| EVAL s = LOG(base, value);
286286

287287
warning:Line 2:12: evaluation of [LOG(base, value)] failed, treating result as null. Only first 20 failures recorded.
@@ -292,95 +292,95 @@ base:double | value:double | s:double
292292
;
293293

294294
logofIntLong#[skip:-8.12.99,reason:new scalar function added in 8.13]
295-
row base = 10, value = to_long(1000000000000)
295+
ROW base = 10, value = to_long(1000000000000)
296296
| EVAL s = LOG(base, value);
297297

298298
base:integer | value:long | s:double
299299
10 | 1000000000000 | 12
300300
;
301301

302302
logofLongInt#[skip:-8.12.99,reason:new scalar function added in 8.13]
303-
row base = to_long(1000000000000), value = 10
303+
ROW base = to_long(1000000000000), value = 10
304304
| EVAL s = LOG(base, value);
305305

306306
base:long | value:integer | s:double
307307
1000000000000 | 10 | 0.08333333333333333
308308
;
309309

310310
logofLongLong#[skip:-8.12.99,reason:new scalar function added in 8.13]
311-
row base = to_long(1000000000000), value = to_long(1000000000000)
311+
ROW base = to_long(1000000000000), value = to_long(1000000000000)
312312
| EVAL s = LOG(base, value);
313313

314314
base:long | value:long | s:double
315315
1000000000000 | 1000000000000 |1.0
316316
;
317317

318318
logofLongDouble#[skip:-8.12.99,reason:new scalar function added in 8.13]
319-
row base = to_long(1000000000000), value = 10.0
319+
ROW base = to_long(1000000000000), value = 10.0
320320
| EVAL s = LOG(base, value);
321321

322322
base:long | value:double | s:double
323323
1000000000000 | 10.0 | 0.08333333333333333
324324
;
325325

326326
logofDoubleLong#[skip:-8.12.99,reason:new scalar function added in 8.13]
327-
row base = 10.0, value = to_long(1000000000000)
327+
ROW base = 10.0, value = to_long(1000000000000)
328328
| EVAL s = LOG(base, value);
329329

330330
base:double | value:long | s:double
331331
10.0 | 1000000000000 | 12
332332
;
333333

334334
logofLongUnsignedLong#[skip:-8.12.99,reason:new scalar function added in 8.13]
335-
row base = to_long(1000000000000), value = to_ul(1000000000000000000)
335+
ROW base = to_long(1000000000000), value = to_ul(1000000000000000000)
336336
| EVAL s = LOG(base, value);
337337

338338
base:long | value:UNSIGNED_LONG | s:double
339339
1000000000000 | 1000000000000000000 | 1.5
340340
;
341341

342342
logofUnsignedLongLong#[skip:-8.12.99,reason:new scalar function added in 8.13]
343-
row base = to_ul(1000000000000000000), value = to_long(1000000000000)
343+
ROW base = to_ul(1000000000000000000), value = to_long(1000000000000)
344344
| EVAL s = LOG(base, value);
345345

346346
base:UNSIGNED_LONG | value:long | s:double
347347
1000000000000000000 | 1000000000000 | 0.6666666666666666
348348
;
349349

350350
logofIntUnsignedLong#[skip:-8.12.99,reason:new scalar function added in 8.13]
351-
row base = 10, value = to_ul(1000000000000000000)
351+
ROW base = 10, value = to_ul(1000000000000000000)
352352
| EVAL s = LOG(base, value);
353353

354354
base:integer | value:UNSIGNED_LONG | s:double
355355
10 | 1000000000000000000 | 18.0
356356
;
357357

358358
logofUnsignedLongInt#[skip:-8.12.99,reason:new scalar function added in 8.13]
359-
row base = to_ul(1000000000000000000), value = 10
359+
ROW base = to_ul(1000000000000000000), value = 10
360360
| EVAL s = LOG(base, value);
361361

362362
base:UNSIGNED_LONG | value:integer | s:double
363363
1000000000000000000 | 10 | 0.05555555555555555
364364
;
365365

366366
logofUnsignedLongUnsignedLong#[skip:-8.12.99,reason:new scalar function added in 8.13]
367-
row base = to_ul(1000000000000000000), value = to_ul(1000000000000000000)
367+
ROW base = to_ul(1000000000000000000), value = to_ul(1000000000000000000)
368368
| EVAL s = LOG(base, value);
369369

370370
base:UNSIGNED_LONG | value:UNSIGNED_LONG | s:double
371371
1000000000000000000 | 1000000000000000000 | 1.0
372372
;
373373

374374
logofUnsignedLongDouble#[skip:-8.12.99,reason:new scalar function added in 8.13]
375-
row base = to_ul(1000000000000000000), value = 1000000000.0
375+
ROW base = to_ul(1000000000000000000), value = 1000000000.0
376376
| EVAL s = LOG(base, value);
377377

378378
base:UNSIGNED_LONG | value:double | s:double
379379
1000000000000000000 | 1.0E9 | 0.5
380380
;
381381

382382
logofDoubleUnsignedLong#[skip:-8.12.99,reason:new scalar function added in 8.13]
383-
row base = 10.0, value = to_ul(1000000000000000000)
383+
ROW base = 10.0, value = to_ul(1000000000000000000)
384384
| EVAL s = LOG(base, value);
385385

386386
base:double | value:UNSIGNED_LONG | s:double
@@ -389,7 +389,7 @@ base:double | value:UNSIGNED_LONG | s:double
389389

390390
logofInt#[skip:-8.12.99,reason:new scalar function added in 8.13]
391391
// tag::logUnary[]
392-
row value = 100
392+
ROW value = 100
393393
| EVAL s = LOG(value);
394394
// end::logUnary[]
395395

@@ -400,23 +400,23 @@ value: integer | s:double
400400
;
401401

402402
logofLong#[skip:-8.12.99,reason:new scalar function added in 8.13]
403-
row value = to_long(1000000000000)
403+
ROW value = to_long(1000000000000)
404404
| EVAL s = LOG(value);
405405

406406
value: long | s:double
407407
1000000000000 | 27.631021115928547
408408
;
409409

410410
logofUnsignedLong#[skip:-8.12.99,reason:new scalar function added in 8.13]
411-
row value = to_ul(1000000000000000000)
411+
ROW value = to_ul(1000000000000000000)
412412
| EVAL s = LOG(value);
413413

414414
value: unsigned_long | s:double
415415
1000000000000000000 | 41.44653167389282
416416
;
417417

418418
logofDouble#[skip:-8.12.99,reason:new scalar function added in 8.13]
419-
row value = 1000000000000.0
419+
ROW value = 1000000000000.0
420420
| EVAL s = LOG(value);
421421

422422
value: double | s:double
@@ -1323,7 +1323,7 @@ cbrt
13231323
required_capability: fn_cbrt
13241324
// tag::cbrt[]
13251325
ROW d = 1000.0
1326-
| EVAL c = cbrt(d)
1326+
| EVAL c = CBRT(d)
13271327
// end::cbrt[]
13281328
;
13291329

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,8 +2099,8 @@ FROM employees | STATS min = min(salary) by languages | SORT min + CASE(language
20992099

21002100
weightedAvg
21012101
required_capability: agg_weighted_avg
2102-
from employees
2103-
| stats w_avg_1 = weighted_avg(salary, 1), avg = avg(salary), w_avg_2 = weighted_avg(salary, height)
2102+
FROM employees
2103+
| STATS w_avg_1 = weighted_avg(salary, 1), avg = avg(salary), w_avg_2 = weighted_avg(salary, height)
21042104
| EVAL w_avg_1 = ROUND(w_avg_1), avg = ROUND(avg), w_avg_2 = ROUND(w_avg_2)
21052105
;
21062106

@@ -2112,7 +2112,7 @@ weightedAvgGrouping
21122112
required_capability: agg_weighted_avg
21132113
// tag::weighted-avg[]
21142114
FROM employees
2115-
| STATS w_avg = WEIGHTED_AVG(salary, height) by languages
2115+
| STATS w_avg = WEIGHTED_AVG(salary, height) BY languages
21162116
| EVAL w_avg = ROUND(w_avg)
21172117
| KEEP w_avg, languages
21182118
| SORT languages

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,9 +1722,9 @@ valuesGrouped
17221722
required_capability: agg_values
17231723

17241724
// tag::values-grouped[]
1725-
FROM employees
1725+
FROM employees
17261726
| EVAL first_letter = SUBSTRING(first_name, 0, 1)
1727-
| STATS first_name=MV_SORT(VALUES(first_name)) BY first_letter
1727+
| STATS first_name = MV_SORT(VALUES(first_name)) BY first_letter
17281728
| SORT first_letter
17291729
// end::values-grouped[]
17301730
;
@@ -1768,8 +1768,8 @@ M | [foo, bar]
17681768

17691769
locate#[skip:-8.13.99,reason:new string function added in 8.14]
17701770
// tag::locate[]
1771-
row a = "hello"
1772-
| eval a_ll = locate(a, "ll")
1771+
ROW a = "hello"
1772+
| EVAL a_ll = LOCATE(a, "ll")
17731773
// end::locate[]
17741774
;
17751775

@@ -1960,8 +1960,8 @@ base64Encode#[skip:-8.13.99,reason:new base64 function added in 8.14]
19601960
required_capability: base64_decode_encode
19611961

19621962
// tag::to_base64[]
1963-
row a = "elastic"
1964-
| eval e = to_base64(a)
1963+
ROW a = "elastic"
1964+
| EVAL e = TO_BASE64(a)
19651965
// end::to_base64[]
19661966
;
19671967

@@ -1975,8 +1975,8 @@ base64Decode#[skip:-8.13.99,reason:new base64 function added in 8.14]
19751975
required_capability: base64_decode_encode
19761976

19771977
// tag::from_base64[]
1978-
row a = "ZWxhc3RpYw=="
1979-
| eval d = from_base64(a)
1978+
ROW a = "ZWxhc3RpYw=="
1979+
| EVAL d = FROM_BASE64(a)
19801980
// end::from_base64[]
19811981
;
19821982

0 commit comments

Comments
 (0)