Skip to content

Commit

Permalink
[ESQL] Add TO_DATE_NANOS conversion function (elastic#112150) (elasti…
Browse files Browse the repository at this point in the history
…c#113641)

Resolves elastic#111842

This adds a conversion function that yields DATE_NANOS. Mostly this is straight forward.

It is worth noting that when converting a millisecond date into a nanosecond date, the conversion function truncates it to 0 nanoseconds (i.e. first nanosecond of that millisecond). This is, of course, a bit of an assumption, but I don't have a better assumption we can make. I'd thought about adding a second, optional, parameter to control this behavior, but it's important that TO_DATE_NANOS extend AbstractConvertFunction, which itself extends UnaryScalarFunction, so that it will work correctly with union types. Also, it's unlikely the user will have any better guess than we do for filling in the nanoseconds.

Making that assumption does, however, create some weirdness. Consider two comparisons:

TO_DATETIME("2023-03-23T12:15:03.360103847") == TO_DATETIME("2023-03-23T12:15:03.360") will return true while TO_DATE_NANOS("2023-03-23T12:15:03.360103847") == TO_DATE_NANOS("2023-03-23T12:15:03.360") will return false. This is akin to casting between longs and doubles, where things may compare equal in one type that are not equal in the other. This seems fine, and I can't think of a better way to do it, but it's worth being aware of.

---------

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
not-napoleon and elasticmachine authored Sep 27, 2024
1 parent 4ea42af commit d2a8996
Show file tree
Hide file tree
Showing 34 changed files with 1,104 additions and 128 deletions.
5 changes: 0 additions & 5 deletions docs/reference/esql/functions/description/qstr.asciidoc

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions docs/reference/esql/functions/examples/qstr.asciidoc

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 0 additions & 36 deletions docs/reference/esql/functions/kibana/definition/qstr.json

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/esql/functions/kibana/docs/date_format.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/esql/functions/kibana/docs/mv_avg.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/esql/functions/kibana/docs/mv_sum.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions docs/reference/esql/functions/kibana/docs/qstr.md

This file was deleted.

8 changes: 8 additions & 0 deletions docs/reference/esql/functions/kibana/docs/to_date_nanos.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/reference/esql/functions/kibana/inline_cast.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 0 additions & 17 deletions docs/reference/esql/functions/layout/qstr.asciidoc

This file was deleted.

16 changes: 16 additions & 0 deletions docs/reference/esql/functions/layout/to_date_nanos.asciidoc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion docs/reference/esql/functions/signature/qstr.svg

This file was deleted.

1 change: 1 addition & 0 deletions docs/reference/esql/functions/signature/to_date_nanos.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
millis:date,nanos:date_nanos
2023-10-23T13:55:01.543Z,2023-10-23T13:55:01.543123456Z
2023-10-23T13:53:55.832Z,2023-10-23T13:53:55.832987654Z
2023-10-23T13:52:55.015Z,2023-10-23T13:52:55.015787878Z
2023-10-23T13:51:54.732Z,2023-10-23T13:51:54.732102837Z
2023-10-23T13:33:34.937Z,2023-10-23T13:33:34.937193000Z
2023-10-23T12:27:28.948Z,2023-10-23T12:27:28.948000000Z
2023-10-23T12:15:03.360Z,2023-10-23T12:15:03.360103847Z
1999-10-23T12:15:03.360Z,[2023-03-23T12:15:03.360103847Z, 2023-02-23T13:33:34.937193000Z, 2023-01-23T13:55:01.543123456Z]
millis:date,nanos:date_nanos,num:long
2023-10-23T13:55:01.543Z,2023-10-23T13:55:01.543123456Z,1698069301543123456
2023-10-23T13:53:55.832Z,2023-10-23T13:53:55.832987654Z,1698069235832987654
2023-10-23T13:52:55.015Z,2023-10-23T13:52:55.015787878Z,1698069175015787878
2023-10-23T13:51:54.732Z,2023-10-23T13:51:54.732102837Z,1698069114732102837
2023-10-23T13:33:34.937Z,2023-10-23T13:33:34.937193000Z,1698068014937193000
2023-10-23T12:27:28.948Z,2023-10-23T12:27:28.948000000Z,1698064048948000000
2023-10-23T12:15:03.360Z,2023-10-23T12:15:03.360103847Z,1698063303360103847
1999-10-23T12:15:03.360Z,[2023-03-23T12:15:03.360103847Z, 2023-02-23T13:33:34.937193000Z, 2023-01-23T13:55:01.543123456Z], 0
Loading

0 comments on commit d2a8996

Please sign in to comment.