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

ESQL: Improve verifier error for incorrect agg declaration #100650

Merged
merged 6 commits into from Oct 11, 2023

Conversation

costin
Copy link
Member

@costin costin commented Oct 11, 2023

Add specific check for aliased function declarations in stats

Fix #100641

Add specific check for aliased function declarations in stats

Fix elastic#100634
@costin costin added >bug auto-merge Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) auto-backport-and-merge Automatically create backport pull requests and merge when ready :Analytics/ES|QL AKA ESQL v8.11.1 v8.12.0 labels Oct 11, 2023
@costin costin requested review from nik9000, astefan, bpintea, alex-spies and luigidellaquila and removed request for nik9000 October 11, 2023 00:56
@elasticsearchmachine elasticsearchmachine added the Team:QL (Deprecated) Meta label for query languages team label Oct 11, 2023
@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-ql (Team:QL)

@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/elasticsearch-esql (:Query Languages/ES|QL)

@costin costin added ES|QL-ui Impacts ES|QL UI and removed auto-merge Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) labels Oct 11, 2023
@elasticsearchmachine
Copy link
Collaborator

Hi @costin, I've updated the changelog YAML for you.

@costin costin mentioned this pull request Oct 11, 2023
32 tasks
Copy link
Contributor

@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.

LGTM even though in some cases it could be misleading, eg ... | stats a = foo will result in incomplete aggregate function declaration; add parenthesis to [foo], and when the user tries to add the parentheses ... | stats a = foo() he will just get another error.
Maybe we could be more generic and just say invalid stats declaration; [{}] is not an aggregate function.

As a future evolution, we could also use the FunctionRegistry to suggest alternatives, like did you mean xyz()?

Copy link
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.

Imho, I believe we are too picky with the error messages improvements. Yes, we can do better in some situations but there will always be users who will complain about the message.
And @luigidellaquila's example is very good in pointing out another of these edge situations where we could do better.

Another one is stats c = avg(, where one could argue that the language should have a better error message than no viable alternative at input 'avg(' (ie "why isn't the language telling me that I should add another parenthesis?").

In any case, the improvement in this PR is welcomed, BUT I suggest incorporating the fix that @luigidellaquila mentioned in this PR not in a new one.

@@ -89,6 +91,19 @@ Collection<Failure> verify(LogicalPlan plan) {
else if (p.resolved()) {
return;
}
// handle aggregate first to disambiguate between missing fields or incorrect function declaration
if (p instanceof Aggregate aggregate) {
for (NamedExpression agg : aggregate.aggregates()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we maybe consolidate this with the verification happening below in lines 125/140? Now we're verifying aggs in two places.

Copy link
Member Author

Choose a reason for hiding this comment

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

There are different types of verifications - the first one is around unknown fields the other around resolved fields but incorrectly declared.

@costin costin merged commit 3636d3d into elastic:main Oct 11, 2023
3 of 13 checks passed
@costin costin deleted the fix/100634 branch October 11, 2023 23:46
costin added a commit to costin/elasticsearch that referenced this pull request Oct 11, 2023
…00650)

Add specific check for aliased function declarations in stats

Fix elastic#100634
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.11

elasticsearchmachine pushed a commit that referenced this pull request Oct 12, 2023
…100738)

Add specific check for aliased function declarations in stats

Fix #100634
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-and-merge Automatically create backport pull requests and merge when ready >bug ES|QL-ui Impacts ES|QL UI Team:QL (Deprecated) Meta label for query languages team v8.11.1 v8.12.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ESQL: Better error message for agg functions without brackets
5 participants