Skip to content

ESQL: Replace [ccq.mode] in favor of a policy prefix#105224

Merged
elasticsearchmachine merged 3 commits intoelastic:mainfrom
costin:esql/eliminate-ccq-mode
Feb 8, 2024
Merged

ESQL: Replace [ccq.mode] in favor of a policy prefix#105224
elasticsearchmachine merged 3 commits intoelastic:mainfrom
costin:esql/eliminate-ccq-mode

Conversation

@costin
Copy link
Copy Markdown
Member

@costin costin commented Feb 7, 2024

For consistency, replace [ccq.mode:] with _:policyName ENRICH [ccq.mode=any] policyName becomes ENRICH _any:policyName

For consistency, replace [ccq.mode:<type>] with _<resolution>:policyName
`ENRICH [ccq.mode=any] policyName` becomes `ENRICH _any:policyName`
@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Feb 7, 2024
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

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

Copy link
Copy Markdown
Member

@luigidellaquila luigidellaquila left a comment

Choose a reason for hiding this comment

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

Technically the PR looks good.

From a usability point of view I have some doubts, in particular for the syntax mode:policy_name clashing with CCQ syntax cluster_name:index_name.

This feature is specifically for CCQ, so users will easily mix the two things and try ENRICH cluster_name:policy_name, that would also make a lot of sense as an option to explicitly choose which cluster/enrich index you want to use.

If that's in the radar, then we have to take into consideration the fact that cluster names could clash with the keywords we are defining now for CCQ mode (_local, _coordinator, _any).

IMHO this aspect has to be clarified before merging

ENRICH_POLICY_NAME
: (LETTER | DIGIT) ENRICH_POLICY_NAME_BODY*
// allow prefix for the policy to specify its resolution
: (ENRICH_POLICY_NAME_BODY+ COLON)? ENRICH_POLICY_NAME_BODY+
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I guess changing the allowed characters here is on purpose.
Before this change, the policy name only allowed letters or numbers as first char, now any character apart from those explicitly excluded in ENRICH_POLICY_NAME_BODY is allowed.
The good is that it allows all the valid policy names to be used (eg. a policy name can start with $ or .)
The bad is that it also allows invalid policy names, eg. ., .. or names starting with +, _, -

The impact is limited though, because the validation takes care of checking that the policy does not exist.
Most of the problem is for Kibana, that will need further validation outside of the grammar

@astefan
Copy link
Copy Markdown
Contributor

astefan commented Feb 7, 2024

If that's in the radar, then we have to take into consideration the fact that cluster names could clash with the keywords we are defining now for CCQ mode (_local, _coordinator, _any)

Digging a bit in the code and performing some tests, _ (underscore) is allowed as a cluster alias. If I am not mistaken this is the regex that is checked for matches for the cluster alias name: ((\Qcluster.remote.\E)([-\w]+)\.\Qseeds\E)(?:\..*)? (this is cluster.remote.[alias_name].seeds configuration from docs) where \w definitely allows underscore. And a simple test with PUT /_cluster/settings allows _any or ___123 as an alias name.

If we will consider in the future to support ENRICH my_cluster_alias:policy_name then a cluster named _any would be ambiguous.

@costin
Copy link
Copy Markdown
Member Author

costin commented Feb 8, 2024

Enrich policies follow the same rules as an index - see

}
// The policy name is used to create the enrich index name and
// therefor a policy name has the same restrictions as an index name
MetadataCreateIndexService.validateIndexOrAliasName(
name,
(policyName, error) -> new IllegalArgumentException("Invalid policy name [" + policyName + "], " + error)
);

which leads to

if (index.charAt(0) == '_' || index.charAt(0) == '-' || index.charAt(0) == '+') {
throw exceptionCtor.apply(index, "must not start with '_', '-', or '+'");
}

Essentially _ cannot be used be used, which is consistent with the index conventions so _any, _coordinator and _remote should be safe.

The proposed grammar changes overload the meaning of : when resolving an enrich policy across CCQ.
I've checked with Nhat to confirm it makes little sense to refer to a policy from a remote cluster - it's more likely that if such ability is created, it would be done inside the policy itself on each individual cluster.
That is ENRICH remote-cluster:some-policy is highly unlikely at the moment.
Assuming it will, in that scenario one way to disambiguate is to use double qualifiers:
ENRICH _any:remote-cluster:some-policy or come up at the time with another character.

