Skip to content

Commit 52be761

Browse files
not-napoleonelasticsearchmachine
andcommitted
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 bd96122 commit 52be761

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
@@ -1241,3 +1241,28 @@ sv_nanos:date_nanos | a:keyword | b:keyword | c:keywo
12411241
2023-03-23T12:15:03.360103847Z | 2023-03-23T12:15:03.360Z | 2023-03-23 | 2023-03-23T12:15:03.360103847Z
12421242
2023-03-23T12:15:03.360103847Z | 2023-03-23T12:15:03.360Z | 2023-03-23 | 2023-03-23T12:15:03.360103847Z
12431243
;
1244+
1245+
Date Nanos Date Diff
1246+
required_capability: date_nanos_date_diff
1247+
required_capability: to_date_nanos
1248+
1249+
FROM date_nanos
1250+
| EVAL n = MV_MAX(nanos)
1251+
| EVAL diff_sec = DATE_DIFF("seconds", TO_DATE_NANOS("2023-10-23T12:15:03.360103847Z"), n)
1252+
| EVAL diff_sec_m = DATE_DIFF("seconds", TO_DATETIME("2023-10-23T12:15:03.360103847Z"), n)
1253+
| KEEP diff_sec, diff_sec_m, n;
1254+
ignoreOrder:true
1255+
1256+
# Note - it is expected that the millisecond diff is slightly different due to rounding.
1257+
diff_sec:integer | diff_sec_m:integer | n:date_nanos
1258+
5998 | 5998 | 2023-10-23T13:55:01.543123456Z
1259+
5932 | 5932 | 2023-10-23T13:53:55.832987654Z
1260+
5871 | 5871 | 2023-10-23T13:52:55.015787878Z
1261+
5811 | 5811 | 2023-10-23T13:51:54.732102837Z
1262+
4711 | 4711 | 2023-10-23T13:33:34.937193000Z
1263+
745 | 745 | 2023-10-23T12:27:28.948000000Z
1264+
0 | 0 | 2023-10-23T12:15:03.360103847Z
1265+
0 | 0 | 2023-10-23T12:15:03.360103847Z
1266+
-18489600 | -18489599 | 2023-03-23T12:15:03.360103847Z
1267+
-18489600 | -18489599 | 2023-03-23T12:15:03.360103847Z
1268+
;

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)