elastic / elasticsearch

Free and Open Source, Distributed, RESTful Search Engine
https://www.elastic.co/products/elasticsearch
Other
69.62k stars 24.64k forks source link

[ES|QL] inline-casting to `date` doesn't work #112362

Open drewdaemon opened 3 weeks ago

drewdaemon commented 3 weeks ago

Elasticsearch Version

8.15

Installed Plugins

No response

Java Version

bundled

OS Version

Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:21 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T8103 arm64

Problem Description

I would expect to be able to cast values to the date type by using value::date. Instead, I get Couldn't parse Elasticsearch ES|QL query. Check your query and try again. Error: line 1:53: Unknown data type named [date]

Steps to Reproduce

See above

Logs (if relevant)

No response

elasticsearchmachine commented 3 weeks ago

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

elasticsearchmachine commented 3 weeks ago

Pinging @elastic/kibana-esql (ES|QL-ui)

alex-spies commented 3 weeks ago

Are we sure this is a bug? The correct way to write this is value::datetime (or use the conversion functions to_datetime or its alias to_dt). Maybe we could alleviate the confusion a bit if we aliased to_datetime as to_date and ::datetime as ::date, or made sure users get a more useful error message?

drewdaemon commented 3 weeks ago

@alex-spies, @nik9000 asked me for a bug so I gave it to him :)

But, yes, you could reclassify as an enhancement. The idea is to move away from datetime toward date across the docs and language. The reasoning for this is that date is the name of the field type and datetime is essentially synonymous with date.

As to the potential confusion, I think it comes from our inconsistent use of date vs datetime which is exactly what I'm hoping we get away from.

I think the aliasing idea you put forth is a good one 👍

nik9000 commented 3 weeks ago

Yeah - with date being the name of the field in ES I think stuff like ::DATE should work. We call the type DATETIME for historical reasons, but when we render it we tend to call it date - that's it "esName".

ayushrawat99 commented 3 weeks ago

Hey. I am new. Can I pick this up ??

bpintea commented 4 days ago

Yeah - with date being the name of the field in ES I think stuff like ::DATE should work

This was added initially as an alias, but discarded on review and deferred for later. About DATE however...

The idea is to move away from datetime toward date across the docs and language.

... leaving for reference a comment here from looking at this earlier, when we concluded that we might introduce a synthetic DATE (only) type later. (Nothing concrete was decided afterwards.)