-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(adv search): two advanced search fixes (#6252)
* two advanced search fixes * another approach * adding unit tests * fixing checkstyle issue
- Loading branch information
1 parent
94fae0a
commit 228c10d
Showing
17 changed files
with
172 additions
and
21 deletions.
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
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
69 changes: 69 additions & 0 deletions
69
...-graphql-core/src/test/java/com/linkedin/datahub/graphql/resolvers/ResolverUtilsTest.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,69 @@ | ||
package com.linkedin.datahub.graphql.resolvers; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.linkedin.data.template.StringArray; | ||
import com.linkedin.datahub.graphql.QueryContext; | ||
import com.linkedin.datahub.graphql.TestUtils; | ||
import com.linkedin.datahub.graphql.generated.FacetFilterInput; | ||
import com.linkedin.datahub.graphql.generated.FilterOperator; | ||
import com.linkedin.metadata.query.filter.Condition; | ||
import com.linkedin.metadata.query.filter.Criterion; | ||
import graphql.schema.DataFetchingEnvironment; | ||
import junit.framework.TestCase; | ||
import org.testng.annotations.Test; | ||
import org.mockito.Mockito; | ||
|
||
import static com.linkedin.datahub.graphql.resolvers.ResolverUtils.*; | ||
|
||
|
||
public class ResolverUtilsTest extends TestCase { | ||
|
||
@Test | ||
public void testCriterionFromFilter() throws Exception { | ||
final DataFetchingEnvironment mockEnv = Mockito.mock(DataFetchingEnvironment.class); | ||
final QueryContext mockAllowContext = TestUtils.getMockAllowContext(); | ||
Mockito.when(mockEnv.getContext()).thenReturn(mockAllowContext); | ||
|
||
// this is the expected path | ||
Criterion valuesCriterion = criterionFromFilter( | ||
new FacetFilterInput( | ||
"tags", | ||
null, | ||
ImmutableList.of("urn:li:tag:abc", "urn:li:tag:def"), | ||
false, | ||
FilterOperator.EQUAL | ||
) | ||
); | ||
assertEquals(valuesCriterion, 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")); | ||
|
||
// this is the legacy pathway | ||
Criterion valueCriterion = criterionFromFilter( | ||
new FacetFilterInput( | ||
"tags", | ||
"urn:li:tag:abc", | ||
null, | ||
true, | ||
FilterOperator.EQUAL | ||
) | ||
); | ||
assertEquals(valueCriterion, new Criterion().setValue("urn:li:tag:abc").setValues( | ||
new StringArray(ImmutableList.of("urn:li:tag:abc")) | ||
).setNegated(true).setCondition(Condition.EQUAL).setField("tags.keyword")); | ||
|
||
// check that both being null doesn't cause a NPE. this should never happen except via API interaction | ||
Criterion doubleNullCriterion = criterionFromFilter( | ||
new FacetFilterInput( | ||
"tags", | ||
null, | ||
null, | ||
true, | ||
FilterOperator.EQUAL | ||
) | ||
); | ||
assertEquals(doubleNullCriterion, new Criterion().setValue("").setValues( | ||
new StringArray(ImmutableList.of()) | ||
).setNegated(true).setCondition(Condition.EQUAL).setField("tags.keyword")); | ||
} | ||
} |
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
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
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
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
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
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
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
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
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
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
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
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
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
45 changes: 45 additions & 0 deletions
45
metadata-utils/src/test/java/com/linkedin/metadata/utils/SearchUtilTest.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,45 @@ | ||
package com.linkedin.metadata.utils; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import com.linkedin.common.urn.Urn; | ||
import com.linkedin.metadata.search.FilterValue; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import org.testng.annotations.Test; | ||
|
||
import static org.testng.Assert.*; | ||
|
||
|
||
/** | ||
* Tests the capabilities of {@link EntityKeyUtils} | ||
*/ | ||
public class SearchUtilTest { | ||
|
||
@Test | ||
public void testConvertToFilters() throws Exception { | ||
Map<String, Long> aggregations = new HashMap<>(); | ||
aggregations.put("urn:li:tag:abc", 3L); | ||
aggregations.put("urn:li:tag:def", 0L); | ||
|
||
Set<String> filteredValues = ImmutableSet.of("urn:li:tag:def"); | ||
|
||
List<FilterValue> filters = | ||
SearchUtil.convertToFilters(aggregations, filteredValues); | ||
|
||
assertEquals(filters.get(0), new FilterValue() | ||
.setFiltered(false) | ||
.setValue("urn:li:tag:abc") | ||
.setEntity(Urn.createFromString("urn:li:tag:abc")) | ||
.setFacetCount(3L) | ||
); | ||
|
||
assertEquals(filters.get(1), new FilterValue() | ||
.setFiltered(true) | ||
.setValue("urn:li:tag:def") | ||
.setEntity(Urn.createFromString("urn:li:tag:def")) | ||
.setFacetCount(0L) | ||
); | ||
} | ||
} |