|
21 | 21 |
|
22 | 22 | import java.io.IOException;
|
23 | 23 | import java.time.Instant;
|
24 |
| -import java.util.Arrays; |
25 |
| -import java.util.Collections; |
26 |
| -import java.util.HashMap; |
27 |
| -import java.util.HashSet; |
28 | 24 | import java.util.List;
|
29 | 25 | import java.util.Map;
|
30 | 26 | import java.util.Set;
|
@@ -63,7 +59,7 @@ protected boolean preserveIndicesUponCompletion() {
|
63 | 59 | @Before
|
64 | 60 | public void createIndexes() throws IOException {
|
65 | 61 | setupDataAccessRole(DATA_ACCESS_ROLE, REVIEWS_INDEX_NAME);
|
66 |
| - setupUser(TEST_USER_NAME, Arrays.asList("transform_admin", DATA_ACCESS_ROLE)); |
| 62 | + setupUser(TEST_USER_NAME, List.of("transform_admin", DATA_ACCESS_ROLE)); |
67 | 63 |
|
68 | 64 | // it's not possible to run it as @BeforeClass as clients aren't initialized then, so we need this little hack
|
69 | 65 | if (indicesCreated) {
|
@@ -894,6 +890,15 @@ public void testPivotWithTermsAgg() throws Exception {
|
894 | 890 | }
|
895 | 891 | }
|
896 | 892 | },
|
| 893 | + "common_users_desc": { |
| 894 | + "terms": { |
| 895 | + "field": "user_id", |
| 896 | + "size": 3, |
| 897 | + "order": { |
| 898 | + "_key": "desc" |
| 899 | + } |
| 900 | + } |
| 901 | + }, |
897 | 902 | "rare_users": {
|
898 | 903 | "rare_terms": {
|
899 | 904 | "field": "user_id"
|
@@ -922,33 +927,32 @@ public void testPivotWithTermsAgg() throws Exception {
|
922 | 927 | "hits.hits._source.common_users",
|
923 | 928 | searchResult
|
924 | 929 | )).get(0);
|
| 930 | + assertThat(commonUsers, is(not(nullValue()))); |
| 931 | + assertThat( |
| 932 | + commonUsers, |
| 933 | + equalTo( |
| 934 | + Map.of( |
| 935 | + "user_10", |
| 936 | + Map.of("common_businesses", Map.of("business_12", 6, "business_9", 4)), |
| 937 | + "user_0", |
| 938 | + Map.of("common_businesses", Map.of("business_0", 35)) |
| 939 | + ) |
| 940 | + ) |
| 941 | + ); |
| 942 | + Map<String, Integer> commonUsersDesc = (Map<String, Integer>) ((List<?>) XContentMapValues.extractValue( |
| 943 | + "hits.hits._source.common_users_desc", |
| 944 | + searchResult |
| 945 | + )).get(0); |
| 946 | + assertThat(commonUsersDesc, is(not(nullValue()))); |
| 947 | + // 3 user names latest in lexicographic order (user_7, user_8, user_9) are selected properly but their order is not preserved. |
| 948 | + // See https://github.com/elastic/elasticsearch/issues/104847 for more information. |
| 949 | + assertThat(commonUsersDesc, equalTo(Map.of("user_7", 6, "user_9", 2, "user_8", 8))); |
925 | 950 | Map<String, Integer> rareUsers = (Map<String, Integer>) ((List<?>) XContentMapValues.extractValue(
|
926 | 951 | "hits.hits._source.rare_users",
|
927 | 952 | searchResult
|
928 | 953 | )).get(0);
|
929 |
| - assertThat(commonUsers, is(not(nullValue()))); |
930 |
| - assertThat(commonUsers, equalTo(new HashMap<>() { |
931 |
| - { |
932 |
| - put("user_10", Collections.singletonMap("common_businesses", new HashMap<>() { |
933 |
| - { |
934 |
| - put("business_12", 6); |
935 |
| - put("business_9", 4); |
936 |
| - } |
937 |
| - })); |
938 |
| - put("user_0", Collections.singletonMap("common_businesses", new HashMap<>() { |
939 |
| - { |
940 |
| - put("business_0", 35); |
941 |
| - } |
942 |
| - })); |
943 |
| - } |
944 |
| - })); |
945 | 954 | assertThat(rareUsers, is(not(nullValue())));
|
946 |
| - assertThat(rareUsers, equalTo(new HashMap<>() { |
947 |
| - { |
948 |
| - put("user_5", 1); |
949 |
| - put("user_12", 1); |
950 |
| - } |
951 |
| - })); |
| 955 | + assertThat(rareUsers, is(equalTo(Map.of("user_5", 1, "user_12", 1)))); |
952 | 956 | }
|
953 | 957 |
|
954 | 958 | private void assertDateHistogramPivot(String indexName) throws Exception {
|
@@ -1184,8 +1188,8 @@ private void testPreviewTransform(String queryJson) throws Exception {
|
1184 | 1188 | List<Map<String, Object>> preview = (List<Map<String, Object>>) previewTransformResponse.get("preview");
|
1185 | 1189 | // preview is limited to 100
|
1186 | 1190 | assertThat(preview.size(), equalTo(100));
|
1187 |
| - Set<String> expectedTopLevelFields = new HashSet<>(Arrays.asList("user", "by_day")); |
1188 |
| - Set<String> expectedNestedFields = new HashSet<>(Arrays.asList("id", "avg_rating")); |
| 1191 | + Set<String> expectedTopLevelFields = Set.of("user", "by_day"); |
| 1192 | + Set<String> expectedNestedFields = Set.of("id", "avg_rating"); |
1189 | 1193 | preview.forEach(p -> {
|
1190 | 1194 | Set<String> keys = p.keySet();
|
1191 | 1195 | assertThat(keys, equalTo(expectedTopLevelFields));
|
@@ -1255,8 +1259,8 @@ public void testPreviewTransformWithPipeline() throws Exception {
|
1255 | 1259 | List<Map<String, Object>> preview = (List<Map<String, Object>>) previewTransformResponse.get("preview");
|
1256 | 1260 | // preview is limited to 100
|
1257 | 1261 | assertThat(preview.size(), equalTo(100));
|
1258 |
| - Set<String> expectedTopLevelFields = new HashSet<>(Arrays.asList("user", "by_day", "pipeline_field")); |
1259 |
| - Set<String> expectedNestedFields = new HashSet<>(Arrays.asList("id", "avg_rating")); |
| 1262 | + Set<String> expectedTopLevelFields = Set.of("user", "by_day", "pipeline_field"); |
| 1263 | + Set<String> expectedNestedFields = Set.of("id", "avg_rating"); |
1260 | 1264 | preview.forEach(p -> {
|
1261 | 1265 | Set<String> keys = p.keySet();
|
1262 | 1266 | assertThat(keys, equalTo(expectedTopLevelFields));
|
|
0 commit comments