I propose to mark the feature as experimental - which we should do for CCQ as well since it has a different lifecycle than the rest of ESQL.

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've checked with Nhat to confirm it makes little sense to refer to a policy from a remote cluster - it's more likely that if such ability is created, it would be done inside the policy itself on each individual cluster.
That is ENRICH remote-cluster:some-policy is highly unlikely at the moment.
Assuming it will, in that scenario one way to disambiguate is to use double qualifiers:
ENRICH _any:remote-cluster:some-policy or come up at the time with another character.

I am ok with the change given the fairly certain aspect of cluster name aliases not being used in the future or being integrated differently.

I propose to mark the feature as experimental - which we should do for CCQ as well since it has a different lifecycle than the rest of ESQL.

👍

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.

Indeed, there's some room for initial confusion, but IMO the fact that there's no way to accidentally execute the query in an unexpected way contains it. Once you hit the first error (and dip in the documentation, which will generally have to happen before executing an ENRICH, whose policy setting up is a more involved process) the user should be set on the right path.

I don't find the syntax involving a prefixing _ particularly pretty (even after understanding its necessity).

I do find the existing ENRICH <config> <policy> ... syntax better overall (and inline with other similar languages), but not having a better alternative when:

  • having to drop the [ ] usage;
  • not wanting to introduce another keyword, which would break the command's flow.

So will 👍 and maybe we can still iterate, if marking it as experimental.

@costin costin added auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) ES|QL-ui Impacts ES|QL UI labels Feb 8, 2024
@elasticsearchmachine elasticsearchmachine merged commit 5c1e3e2 into elastic:main Feb 8, 2024
Copy link
Copy Markdown
Member

@luigidellaquila luigidellaquila left a comment

Choose a reason for hiding this comment

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

I propose to mark the feature as experimental - which we should do for CCQ as well since it has a different lifecycle than the rest of ESQL.

With this assumption LGTM, we'll have time to see if it's a real UX problem (and in case we'll have a little margin to fix it) or if we are just overestimating its impact

@costin costin deleted the esql/eliminate-ccq-mode branch February 8, 2024 16:09
dej611 added a commit to elastic/kibana that referenced this pull request Feb 9, 2024
## Summary

Sync with elastic/elasticsearch#104958 for
support of builtin fn in STATS
  * validation ✅ 
  * autocomplete ✅ 
  * also fixed `STATS BY <field>` syntax


![new_stats](https://github.com/elastic/kibana/assets/924948/735f9842-b1d3-4aa0-9d51-4b2f9b136ed3)


Sync with elastic/elasticsearch#104913 for new
`log` function
  * validation ✅  - also warning for negative values
  * autocomplete ✅ 

![add_log](https://github.com/elastic/kibana/assets/924948/146b945d-a23b-45ec-9df2-2d2b291e883b)

Sync with elastic/elasticsearch#105064 for
removal of `PROJECT` command
  * validation ✅  (both new and legacy syntax supported)
  * autocomplete ✅  (will only suggest new syntax)


![remove_project](https://github.com/elastic/kibana/assets/924948/b6f40afe-a26d-4917-b7a1-d8ae97c5368b)

Sync with elastic/elasticsearch#105221 for
removal of mandatory brackets for `METADATA` command option
* validation ✅ (added warning deprecation message when using brackets)
  * autocomplete ✅ 

![fix_metadata](https://github.com/elastic/kibana/assets/924948/c65db176-dd94-45f3-9524-45453e62f51a)


Sync with elastic/elasticsearch#105224 for
change of syntax for ENRICH ccq mode
  * validation ✅ 
* autocomplete ✅ (not directly promoted, the user has to type `_` to
trigger it)
  * hover ✅ 
  * code actions ✅ 

![fix_ccq_enrich](https://github.com/elastic/kibana/assets/924948/0900edd9-a0a7-4ac8-bc12-e39a72359984)

![fix_ccq_enrich_2](https://github.com/elastic/kibana/assets/924948/74b0908f-d385-4723-b3d4-c09108f47a73)


Do not merge until those 5 get merged.

Additional things in this PR:
* Added more tests for `callbacks` not passed scenario
  * covered more cases like those with `dissect`
* Added more tests for signature params number (calling a function with
an extra arg should return an error)
* Cleaned up some more unused code
* Improved messages on too many arguments for functions

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
CoenWarmer pushed a commit to CoenWarmer/kibana that referenced this pull request Feb 15, 2024
## Summary

Sync with elastic/elasticsearch#104958 for
support of builtin fn in STATS
  * validation ✅ 
  * autocomplete ✅ 
  * also fixed `STATS BY <field>` syntax


![new_stats](https://github.com/elastic/kibana/assets/924948/735f9842-b1d3-4aa0-9d51-4b2f9b136ed3)


Sync with elastic/elasticsearch#104913 for new
`log` function
  * validation ✅  - also warning for negative values
  * autocomplete ✅ 

![add_log](https://github.com/elastic/kibana/assets/924948/146b945d-a23b-45ec-9df2-2d2b291e883b)

Sync with elastic/elasticsearch#105064 for
removal of `PROJECT` command
  * validation ✅  (both new and legacy syntax supported)
  * autocomplete ✅  (will only suggest new syntax)


![remove_project](https://github.com/elastic/kibana/assets/924948/b6f40afe-a26d-4917-b7a1-d8ae97c5368b)

Sync with elastic/elasticsearch#105221 for
removal of mandatory brackets for `METADATA` command option
* validation ✅ (added warning deprecation message when using brackets)
  * autocomplete ✅ 

![fix_metadata](https://github.com/elastic/kibana/assets/924948/c65db176-dd94-45f3-9524-45453e62f51a)


Sync with elastic/elasticsearch#105224 for
change of syntax for ENRICH ccq mode
  * validation ✅ 
* autocomplete ✅ (not directly promoted, the user has to type `_` to
trigger it)
  * hover ✅ 
  * code actions ✅ 

![fix_ccq_enrich](https://github.com/elastic/kibana/assets/924948/0900edd9-a0a7-4ac8-bc12-e39a72359984)

![fix_ccq_enrich_2](https://github.com/elastic/kibana/assets/924948/74b0908f-d385-4723-b3d4-c09108f47a73)


Do not merge until those 5 get merged.

Additional things in this PR:
* Added more tests for `callbacks` not passed scenario
  * covered more cases like those with `dissect`
* Added more tests for signature params number (calling a function with
an extra arg should return an error)
* Cleaned up some more unused code
* Improved messages on too many arguments for functions

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
fkanout pushed a commit to fkanout/kibana that referenced this pull request Mar 4, 2024
## Summary

Sync with elastic/elasticsearch#104958 for
support of builtin fn in STATS
  * validation ✅ 
  * autocomplete ✅ 
  * also fixed `STATS BY <field>` syntax


![new_stats](https://github.com/elastic/kibana/assets/924948/735f9842-b1d3-4aa0-9d51-4b2f9b136ed3)


Sync with elastic/elasticsearch#104913 for new
`log` function
  * validation ✅  - also warning for negative values
  * autocomplete ✅ 

![add_log](https://github.com/elastic/kibana/assets/924948/146b945d-a23b-45ec-9df2-2d2b291e883b)

Sync with elastic/elasticsearch#105064 for
removal of `PROJECT` command
  * validation ✅  (both new and legacy syntax supported)
  * autocomplete ✅  (will only suggest new syntax)


![remove_project](https://github.com/elastic/kibana/assets/924948/b6f40afe-a26d-4917-b7a1-d8ae97c5368b)

Sync with elastic/elasticsearch#105221 for
removal of mandatory brackets for `METADATA` command option
* validation ✅ (added warning deprecation message when using brackets)
  * autocomplete ✅ 

![fix_metadata](https://github.com/elastic/kibana/assets/924948/c65db176-dd94-45f3-9524-45453e62f51a)


Sync with elastic/elasticsearch#105224 for
change of syntax for ENRICH ccq mode
  * validation ✅ 
* autocomplete ✅ (not directly promoted, the user has to type `_` to
trigger it)
  * hover ✅ 
  * code actions ✅ 

![fix_ccq_enrich](https://github.com/elastic/kibana/assets/924948/0900edd9-a0a7-4ac8-bc12-e39a72359984)

![fix_ccq_enrich_2](https://github.com/elastic/kibana/assets/924948/74b0908f-d385-4723-b3d4-c09108f47a73)


Do not merge until those 5 get merged.

Additional things in this PR:
* Added more tests for `callbacks` not passed scenario
  * covered more cases like those with `dissect`
* Added more tests for signature params number (calling a function with
an extra arg should return an error)
* Cleaned up some more unused code
* Improved messages on too many arguments for functions

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/ES|QL AKA ESQL auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) ES|QL-ui Impacts ES|QL UI >non-issue Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v8.13.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants