Skip to content

ESQL: Fix attribute set equals #118823

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

Merged
merged 6 commits into from
Dec 19, 2024

Conversation

alex-spies
Copy link
Contributor

AttributeSet.equals was made so that one set was never ever equal to another; because we used the underlying AttributeMap and delegated to AttributeMap.equals, which requires equal classes first and foremost.

Fix that, following the pattern from AttributeMap.equals.

And, while at it, let's add a test that uses this and checks that name ids from different LOOKUP JOIN commands do not overlap.

@alex-spies alex-spies added >bug auto-backport Automatically create backport pull requests when merged :Analytics/ES|QL AKA ESQL v9.0.0 v8.18.0 labels Dec 17, 2024
@alex-spies alex-spies requested review from costin and astefan December 17, 2024 09:20
@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Dec 17, 2024
@elasticsearchmachine
Copy link
Collaborator

Hi @alex-spies, I've created a changelog YAML for you.

@elasticsearchmachine
Copy link
Collaborator

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

@@ -2190,6 +2191,36 @@ public void testLookupJoinUnknownField() {
assertThat(e.getMessage(), containsString(errorMessage3 + "right side of join"));
}

public void testMultipleLookupJoinsGiveDifferentAttributes() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@craigtaverner , we were chatting about attributes obtained from different LOOKUP JOINs. This test demonstrates that they do the right thing!

Comment on lines +178 to +182
if (obj instanceof AttributeSet as) {
obj = as.delegate;
}

return delegate.equals(obj);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we expect it to ever be equal if object is not AttributeSet? If not, following could avoid reassigning the parameter

Suggested change
if (obj instanceof AttributeSet as) {
obj = as.delegate;
}
return delegate.equals(obj);
return obj instanceof AttributeSet as && Objects.equals(as.delegate, this.delegate);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I think your approach would be stricter and I'd write it like this if I was writing this from scratch.

However, that'd potentially rule previously equal sets to not be equal anymore, even though that probably never applied in reality. But we'd have to go and check. And this'd be inconsistent with AttributeMap, which also defers to delegate.equals even for instances of different classes.

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.

Thanks for catching this. LGTM

@alex-spies alex-spies added the auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Dec 18, 2024
@alex-spies
Copy link
Contributor Author

The serverless checks fail for a single, completely unrelated test failure (already tracked in https://github.com/elastic/elasticsearch-serverless/issues/3313), so I believe this is fine to merge regardless.

@alex-spies alex-spies merged commit 9cc6cd4 into elastic:main Dec 19, 2024
15 of 16 checks passed
@alex-spies alex-spies deleted the fix-attribute-set-equals branch December 19, 2024 09:22
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.x

alex-spies added a commit to alex-spies/elasticsearch that referenced this pull request Dec 19, 2024
Also add a test that uses this, for lookup join field attribute ids.
elasticsearchmachine pushed a commit that referenced this pull request Dec 19, 2024
Also add a test that uses this, for lookup join field attribute ids.
navarone-feekery pushed a commit to navarone-feekery/elasticsearch that referenced this pull request Dec 26, 2024
Also add a test that uses this, for lookup join field attribute ids.
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 auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) >bug 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.

4 participants