Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ES|QL] Convert string to datetime when the other size of an arithmetic operator is date_period or time_duration #108455

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

fang-xing-esql
Copy link
Contributor

Resolves : #108432

eval x = 1 day + "2024-01-01" this will work after this change. Users don't need to call to_dt explicitly like this eval x = 1 day + to_dt("2024-01-01")

@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label May 9, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

@elasticsearchmachine
Copy link
Collaborator

Hi @fang-xing-esql, I've created a changelog YAML for you.

Copy link
Contributor

@alex-spies alex-spies left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @fang-xing-esql , looks good!

I'd increase test coverage a bit, though; maybe we could also add an analyzer/verifier test that confirms that arbitrary functions producing a (foldable) string can't be used, so that e.g. mv_concat("2024", "-04", "-01") + 1 day is invalid.

@@ -0,0 +1,6 @@
pr: 108455
summary: "[ES|QL] Convert string to datetime when the other size of an arithmetic\
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
summary: "[ES|QL] Convert string to datetime when the other size of an arithmetic\
summary: "[ES|QL] Convert string to datetime when the other side of an arithmetic\

You'll probably need to update the typo in the PR title as well, otherwise the bot may not honor any changes to the changelog.

implicitCastingArithmeticOperation
required_capability: string_literal_auto_casting_to_datetime_add_sub
from employees
| eval x = 1 day + "2024-01-01", y = 1 year + "2024-04-01" + 1 month, z = "2024-01-01" + 3600 seconds
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Maybe let's add a test for to_datetime(null) + 1 day (and other durations/periods) as well.
  • This does not cover subtractions, let's add a test for those as well.
  • Optionally, we could also add tests for expressions like "2024-04-01" + (1 year + 1 day) and expressions where the literal datetime has a an hour/minute/second as well, although this is getting into paranoid territory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/ES|QL AKA ESQL >enhancement ES|QL-ui Impacts ES|QL UI Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v8.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ES|QL] implicit datetime casting for binary operator args
3 participants