Skip to content

Commit

Permalink
fix(views): fix environment filter for views (datahub-project#11771)
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanHolstien authored Nov 7, 2024
1 parent 35a7a2a commit 33751bf
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public class ESUtils {
// top-level properties
// to field level properties
public static final Map<String, List<String>> FIELDS_TO_EXPANDED_FIELDS_LIST =
new HashMap<String, List<String>>() {
new HashMap<>() {
{
put("tags", ImmutableList.of("tags", "fieldTags", "editedFieldTags"));
put(
Expand All @@ -117,6 +117,8 @@ public class ESUtils {
put(
"businessAttribute",
ImmutableList.of("businessAttributeRef", "businessAttributeRef.urn"));
put("origin", ImmutableList.of("origin", "env"));
put("env", ImmutableList.of("env", "origin"));
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,86 @@ public void testGetQueryBuilderFromCriterionFieldToExpand() {
+ " }\n"
+ "}";
Assert.assertEquals(result.toString(), expected);

final Criterion originCriterion = buildCriterion("origin", Condition.EQUAL, "PROD");

// Ensure that the query is expanded!
QueryBuilder originExpanded =
ESUtils.getQueryBuilderFromCriterion(
originCriterion,
false,
new HashMap<>(),
mock(OperationContext.class),
QueryFilterRewriteChain.EMPTY);
String originExpected =
"{\n"
+ " \"bool\" : {\n"
+ " \"should\" : [\n"
+ " {\n"
+ " \"terms\" : {\n"
+ " \"origin.keyword\" : [\n"
+ " \"PROD\"\n"
+ " ],\n"
+ " \"boost\" : 1.0,\n"
+ " \"_name\" : \"origin\"\n"
+ " }\n"
+ " },\n"
+ " {\n"
+ " \"terms\" : {\n"
+ " \"env.keyword\" : [\n"
+ " \"PROD\"\n"
+ " ],\n"
+ " \"boost\" : 1.0,\n"
+ " \"_name\" : \"env\"\n"
+ " }\n"
+ " }\n"
+ " ],\n"
+ " \"adjust_pure_negative\" : true,\n"
+ " \"minimum_should_match\" : \"1\",\n"
+ " \"boost\" : 1.0\n"
+ " }\n"
+ "}";
Assert.assertEquals(originExpanded.toString(), originExpected);

final Criterion envCriterion = buildCriterion("env", Condition.EQUAL, "PROD");

// Ensure that the query is expanded!
QueryBuilder envExpanded =
ESUtils.getQueryBuilderFromCriterion(
envCriterion,
false,
new HashMap<>(),
mock(OperationContext.class),
QueryFilterRewriteChain.EMPTY);
String envExpected =
"{\n"
+ " \"bool\" : {\n"
+ " \"should\" : [\n"
+ " {\n"
+ " \"terms\" : {\n"
+ " \"env.keyword\" : [\n"
+ " \"PROD\"\n"
+ " ],\n"
+ " \"boost\" : 1.0,\n"
+ " \"_name\" : \"env\"\n"
+ " }\n"
+ " },\n"
+ " {\n"
+ " \"terms\" : {\n"
+ " \"origin.keyword\" : [\n"
+ " \"PROD\"\n"
+ " ],\n"
+ " \"boost\" : 1.0,\n"
+ " \"_name\" : \"origin\"\n"
+ " }\n"
+ " }\n"
+ " ],\n"
+ " \"adjust_pure_negative\" : true,\n"
+ " \"minimum_should_match\" : \"1\",\n"
+ " \"boost\" : 1.0\n"
+ " }\n"
+ "}";
Assert.assertEquals(envExpanded.toString(), envExpected);
}

@Test
Expand Down

0 comments on commit 33751bf

Please sign in to comment.