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

Extract references tracking from SearchLookup #68202

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

romseygeek
Copy link
Contributor

@romseygeek romseygeek commented Jan 29, 2021

Reference tracking for field lookups during a script call will be needed for
calculated fields, and may also be useful for things like alias lookups in
future. This commit extracts it from SearchLookup into a dedicated
TrackingMappedFieldLookup class.

@romseygeek romseygeek self-assigned this Jan 29, 2021
@romseygeek romseygeek marked this pull request as draft January 29, 2021 10:59
@romseygeek romseygeek changed the title SearchLookup should track references automatically Extract references tracking from SearchLookup Jan 29, 2021
throw new IllegalArgumentException("Field requires resolving too many dependent fields: " + String.join(" -> ", newFieldChain));
}
return new SearchLookup(this, newFieldChain);
public SearchLookup forkAndTrackReferences(String field) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had hoped to be able to remove this method entirely, but we need it in runtime field queries if we want the root of the field cycle to be reported accurately. In other words, without this method we still get errors thrown on cycles, but instead of being "field -> a -> b -> field" the cycle is reported as "a -> b -> field -> a". I'm not sure if this is a real problem or not - it's a perfectly good cycle detection wherever it starts from. I lean towards removing it anyway, as I think the additional API surface isn't worth the different error message.

Copy link
Member

Choose a reason for hiding this comment

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

I kind of like the error message being accurate. Could we drop the API and have the queries make TrackingMappedFieldsLookup and immediate call the method to add themselves to its list?

protected final void checkLoop(BiConsumer<MappedFieldType, SearchExecutionContext> queryBuilder) {
Exception e = expectThrows(IllegalArgumentException.class, () -> queryBuilder.accept(loopFieldType(), mockContext()));
protected final void checkLoop(BiFunction<MappedFieldType, SearchExecutionContext, Query> queryBuilder) throws IOException {
Query query = queryBuilder.apply(loopFieldType(), mockContext(true, loopFieldType()));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This wasn't really checking an actual production code path before. We now run a search, which forces the script to look up values triggering the loop handling.

return ft.rangeQuery(randomLong(), randomLong(), randomBoolean(), randomBoolean(), null, null, null, ctx);
long lower = randomLongBetween(0, 1000);
long upper = lower + randomLongBetween(5, 5000);
return ft.rangeQuery(lower, upper, randomBoolean(), randomBoolean(), null, null, null, ctx);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because we're actually executing the random query now, we need to ensure its parameter constraints are met.

@romseygeek romseygeek added :Search/Search Search-related issues that do not fall into other categories >refactoring v7.12.0 v8.0.0 labels Jan 29, 2021
@romseygeek romseygeek marked this pull request as ready for review January 29, 2021 16:01
@elasticmachine elasticmachine added the Team:Search Meta label for search team label Jan 29, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (Team:Search)

}
}

public TrackingMappedFieldsLookup excludingField(String field) {
Copy link
Member

Choose a reason for hiding this comment

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

It doesn't really exclude the field, right? It tracks it?

throw new IllegalArgumentException("Field requires resolving too many dependent fields: " + String.join(" -> ", newFieldChain));
}
return new SearchLookup(this, newFieldChain);
public SearchLookup forkAndTrackReferences(String field) {
Copy link
Member

Choose a reason for hiding this comment

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

I kind of like the error message being accurate. Could we drop the API and have the queries make TrackingMappedFieldsLookup and immediate call the method to add themselves to its list?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>refactoring :Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team v7.13.5 v8.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet