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

fix(java) Use alias for name search sorting and fix missing mappings #8648

Conversation

chriscollins3456
Copy link
Collaborator

There were two problems with our search sorting and this solves both of them.

  1. The simpler one: If an index didn't have a field that we were sorting by (such as lastOperationTime) ES would throw an error and not return any results from that index. Instead, we want to pretend like that field exists on the index but just not sort in it. This change is just adding unmappedType in ESUtils.java in our search request.

  2. We want to sort by entity name but unfortunately name isn't the name of the field in all elastic indices. So now i'm introducing a new concept to our SearchableAnnotation called fieldNameAliases which is an array of possible aliases for a given field. This sets the alias on the mapping so we can sort by it. The name alias is going to be _entityName to avoid any clashes with existing fields and now the frontend sorts on that.

Checklist

  • The PR conforms to DataHub's Contributing Guideline (particularly Commit Message Format)
  • Links to related issues (if applicable)
  • Tests for the changes have been added/updated (if applicable)
  • Docs related to the changes have been added/updated (if applicable). If a new feature has been added a Usage Guide has been added for the same.
  • For any breaking change/potential downtime/deprecation/big changes an entry has been made in Updating DataHub

Copy link
Contributor

@iprentic iprentic left a comment

Choose a reason for hiding this comment

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

Want to throw an aliased field on test-models/src/main/pegasus/com/datahub/test/TestEntityInfo.pdl and add a test to MappingsBuilderTest.java? I have an example in my ngrams PR: https://github.com/datahub-project/datahub/pull/8611/files#diff-fc3cb0e02650522d68bf55a60f21a6d6942f0e87c0e61234a8c20c518f62a41a

private static Map<String, Object> getMappingsForFieldNameAliases(@Nonnull final SearchableFieldSpec searchableFieldSpec) {
Map<String, Object> mappings = new HashMap<>();
List<String> fieldNameAliases = searchableFieldSpec.getSearchableAnnotation().getFieldNameAliases();
if (fieldNameAliases.size() > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

we technically don't need this check as it will just not execute anything if we call forEach on an empty list but I leave it up to you if you want to remove it!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yup that makes sense!

@chriscollins3456 chriscollins3456 merged commit a4cb81c into datahub-project:master Aug 23, 2023
54 of 55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
product PR or Issue related to the DataHub UI/UX
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants