-
Notifications
You must be signed in to change notification settings - Fork 3k
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
feat(search): add filter for specific entities #7919
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ef3d8c1
feat(search): add filter for specific entities
03ff4de
add transformation to all functions, and add test where only one filt…
7b8b031
fix checkstyle
8cb8012
Merge branch 'master' into entityFilter
iprentic 838dd03
Break up stream party
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
...ta-io/src/test/java/com/linkedin/metadata/search/elasticsearch/query/ESSearchDAOTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package com.linkedin.metadata.search.elasticsearch.query; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.linkedin.data.template.StringArray; | ||
import com.linkedin.metadata.ESSampleDataFixture; | ||
import com.linkedin.metadata.query.filter.Condition; | ||
import com.linkedin.metadata.query.filter.ConjunctiveCriterion; | ||
import com.linkedin.metadata.query.filter.ConjunctiveCriterionArray; | ||
import com.linkedin.metadata.query.filter.CriterionArray; | ||
import com.linkedin.metadata.query.filter.Filter; | ||
import com.linkedin.metadata.utils.elasticsearch.IndexConvention; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; | ||
import org.testng.annotations.Test; | ||
|
||
import com.linkedin.metadata.query.filter.Criterion; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
|
||
import static org.testng.Assert.*; | ||
|
||
|
||
@Import(ESSampleDataFixture.class) | ||
public class ESSearchDAOTest extends AbstractTestNGSpringContextTests { | ||
@Autowired | ||
@Qualifier("sampleDataIndexConvention") | ||
IndexConvention indexConvention; | ||
|
||
@Test | ||
public void testTransformFilterForEntitiesNoChange() { | ||
Criterion c = new Criterion().setValue("urn:li:tag:abc").setValues( | ||
new StringArray(ImmutableList.of("urn:li:tag:abc", "urn:li:tag:def")) | ||
).setNegated(false).setCondition(Condition.EQUAL).setField("tags.keyword"); | ||
|
||
Filter f = new Filter().setOr( | ||
new ConjunctiveCriterionArray(new ConjunctiveCriterion().setAnd(new CriterionArray(c)))); | ||
|
||
Filter transformedFilter = ESSearchDAO.transformFilterForEntities(f, indexConvention); | ||
assertEquals(f, transformedFilter); | ||
} | ||
|
||
@Test | ||
public void testTransformFilterForEntitiesNullFilter() { | ||
Filter transformedFilter = ESSearchDAO.transformFilterForEntities(null, indexConvention); | ||
assertNotNull(indexConvention); | ||
assertEquals(null, transformedFilter); | ||
} | ||
|
||
@Test | ||
public void testTransformFilterForEntitiesWithChanges() { | ||
|
||
Criterion c = new Criterion().setValue("dataset").setValues( | ||
new StringArray(ImmutableList.of("dataset")) | ||
).setNegated(false).setCondition(Condition.EQUAL).setField("_entityType"); | ||
|
||
Filter f = new Filter().setOr( | ||
new ConjunctiveCriterionArray(new ConjunctiveCriterion().setAnd(new CriterionArray(c)))); | ||
Filter originalF = null; | ||
try { | ||
originalF = f.copy(); | ||
} catch (CloneNotSupportedException e) { | ||
fail(e.getMessage()); | ||
} | ||
assertEquals(f, originalF); | ||
|
||
Filter transformedFilter = ESSearchDAO.transformFilterForEntities(f, indexConvention); | ||
assertNotEquals(originalF, transformedFilter); | ||
|
||
Criterion expectedNewCriterion = new Criterion().setValue("smpldat_datasetindex_v2").setValues( | ||
new StringArray(ImmutableList.of("smpldat_datasetindex_v2")) | ||
).setNegated(false).setCondition(Condition.EQUAL).setField("_index"); | ||
|
||
Filter expectedNewFilter = new Filter().setOr( | ||
new ConjunctiveCriterionArray(new ConjunctiveCriterion().setAnd(new CriterionArray(expectedNewCriterion)))); | ||
|
||
assertEquals(expectedNewFilter, transformedFilter); | ||
} | ||
|
||
@Test | ||
public void testTransformFilterForEntitiesWithSomeChanges() { | ||
|
||
Criterion criterionChanged = new Criterion().setValue("dataset").setValues( | ||
new StringArray(ImmutableList.of("dataset")) | ||
).setNegated(false).setCondition(Condition.EQUAL).setField("_entityType"); | ||
Criterion criterionUnchanged = new Criterion().setValue("urn:li:tag:abc").setValues( | ||
new StringArray(ImmutableList.of("urn:li:tag:abc", "urn:li:tag:def")) | ||
).setNegated(false).setCondition(Condition.EQUAL).setField("tags.keyword"); | ||
|
||
Filter f = new Filter().setOr( | ||
new ConjunctiveCriterionArray(new ConjunctiveCriterion().setAnd(new CriterionArray(criterionChanged, criterionUnchanged)))); | ||
Filter originalF = null; | ||
try { | ||
originalF = f.copy(); | ||
} catch (CloneNotSupportedException e) { | ||
fail(e.getMessage()); | ||
} | ||
assertEquals(f, originalF); | ||
|
||
Filter transformedFilter = ESSearchDAO.transformFilterForEntities(f, indexConvention); | ||
assertNotEquals(originalF, transformedFilter); | ||
|
||
Criterion expectedNewCriterion = new Criterion().setValue("smpldat_datasetindex_v2").setValues( | ||
new StringArray(ImmutableList.of("smpldat_datasetindex_v2")) | ||
).setNegated(false).setCondition(Condition.EQUAL).setField("_index"); | ||
|
||
Filter expectedNewFilter = new Filter().setOr( | ||
new ConjunctiveCriterionArray(new ConjunctiveCriterion().setAnd(new CriterionArray(expectedNewCriterion, criterionUnchanged)))); | ||
|
||
assertEquals(expectedNewFilter, transformedFilter); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this need to be static? Without it being static you don't need to pass in the indexConvention method param
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't need to be, but it seemed easier to test this way...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, yeah you can just new up the ESSearchDAO like is done here: https://github.com/datahub-project/datahub/blob/master/metadata-io/src/test/java/com/linkedin/metadata/ESSampleDataFixture.java#L99
(or convert this to a bean definition and wire it in instead of just the IndexConvention)