Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
dnhatn committed Oct 11, 2023
1 parent 5231a0f commit afdcf18
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -1188,6 +1189,39 @@ public void testGroupingMultiValueByOrdinals() {
}
}

public void testUnsupportedTypesOrdinalGrouping() {
assertAcked(
client().admin().indices().prepareCreate("index-1").setMapping("f1", "type=keyword", "f2", "type=keyword", "v", "type=long")
);
assertAcked(
client().admin().indices().prepareCreate("index-2").setMapping("f1", "type=object", "f2", "type=keyword", "v", "type=long")
);
Map<String, Long> groups = new HashMap<>();
int numDocs = randomIntBetween(10, 20);
for (int i = 0; i < numDocs; i++) {
String k = randomFrom("a", "b", "c");
long v = randomIntBetween(1, 10);
groups.merge(k, v, Long::sum);
groups.merge(null, v, Long::sum); // null group
client().prepareIndex("index-1").setSource("f1", k, "v", v).get();
client().prepareIndex("index-2").setSource("f2", k, "v", v).get();
}
client().admin().indices().prepareRefresh("index-1", "index-2").get();
for (String field : List.of("f1", "f2")) {
try (var resp = run("from index-1,index-2 | stats sum(v) by " + field)) {
Iterator<Iterator<Object>> values = resp.values();
Map<String, Long> actual = new HashMap<>();
while (values.hasNext()) {
Iterator<Object> row = values.next();
Long v = (Long) row.next();
String k = (String) row.next();
actual.put(k, v);
}
assertThat(actual, equalTo(groups));
}
}
}

private void createNestedMappingIndex(String indexName) throws IOException {
XContentBuilder builder = JsonXContent.contentBuilder();
builder.startObject();
Expand Down

0 comments on commit afdcf18

Please sign in to comment.