Skip to content

Commit 00b32d8

Browse files
authored
[ES|QL] Use describe method to generate OrdinalGroupingOperator profile message (#113150) (#113279)
* Use describe method to generate aggregators string * Improve message * remove incorrect query change
1 parent dd9da3d commit 00b32d8

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/OrdinalsGroupingOperator.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import java.util.Objects;
4747
import java.util.function.IntFunction;
4848
import java.util.function.Supplier;
49+
import java.util.stream.Collectors;
4950

5051
import static java.util.Objects.requireNonNull;
5152
import static java.util.stream.Collectors.joining;
@@ -325,7 +326,11 @@ private static void checkState(boolean condition, String msg) {
325326

326327
@Override
327328
public String toString() {
328-
return this.getClass().getSimpleName() + "[" + "aggregators=" + aggregatorFactories + "]";
329+
String aggregatorDescriptions = aggregatorFactories.stream()
330+
.map(factory -> "\"" + factory.describe() + "\"")
331+
.collect(Collectors.joining(", "));
332+
333+
return this.getClass().getSimpleName() + "[" + "aggregators=[" + aggregatorDescriptions + "]]";
329334
}
330335

331336
record SegmentID(int shardIndex, int segmentIndex) {

x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/RestEsqlIT.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,35 @@ public void testProfile() throws IOException {
323323
);
324324
}
325325

326+
public void testProfileOrdinalsGroupingOperator() throws IOException {
327+
indexTimestampData(1);
328+
329+
RequestObjectBuilder builder = requestObjectBuilder().query(fromIndex() + " | STATS AVG(value) BY test.keyword");
330+
builder.profile(true);
331+
if (Build.current().isSnapshot()) {
332+
// Lock to shard level partitioning, so we get consistent profile output
333+
builder.pragmas(Settings.builder().put("data_partitioning", "shard").build());
334+
}
335+
Map<String, Object> result = runEsql(builder);
336+
337+
List<List<String>> signatures = new ArrayList<>();
338+
@SuppressWarnings("unchecked")
339+
List<Map<String, Object>> profiles = (List<Map<String, Object>>) ((Map<String, Object>) result.get("profile")).get("drivers");
340+
for (Map<String, Object> p : profiles) {
341+
fixTypesOnProfile(p);
342+
assertThat(p, commonProfile());
343+
List<String> sig = new ArrayList<>();
344+
@SuppressWarnings("unchecked")
345+
List<Map<String, Object>> operators = (List<Map<String, Object>>) p.get("operators");
346+
for (Map<String, Object> o : operators) {
347+
sig.add((String) o.get("operator"));
348+
}
349+
signatures.add(sig);
350+
}
351+
352+
assertThat(signatures.get(0).get(2), equalTo("OrdinalsGroupingOperator[aggregators=[\"sum of longs\", \"count\"]]"));
353+
}
354+
326355
public void testInlineStatsProfile() throws IOException {
327356
assumeTrue("INLINESTATS only available on snapshots", Build.current().isSnapshot());
328357
indexTimestampData(1);

0 commit comments

Comments
 (0)