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

ESQL: Formalize common type conversions inside a query #104638

Open
costin opened this issue Jan 23, 2024 · 2 comments
Open

ESQL: Formalize common type conversions inside a query #104638

costin opened this issue Jan 23, 2024 · 2 comments
Labels
:Analytics/ES|QL AKA ESQL >enhancement Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo)

Comments

@costin
Copy link
Member

costin commented Jan 23, 2024

Description

A common pattern in certain queries is to declare values as strings even though the underlying consumer expects a different type - e.g. declare dates as strings; see #104547
Instead of addressing this locally, which can be problematic as the consumer has to perform both conversion and error reporting, this is better addressed in a centralized matter:

// instead of internal conversion
| AUTO_BUCKET(hire_date, 20,  "1985-01-01T00:00:00Z", "1986-01-01T00:00:00Z")

// use external, inlined conversion
AUTO_BUCKET(hire_date, 20, to_datetime("1985-01-01T00:00:00Z"), to_datetime("1986-01-01T00:00:00Z"))

For this to happen, the Analyzer would catch the type difference and add a synthetic conversion in place, which can then bubble up.
Note that we'd like the conversion to be applied early, in order to catch any potential failures as soon as possible.

P.S. This is a topic that occurred in SQL several times as well:
#49636
#77055

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

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

@luigidellaquila
Copy link
Contributor

It should be straight forward for binary operators (e.g. make left and right values uniform by converting one of the two).

For functions it could be more tricky, because the supported input types for each single function are defined in code and checked at resolution/validation time (resolveType() method); today we have no API that can tell the optimizer which types (and which type combinations, for multiple parameters) a function accepts.

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 Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo)
Projects
None yet
Development

No branches or pull requests

3 participants