[ES|QL] Use avg metric for AMD default metric#141331
Conversation
e768f1d to
1a810a6
Compare
This commit changes the behavior of the default metric for aggregate_metric_double in ES|QL to always use the average regardless of what the default metric is mapped to. Note that this avg is not the same as the average you would get if you ran `STATS avg(agg_metric)`, because the aformentioned is the average of all docs, but the avg metric is an average on a per-doc basis.
1a810a6 to
d594cb2
Compare
x-pack/plugin/esql/qa/testFixtures/src/main/resources/inlinestats.csv-spec
Outdated
Show resolved
Hide resolved
x-pack/plugin/esql/qa/testFixtures/src/main/resources/k8s-timeseries.csv-spec
Show resolved
Hide resolved
...in/java/org/elasticsearch/xpack/aggregatemetric/mapper/AggregateMetricDoubleBlockLoader.java
Outdated
Show resolved
Hide resolved
x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/40_tsdb.yml
Outdated
Show resolved
Hide resolved
|
Pinging @elastic/es-storage-engine (Team:StorageEngine) |
...in/java/org/elasticsearch/xpack/aggregatemetric/mapper/AggregateMetricDoubleBlockLoader.java
Outdated
Show resolved
Hide resolved
...in/java/org/elasticsearch/xpack/aggregatemetric/mapper/AggregateMetricDoubleBlockLoader.java
Outdated
Show resolved
Hide resolved
|
Hi @limotova, I've created a changelog YAML for you. |
gmarouli
left a comment
There was a problem hiding this comment.
Looks very promising, I added some questions that will help me better understand the code before I give the LGTM :)
...ugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/CsvTestsDataLoader.java
Outdated
Show resolved
Hide resolved
| return values; | ||
| } | ||
| var sortedValues = leafReader.getSortedNumericDocValues(fieldName); | ||
| return DocValues.unwrapSingleton(sortedValues); |
There was a problem hiding this comment.
I am not very familiar with the different doc values data structure, so it's not clear to me what we do here.
It looks like:
- We try to retrieve
leafReader.getNumericDocValues(fieldName)first, why is that? Which cases do we have where this is null? - Then if it's null, we move to
leafReader.getSortedNumericDocValues(fieldName), I was under the impression that we used only this before. - Then we
DocValues.unwrapSingleton(sortedValues), this method returnsnullif the doc values are not singleton, are we sure that this will always be a singleton?
Can you elaborate a little bit, if it's just me then I will learn something new, if we think it's very specific for this case we can add some comments.
There was a problem hiding this comment.
I don't really have any answers here - I don't know the specifics of this myself, iirc i think it usually goes through the null route (SortedNumericDocValues), but i believe this was how it was written in the very very first iteration and I didn't change it
I think @martijnvg might have a better understanding..?
...in/java/org/elasticsearch/xpack/aggregatemetric/mapper/AggregateMetricDoubleBlockLoader.java
Show resolved
Hide resolved
| NumericDocValues sumValues = getNumericDocValues(sumFieldType, context.reader()); | ||
| NumericDocValues valueCountValues = getNumericDocValues(countFieldType, context.reader()); |
There was a problem hiding this comment.
More context in comment, I was thinking something like that:
| NumericDocValues sumValues = getNumericDocValues(sumFieldType, context.reader()); | |
| NumericDocValues valueCountValues = getNumericDocValues(countFieldType, context.reader()); | |
| NumericDocValues sumValues = DocValues.getSortedNumeric(context.reader(), sumFieldType.name()); | |
| NumericDocValues valueCountValues = DocValues.getSortedNumeric(context.reader(), countFieldType.name()); |
...in/java/org/elasticsearch/xpack/aggregatemetric/mapper/AggregateMetricDoubleBlockLoader.java
Outdated
Show resolved
Hide resolved
...in/java/org/elasticsearch/xpack/aggregatemetric/mapper/AggregateMetricDoubleFieldMapper.java
Outdated
Show resolved
Hide resolved
…tra advanceExact call
...in/java/org/elasticsearch/xpack/aggregatemetric/mapper/AggregateMetricDoubleFieldMapper.java
Outdated
Show resolved
Hide resolved
This commit changes the behavior of the default metric for aggregate_metric_double in ES|QL to always use the average regardless of what the default metric is mapped to. Note that this avg is not the same as the average you would get if you ran `STATS avg(agg_metric)`, because the aforementioned is the average of all docs, but the avg metric is an average on a per-doc basis. Part of elastic#128356
This commit changes the behavior of the default metric for
aggregate_metric_double in ES|QL to always use the average regardless
of what the default metric is mapped to.
Note that this avg is not the same as the average you would get if you
ran
STATS avg(agg_metric), because the aforementioned is the averageof all docs, but the avg metric is an average on a per-doc basis.
Part of #128356