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

SQL: Perform lazy evaluation of mismatched mappings #35676

Merged
merged 2 commits into from Nov 21, 2018

Conversation

costin
Copy link
Member

@costin costin commented Nov 17, 2018

Move away from performing eager, fail-fast validation of mismatched
mapping to a lazy evaluation based on the fields actually used in the
query. This allows queries to run on the parts of the indices that
"work" which is not just convenient but also a necessity for large
mappings (like logging) where alignment is hard/impossible to achieve.

Fix #35659

Note this PR picked up uses #35675 until it gets merged into master (see the first commit) - it's the second commit which is relevant.

@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search-aggs

@costin
Copy link
Member Author

costin commented Nov 17, 2018

/cc @alexfrancoeur @elastic/kibana-canvas

@costin
Copy link
Member Author

costin commented Nov 17, 2018

retest this please

Move away from performing eager, fail-fast validation of mismatched
 mapping to a lazy evaluation based on the fields actually used in the
 query. This allows queries to run on the parts of the indices that
 "work" which is not just convenient but also a necessity for large
 mappings (like logging) where alignment is hard/impossible to achieve.

Fix elastic#35659
Copy link
Contributor

@matriv matriv left a comment

Choose a reason for hiding this comment

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

Looks good, left 2 comments.

public boolean equals(Object obj) {
if (super.equals(obj)) {
InvalidMappedField other = (InvalidMappedField) obj;
return Objects.equals(errorMessage, other.errorMessage);
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor, but If the objects are equal (this == other) we don't need to check, on the other hand might be ugly to implement completely the super.equals here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, that's why the call to the equals above.

}
FieldCapabilities parentCap = map.values().iterator().next();
parent = createField(parentName, globalCaps, hierarchicalMapping, flattedMapping,
s -> createField(s, parentCap.getType(), new TreeMap<>(), parentCap.isAggregatable()));
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe I'm overlooking something, but why do you need a new TreeMap here, Collections.emptyMap() won't work?

Copy link
Member Author

Choose a reason for hiding this comment

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

The map is used for the properties of the parent; a treeMap is used since the children need to be sorted out alphabetically. The field caps does not return fields in order anymore and thus this needs to be maintained internally.
emptyMap is still used for fields that do not have children but the call above is for a parent (which by definition has).

Copy link
Contributor

Choose a reason for hiding this comment

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

got it, thx!

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.

LGTM. Left one (more cosmetic) comment.

errorMessage.append("[" + indexPattern + "] points to indices with incompatible mappings: ");
errorMessage.append("field [" + name + "] is aggregateable except in ");
errorMessage.append(Arrays.toString(fieldCap.nonAggregatableIndices()));
errorMessage.insert(0, "mapped as [" + types.size() + "] incompatible types: ");
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand the need to use types.size() as it can be of large values when multiple indices are resolved and used in a query, but would you consider at least for smaller size values - like 1,2,3 - to use the word instead? (one, two, three)

Copy link
Member Author

Choose a reason for hiding this comment

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

How would that work? First 1 should never appear so it's about 2, 3 (or whatever limit) and the rest.
This means the message can be "mapped as [three] incompatible types" vs "mapped as [5] incompatible types" since we don't have any utility to convert the numbers into words.
Further more words are never used instead of numbers in any error message that I can think of plus it decreases the readability of the message imo - [5] is shorter and more concise than [five] which arguably should not have the [, ] around.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's fair. All good

Copy link
Contributor

@matriv matriv left a comment

Choose a reason for hiding this comment

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

LGTM

@costin costin merged commit 03f0037 into elastic:master Nov 21, 2018
@costin costin deleted the fix-35659 branch November 21, 2018 15:35
@rashidkpc
Copy link

Wooooooooo

costin added a commit that referenced this pull request Nov 21, 2018
Move away from performing eager, fail-fast validation of mismatched
 mapping to a lazy evaluation based on the fields actually used in the
 query. This allows queries to run on the parts of the indices that
 "work" which is not just convenient but also a necessity for large
 mappings (like logging) where alignment is hard/impossible to achieve.

Fix #35659

(cherry picked from commit 03f0037)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants