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

Smarter field caps with subscribable listener #116755

Merged
merged 37 commits into from
Dec 3, 2024

Conversation

astefan
Copy link
Contributor

@astefan astefan commented Nov 13, 2024

This change is two fold:

  • refactors EsqlSession to use (hopefully) a more readable and manageable series of async calls that start with pre-analysis of enrich policies, regular indices, lookup indices and end with verification of the analyzed logical plan of the query. It's changing the nested calls using ActionListeners to a "flat" series of steps using SubscribableListener
  • in case of VerificationException being thrown in the verification step (following the analysis of the logical plan) and given a REST request filter was used, it removes the filter and retries the analysis. Assuming the first call to IndexResolver using the filter (and implicitly to _field_caps call where the filter is being used, as well) fails, it's retries the _field_caps call without a filter.

There is a leftover task (to be addressed in a separate PR) that should add tests in CCS scenarios: #118054

Addresses #115053

@astefan
Copy link
Contributor Author

astefan commented Nov 13, 2024

@elasticmachine run elasticsearch-ci/part-2

@astefan
Copy link
Contributor Author

astefan commented Nov 13, 2024

@elasticmachine update branch

@astefan
Copy link
Contributor Author

astefan commented Nov 15, 2024

@dnhatn @original-brownbear asking for a double-checking of how I tried to use the SubscribableListener.
There is still something not right with my approach, given the tests that fail... one of them is about a VerificationException that is not thrown from the two-three places in this PR where I catch them (while calling analyzeAction.apply(indexResolution, enrichResolution)). I wasn't aware that specific exception is thrown from other places other than the Verifier. This proves to a degree that the way the listeners are chained and how they deal with this type of exception is not 100% correct.

@astefan
Copy link
Contributor Author

astefan commented Nov 21, 2024

@elasticmachine update branch

Comment on lines 634 to 659
class IndexResolutionWrappingListener implements ActionListener<EnrichResolution> {

private final ActionListener<Tuple<EnrichResolution, IndexResolution>> delegate;
private final IndexResolution indexResolution;

IndexResolutionWrappingListener(
ActionListener<Tuple<EnrichResolution, IndexResolution>> delegate,
IndexResolution indexResolution
) {
this.delegate = delegate;
this.indexResolution = indexResolution;
}

@Override
public void onResponse(EnrichResolution enrichResolution) {
delegate.onResponse(new Tuple<>(enrichResolution, indexResolution));
}

@Override
public void onFailure(Exception e) {
delegate.onFailure(e);
}
}

class EnrichResolutionWrappingListener implements ActionListener<IndexResolution> {

Copy link
Member

Choose a reason for hiding this comment

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

These two classes are very similar - use a base class with Generics to pass the parameter in.

// whatever tuple we have here (from CCS-special handling or from the original pre-analysis), pass it on to the next step
l.onResponse(tuple);
})
.<Tuple<EnrichResolution, IndexResolution>>andThen((l, tuple) -> {
Copy link
Member

Choose a reason for hiding this comment

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

👍
This style is more readable.
Furthermore I would extract the lambda in each stage in a separate method - it improves readability and avoids casts (inferred based on the method signature).

@elasticsearchmachine
Copy link
Collaborator

Hi @astefan, I've created a changelog YAML for you.

@astefan astefan marked this pull request as ready for review November 26, 2024 21:34
@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Nov 26, 2024
@elasticsearchmachine
Copy link
Collaborator

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

@astefan
Copy link
Contributor Author

astefan commented Nov 26, 2024

@astefan Would you mind updating the PR's description? I think I'm missing the context of the issue we're trying to solve. Thanks!

Sorry, @dnhatn, you're right. I've added tests, updated the description of the PR and marked as ready for review.

@astefan
Copy link
Contributor Author

astefan commented Nov 26, 2024

@elasticmachine run elasticsearch-ci/part-1

QueryBuilder requestFilter,
ListenerResult listenerResult,
ActionListener<ListenerResult> l,
ActionListener<LogicalPlan> logicalPlanListener
Copy link
Member

Choose a reason for hiding this comment

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

Passing and completing the logicalPlanListener within this method does not seem to integrate well into the chain, as it causes the chain to abruptly terminate. Ideally, the SubscribableListener should execute sequentially and asynchronously, block by block, until it encounters a failure. Could we implement retries within this block by calling the method again without a filter?

@astefan
Copy link
Contributor Author

astefan commented Dec 3, 2024

@elasticmachine run elasticsearch-ci/part-2

@astefan
Copy link
Contributor Author

astefan commented Dec 3, 2024

@elasticmachine update branch

@astefan astefan added the auto-backport Automatically create backport pull requests when merged label Dec 3, 2024
Copy link
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

@astefan astefan merged commit 22f4a79 into elastic:main Dec 3, 2024
16 checks passed
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
8.x Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 116755

@astefan astefan deleted the smarter_field_caps_subscribableListener branch December 3, 2024 18:11
@astefan astefan added the ES|QL-ui Impacts ES|QL UI label Dec 3, 2024
astefan added a commit to astefan/elasticsearch that referenced this pull request Dec 5, 2024
elasticsearchmachine pushed a commit that referenced this pull request Dec 5, 2024
* Smarter field caps with subscribable listener (#116755)

(cherry picked from commit 22f4a79)

* Create the mapping explicitly, otherwise for 0 documents indices (#118015)

the mapping will not contain the "value" field

(cherry picked from commit 774c6ea)
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-backport Automatically create backport pull requests when merged >enhancement ES|QL-ui Impacts ES|QL UI Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v8.18.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants