Skip to content

Commit 7e43605

Browse files
not-napoleonelasticsearchmachine
andauthored
Esql Support date nanos on date diff function (#120645)
Resolves #109999 This adds support for date nanos in the date diff function, as well as mixed nanos/millis use cases. --------- Co-authored-by: elasticsearchmachine <[email protected]>
1 parent dc4fa26 commit 7e43605

File tree

17 files changed

+1823
-22
lines changed

17 files changed

+1823
-22
lines changed

docs/changelog/120645.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 120645
2+
summary: Esql Support date nanos on date diff function
3+
area: ES|QL
4+
type: enhancement
5+
issues:
6+
- 109999

docs/reference/esql/functions/kibana/definition/date_diff.json

Lines changed: 144 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/esql/functions/types/date_diff.asciidoc

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,3 +1249,28 @@ sv_nanos:date_nanos | a:keyword | b:keyword | c:keywo
12491249
2023-03-23T12:15:03.360103847Z | 2023-03-23T12:15:03.360Z | 2023-03-23 | 2023-03-23T12:15:03.360103847Z
12501250
2023-03-23T12:15:03.360103847Z | 2023-03-23T12:15:03.360Z | 2023-03-23 | 2023-03-23T12:15:03.360103847Z
12511251
;
1252+
1253+
Date Nanos Date Diff
1254+
required_capability: date_nanos_date_diff
1255+
required_capability: to_date_nanos
1256+
1257+
FROM date_nanos
1258+
| EVAL n = MV_MAX(nanos)
1259+
| EVAL diff_sec = DATE_DIFF("seconds", TO_DATE_NANOS("2023-10-23T12:15:03.360103847Z"), n)
1260+
| EVAL diff_sec_m = DATE_DIFF("seconds", TO_DATETIME("2023-10-23T12:15:03.360103847Z"), n)
1261+
| KEEP diff_sec, diff_sec_m, n;
1262+
ignoreOrder:true
1263+
1264+
# Note - it is expected that the millisecond diff is slightly different due to rounding.
1265+
diff_sec:integer | diff_sec_m:integer | n:date_nanos
1266+
5998 | 5998 | 2023-10-23T13:55:01.543123456Z
1267+
5932 | 5932 | 2023-10-23T13:53:55.832987654Z
1268+
5871 | 5871 | 2023-10-23T13:52:55.015787878Z
1269+
5811 | 5811 | 2023-10-23T13:51:54.732102837Z
1270+
4711 | 4711 | 2023-10-23T13:33:34.937193000Z
1271+
745 | 745 | 2023-10-23T12:27:28.948000000Z
1272+
0 | 0 | 2023-10-23T12:15:03.360103847Z
1273+
0 | 0 | 2023-10-23T12:15:03.360103847Z
1274+
-18489600 | -18489599 | 2023-03-23T12:15:03.360103847Z
1275+
-18489600 | -18489599 | 2023-03-23T12:15:03.360103847Z
1276+
;

x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/date/DateDiffConstantMillisEvaluator.java

Lines changed: 168 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)