Skip to content

[ES|QL] Support Named and Positional Parameters in EsqlQueryRequest#108421

Merged
fang-xing-esql merged 38 commits intoelastic:mainfrom
fang-xing-esql:namedParameters
Jun 11, 2024
Merged

[ES|QL] Support Named and Positional Parameters in EsqlQueryRequest#108421
fang-xing-esql merged 38 commits intoelastic:mainfrom
fang-xing-esql:namedParameters

Conversation

@fang-xing-esql
Copy link
Copy Markdown
Member

@fang-xing-esql fang-xing-esql commented May 8, 2024

Resolve #107029

Unnamed parameters are already supported in EsqlQueryRequest. e.g.

{
  "version": "2024.04.01",
  "query": "ROW x = ?",
  "params": [{"value": 1, "type" : "integer"}]
}

       x       
---------------
1              

This PR is to support named and positional parameters in EsqlQueryRequest, e.g.

Named parameter:

{
  "version": "2024.04.01",
  "query": "ROW x = ?name1, y = ?name1",
  "params": [{"name1": 1}]
}

       x       |       y       
---------------+---------------
1              |1    

Positional parameter

{
  "version": "2024.04.01",
  "query": "ROW x = ?1, y = ?1",
  "params": [{"name1": 1}]
}
'

       x       |       y       
---------------+---------------
1              |1      

And also drop the support to explicit type:

{
  "version": "2024.04.01",
  "query": "ROW x = ?",
  "params": [{"value": 1}]
}

       x       
---------------
1              

@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

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

Copy link
Copy Markdown
Member

@costin costin left a comment

Choose a reason for hiding this comment

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

Had a call with Fang about this.
FTR:

  • mixing anonymous, named and ordinal params should not be allowed
  • drop param type, we never use it/advertised it
  • change List to a Params like object that returns the value of the given input param and does validation (for params to not be mixed, invalid ordinal, names, etc...)

@fang-xing-esql fang-xing-esql added the ES|QL-ui Impacts ES|QL UI label May 13, 2024
@fang-xing-esql fang-xing-esql marked this pull request as ready for review May 14, 2024 21:38
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

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

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

@bpintea bpintea left a comment

Choose a reason for hiding this comment

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

Had a first look, left some comments. I guess deciding to remove the type would make things clearer about how to progress.

final class RequestXContent {

private static final ConstructingObjectParser<TypedParamValue, Void> PARAM_PARSER = new ConstructingObjectParser<>(
private static class TempObjects {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This feels like a strange class to have. I guess if we get rid of the Params it might no longer be needed.

Copy link
Copy Markdown
Member

@costin costin left a comment

Choose a reason for hiding this comment

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

This needs more work. In its current form it's breaking bwc since it changes the declaration for anonymous / un-named params from values: [1,2,3, "string"] to values: {[value:1], ...

This is of course a problem

@costin
Copy link
Copy Markdown
Member

costin commented May 17, 2024

Unnamed parameters are already supported in EsqlQueryRequest. e.g.

{
  "version": "2024.04.01",
  "query": "ROW x = ?",
  "params": [{"value": 1, "type" : "integer"}]
}

       x       
---------------
1              

^
This is inaccurate - this style was supported by not advertised and now it is being removed.
The PR should preserve the current style which is:

{
"version": "2024.04.01",
"query": "ROW x = ?",
"params": [2, 3, "string"]
}

@fang-xing-esql
Copy link
Copy Markdown
Member Author

This needs more work. In its current form it's breaking bwc since it changes the declaration for anonymous / un-named params from values: [1,2,3, "string"] to values: {[value:1], ...

This is of course a problem

We will keep params as an array, since it is already an array, not an object.

Copy link
Copy Markdown
Contributor

@astefan astefan left a comment

Choose a reason for hiding this comment

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

I haven't looked at the tests yet, but there are aspects that can be improved regarding the error messaging and, probably, the way these error messages are tested.

@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

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

@fang-xing-esql
Copy link
Copy Markdown
Member Author

I haven't looked at the tests yet, but there are aspects that can be improved regarding the error messaging and, probably, the way these error messages are tested.

Thanks for reviewing @astefan ! The tests and messages are updated in the last commit, just need to clean up CI.

Copy link
Copy Markdown
Member

@costin costin left a comment

Choose a reason for hiding this comment

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

LGTM

@fang-xing-esql
Copy link
Copy Markdown
Member Author

I haven't looked at the tests yet, but there are aspects that can be improved regarding the error messaging and, probably, the way these error messages are tested.

Thank you so much for thorough review @astefan !! I believe that the existing comments are all addressed. Please just let me know if I missed anything.

Copy link
Copy Markdown
Contributor

@astefan astefan left a comment

Choose a reason for hiding this comment

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

For the ParsingExceptions that I was suggesting to have the location included in the message in EsqlParser, please also adjust any tests that assert those messages.

Once the latest comments are addressed, this LGTM. Thank you for your patience with all the comments I had.

@fang-xing-esql fang-xing-esql merged commit ccef9e7 into elastic:main Jun 11, 2024
stratoula added a commit to elastic/kibana that referenced this pull request Jul 17, 2024
…eld (#184361)

## Summary

Based on elastic/elasticsearch#108421

Closes #180805

It allows the users to add an `?earliest` and `?latest` variable in the
ES|QL editor.

When we are detecting this variable, we are also sending the values to
ES.

- Earliest is the from value of the date picker
- Latest is the to value of the date picker


![meow](https://github.com/elastic/kibana/assets/17003240/177ceafe-558d-43ea-809c-f0ec2833ec17)

Usage in bucket


![meow](https://github.com/elastic/kibana/assets/17003240/8dea8188-b4e0-43e6-894e-236811374030)

This enables 2 very important features:

- I can use the values of the time picker in the bucket function
- I can use the time picker for indices without `@timestamp` field

### For reviewers
- Although it seems as a big PR, the majority of the changes happen due
to the signature change of the `getESQLAdHocDataview`
- The ML changes are mostly because the ML code has a lot of repetition.
I think the code needs to be refactored to have a central point
(preferably the `getESQLResults` from the esql-utils. I will create an
issue for the ML team.
- I am not proposing this in bucket autocomplete because it doesnt work
great in general for the date histogram case. We are working on
autocomplete improvements so I am expecting this to be part of a follow
up PR.
- I want to talk to the docs team to add it in the docs.


### Follow ups
- Change the histogram to use the bucket instead of the date_trunc
(needs investigation first)
- Speak with the docs team about adding an example on our official docs


### Flaky test runner 
https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/6521

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Julia Rechkunova <julia.rechkunova@gmail.com>
@fang-xing-esql fang-xing-esql deleted the namedParameters branch August 5, 2024 13:25
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: Named parameters

6 participants