elastic / kibana

Your window into the Elastic Stack
https://www.elastic.co/products/kibana
Other
19.77k stars 8.17k forks source link

[ES|QL] Client side validation enhancements #177699

Open stratoula opened 7 months ago

stratoula commented 7 months ago

Kibana version:

Here we are gathering enhancements of the client side validation which means things that ES is marking as errors but we allow them. The impact is low because the users will get the errors when run the query on the server side.

... | eval b = ... | stats a = avg(field) | keep b

Here b is not valid as stats is not using it

FROM kibana_sample_data_logs | KEEP `geo`.`dest`
elasticmachine commented 7 months ago

Pinging @elastic/kibana-visualizations (Team:Visualizations)

elasticmachine commented 6 months ago

Pinging @elastic/kibana-esql (Team:ESQL)

drewdaemon commented 5 months ago

Added problem case: from kibana_sample_data_logs | where 23where shouldn't accept non-boolean expressions

stratoula commented 5 months ago

Nice catch!

dej611 commented 5 months ago

Added problem case: from kibana_sample_data_logs | where 23where shouldn't accept non-boolean expressions

This is a legacy problem. ES has been accepting them casting any non-boolean values as false in the past so the validation code had to be relaxed. It can be made stricter again but mind that can change again.

stratoula commented 5 months ago

I think the latter addition from index | stats max(<date_field>) is much more important case as is a very common thing to do and we should prioritize it. The from kibana_sample_data_logs | where 23 is not bothering me so much as the editor doesn't complain, it should but is ok if we fix it with lower priority. But the aggregations with date fields is an important mis-validation from our side.

dej611 commented 5 months ago

I went checking the ES annotations for Max but it's not mention any date: https://github.com/elastic/elasticsearch/blob/main/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/aggregate/Max.java

Also the documentation seems to not mention dates.

Given the work on auto sync the signatures from ES, it is probably worth notifying this thing to them as well, to avoid regressions.

drewdaemon commented 5 months ago

@dej611 thanks for looking into that! It's a good idea to let them know, but FWIW we've changed strategy and won't be using those signature annotations in https://github.com/elastic/kibana/issues/179634. Instead, the function signatures will be generated from the unit tests in Elasticsearch (ref).

dej611 commented 5 months ago

There are no date tests for the max aggs function in Elasticsearch: https://github.com/elastic/elasticsearch/blob/main/x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/aggregation/, hence the lack of annotation.

sphilipse commented 4 months ago

Index patterns with a negative produce a syntax error, despite working perfectly:

Screenshot 2024-05-15 at 15 12 51

(this pattern should return all indices except those that start with a .)

drewdaemon commented 4 months ago

@sphilipse thanks for the report

drewdaemon commented 4 months ago

Pretty much all functions and operators can accept null in place of any parameter. We should update the validation to reflect this.

stratoula commented 3 months ago

We are tracking valid time units as wrong

CleanShot 2024-06-07 at 13 40 44@2x

drewdaemon commented 3 months ago

We aren't catching nested aggregation functions (e.g. from kibana_sample_data_logs | stats avg(to_long(avg(1))))

stratoula commented 3 months ago

I looked through all the open issues here and except maybe from this

 Wrapped boolean expression are not always handled with their final type:

all the others are mostly enhancements. So I am lowering the impact from high to medium.

stratoula commented 3 months ago

Using field names that are also field types cause the validation to complain wrongly

image
dej611 commented 3 months ago

Using field names that are also field types cause the validation to complain wrongly

image

The ip field is of type IP. I guess trim implicitly cast it to string on ES side.

stratoula commented 3 months ago

Sorry MArco what do you mean? If I use meow instead of ip the client side validator won't complain. Dissect must return strings if I am not mistaken

dej611 commented 3 months ago

Yeah, you are right. I guess that is a type conflict that the validation logic won't fix by default. I guess that is another issue of the Make variable/fields check aware of query location problem.

drewdaemon commented 2 months ago

... | STATS AVG(false OR false) should be an error. AVG does not support boolean. The validator works correctly with a literal: ... | STATS AVG(false), just not a function return type.

cc @stratoula

stratoula commented 4 weeks ago

I cleaned it up and kept here only the enhancements (also updated the description)

We are going to gather the bugs here https://github.com/elastic/kibana/issues/192255

Validation bugs are things we are marking as errors while they are not in ES side