Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/changelog/138647.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 138647
summary: Run aggregations on aggregate metric double with default metric
area: ES|QL
type: feature
issues:
- 136297
Original file line number Diff line number Diff line change
Expand Up @@ -2120,6 +2120,7 @@ public BlockLoader blockLoader(BlockLoaderContext blContext) {
return switch (cfg.function()) {
case MV_MAX -> type.blockLoaderFromDocValuesMvMax(name());
case MV_MIN -> type.blockLoaderFromDocValuesMvMin(name());
case AMD_COUNT, AMD_DEFAULT, AMD_MAX, AMD_MIN, AMD_SUM -> type.blockLoaderFromDocValues(name());
default -> throw new UnsupportedOperationException("unknown fusion config [" + cfg.function() + "]");
};
}
Expand All @@ -2140,7 +2141,7 @@ public BlockLoader blockLoader(BlockLoaderContext blContext) {
public boolean supportsBlockLoaderConfig(BlockLoaderFunctionConfig config, FieldExtractPreference preference) {
if (hasDocValues() && (preference != FieldExtractPreference.STORED || isSyntheticSource)) {
return switch (config.function()) {
case MV_MAX, MV_MIN -> true;
case AMD_MIN, AMD_MAX, AMD_SUM, AMD_COUNT, AMD_DEFAULT, MV_MAX, MV_MIN -> true;
default -> false;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public int hashCode() {

enum Function {
AMD_COUNT,
AMD_DEFAULT,
AMD_MAX,
AMD_MIN,
AMD_SUM,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ public Block getMetricBlock(int index) {
@Override
public String toString() {
String valuesString = Stream.of(AggregateMetricDoubleBlockBuilder.Metric.values())
.filter(metric -> metric != AggregateMetricDoubleBlockBuilder.Metric.DEFAULT)
.map(metric -> metric.getLabel() + "=" + getMetricBlock(metric.getIndex()))
.collect(Collectors.joining(", ", "[", "]"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ public enum Metric {
MIN(0, "min"),
MAX(1, "max"),
SUM(2, "sum"),
COUNT(3, "value_count");
COUNT(3, "value_count"),
DEFAULT(4, "default");

private final int index;
private final String label;
Expand All @@ -210,6 +211,7 @@ public static Metric indexToMetric(int i) {
case 1 -> MAX;
case 2 -> SUM;
case 3 -> COUNT;
case 4 -> DEFAULT;
default -> null;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1138,3 +1138,59 @@ max_deriv:double | max_rate:double | time_bucket:date_nanos | cluster:keyword
16.0871 | 11.8608 | 2024-05-10T00:15:00.000Z | prod
10.2206 | 6.9807 | 2024-05-10T00:20:00.000Z | prod
;

DefaultMetricWithFrom
required_capability: ts_command_v0
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test doesn't use the TS command but tests with this capability only get run as EsqlSpecIT, and not as CSV tests, and I was running into issues running these tests through the CSV framework and did not think it was worth it to debug, so I added this capability.

required_capability: aggregate_metric_double_default_metric
FROM k8s-downsampled
| STATS max = max(network.eth0.tx), std_dev = ROUND(STD_DEV(network.eth0.tx), 7) by pod
| sort pod
;

max:double | std_dev:double | pod:keyword
1060.0 | 331.5018947 | one
824.0 | 151.9744943 | three
1419.0 | 364.4118888 | two
;

DefaultMetricWithTS
required_capability: ts_command_v0
required_capability: aggregate_metric_double_default_metric
TS k8s-downsampled
| STATS max = max(network.eth0.tx), std_dev = ROUND(STD_DEV(network.eth0.tx), 7) by pod
| sort pod
;

max:double | std_dev:double | pod:keyword
1060.0 | 355.3786713 | one
824.0 | 180.6918802 | three
815.0 | 102.3469046 | two
;

DefaultMetricWithFromImplicitCasting
required_capability: ts_command_v0
required_capability: aggregate_metric_double_default_metric
FROM k8s*
| STATS min = min(network.eth0.tx), std_dev = ROUND(STD_DEV(network.eth0.tx), 7) by pod
| sort pod
;

min:double | std_dev:double | pod:keyword
18.0 | 380.8643432 | one
48.0 | 340.5483293 | three
20.0 | 431.2070165 | two
;

DefaultMetricWithTSImplicitCasting
required_capability: ts_command_v0
required_capability: aggregate_metric_double_default_metric
TS k8s*
| STATS min = min(network.eth0.tx), std_dev = ROUND(STD_DEV(network.eth0.tx), 7) by pod
| sort pod
;

min:double | std_dev:double | pod:keyword
193.0 | 427.9853269 | one
715.0 | 208.6955678 | three
602.0 | 375.7757842 | two
;
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,11 @@ public enum Cap {
*/
AGGREGATE_METRIC_DOUBLE_V0,

/**
* Support running all aggregations on aggregate_metric_double using the default metric
*/
AGGREGATE_METRIC_DOUBLE_DEFAULT_METRIC,

/**
* Support change point detection "CHANGE_POINT".
*/
Expand Down
Loading