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

Added null check for ParentJoinFieldMapper #42997 #43360

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

Conversation

0xamogh
Copy link

@0xamogh 0xamogh commented Jun 19, 2019

Copy link
Contributor

@polyfractal polyfractal left a comment

Choose a reason for hiding this comment

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

Great, thanks @amogh-jrules! Left a comment about the change.

Would you be willing to add a unit test for this too, to make sure the unmapped case works as expected? I think ParentToChildrenAggregatorTests would be the right place to add a test. Let me know if you have questions, parent/child tests are a little more complicated than elsewhere. You may also need #43405 to merge first so that testing unmapped fields is a little easier.

Thanks again for the PR!

final SortedSetDVOrdinalsIndexFieldData fieldData = context.getForField(fieldType);
config.fieldContext(new FieldContext(fieldType.name(), fieldData, fieldType));
} else {
if(parentJoinFieldMapper != null){
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, let's see if we can un-nest the if conditional? Usually cleaner to read if they don't nest in my opinion. How about something like:

if (parentJoinFieldMapper == null) {
    config.unmapped(true);
    return;
}

ParentIdFieldMapper parentIdFieldMapper = parentJoinFieldMapper.getParentIdFieldMapper(childType, false);
if (parentIdFieldMapper == null) {
    config.unmapped(true);
    return;
}

And then after that point we know both fields are not null, so we can set the config outside of a conditional. Should flatten the whole thing a bit.

Copy link
Author

Choose a reason for hiding this comment

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

Alright, makes sense

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-analytics-geo

@0xamogh
Copy link
Author

0xamogh commented Jun 20, 2019

Great, thanks @amogh-jrules! Left a comment about the change.

Would you be willing to add a unit test for this too, to make sure the unmapped case works as expected? I think ParentToChildrenAggregatorTests would be the right place to add a test. Let me know if you have questions, parent/child tests are a little more complicated than elsewhere. You may also need #43405 to merge first so that testing unmapped fields is a little easier.

Thanks again for the PR!

Okay, I haven't done this before, I'll give it a shot, please help me out if I mess up

@polyfractal
Copy link
Contributor

No problem at all, here to help! Feel free to ping with questions, or push a work-in-progress and I can leave comments/suggestions.

@0xamogh
Copy link
Author

0xamogh commented Jun 22, 2019

Hey @polyfractal , I have flattened the if-else structure and added the commit. Also, I took a look at creating a unit test. I had 1 question though. In essence, what I have to do is create a new method in the ParentToChildrenAggregatorTests file which calls this particular case when parentIdFieldMapper is null. Is that correct? As in went through the file I couldn't quite find a method which calls .getMapper() method as in the file I changed

@polyfractal
Copy link
Contributor

Hey @amogh-jrules sorry for the delay, saw this and then forgot to reply.

In essence, what I have to do is create a new method in the ParentToChildrenAggregatorTests file which calls this particular case when parentIdFieldMapper is null. Is that correct?

I haven't looked super closely, but that sounds correct to me. You should be able to just set the field type to null (or pass in null directly). You can see the field type being passed in here. Setting this to null will tell the test that the field is unmapped.

You'll have to tweak the testCase() method to allow passing in a field type, similar to what was done in #43405 (adding another overload of testCase which accepts a field type)

@0xamogh
Copy link
Author

0xamogh commented Jun 28, 2019

Thanks for your reply, I'll get on it right away

@jpountz jpountz added v7.4.0 and removed v7.3.0 labels Jul 3, 2019
@elasticsearchmachine elasticsearchmachine changed the base branch from master to main July 22, 2022 23:14
@mark-vieira mark-vieira added v8.5.0 and removed v8.4.0 labels Jul 27, 2022
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytics-geo (Team:Analytics)

@elasticsearchmachine
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/Aggregations Aggregations >bug Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v8.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet