Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve metric types in top_metrics #53288

Merged
merged 7 commits into from
Mar 11, 2020

Conversation

nik9000
Copy link
Member

@nik9000 nik9000 commented Mar 9, 2020

This changes the top_metrics aggregation to return metrics in their
original type. Since it only supports numerics, that means that dates,
longs, and doubles will come back as stored, with their appropriate
formatter applied.

This changes the `top_metrics` aggregation to return metrics in their
original type. Since it only supports numerics, that means that dates,
longs, and doubles will come back as stored, with their appropriate
formatter applied.
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-analytics-geo (:Analytics/Aggregations)

@@ -217,14 +218,14 @@ TopMetric topMetric() {
TopMetric(StreamInput in) throws IOException {
sortFormat = in.readNamedWriteable(DocValueFormat.class);
sortValue = in.readNamedWriteable(SortValue.class);
metricValues = in.readDoubleArray();
metricValues = in.readList(s -> s.readOptionalWriteable(MetricValue::new));
Copy link
Member Author

Choose a reason for hiding this comment

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

Again, we haven't released this so this break is ok.


static class MetricValue implements Writeable, ToXContent {
private final DocValueFormat format;
private final SortValue value;
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm aware it is odd to have a "SortValue" be part of a MetricValue. It is a very convenient way to send a type-aware thing across the wire though.

Copy link
Member

Choose a reason for hiding this comment

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

I think this would be better as an inline comment than a PR comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

Copy link
Member

@not-napoleon not-napoleon left a comment

Choose a reason for hiding this comment

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

LGTM, left a couple of small nits.


static class MetricValue implements Writeable, ToXContent {
private final DocValueFormat format;
private final SortValue value;
Copy link
Member

Choose a reason for hiding this comment

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

I think this would be better as an inline comment than a PR comment.

/**
* Tracks "missing" values in a {@link BitArray}. Unlike
* {@link DoubleMetricValues}, we there isn't a sentinel value
* that we can steel from the longs to represent missing that
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* that we can steel from the longs to represent missing that
* that we can steal from the longs to represent missing that

@nik9000
Copy link
Member Author

nik9000 commented Mar 10, 2020

Thanks @not-napoleon! I think @polyfractal said he was looking at this so I'll probably give him some more time before merging.

Copy link
Contributor

@polyfractal polyfractal left a comment

Choose a reason for hiding this comment

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

Had a quick skim, LGTM2.

We might want to add the new "supported type" tests at some point... but since it was designed for single-type aggs it'll probably need some fiddling and I don't want to hold up this PR for that. 👍

@@ -234,12 +309,13 @@ public void swap(long lhs, long rhs) {
@Override
public Loader loader(LeafReaderContext ctx) throws IOException {
// TODO allow configuration of value mode
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we put an info blurb somewhere in the docs that multi-valued fields will be averaged together?

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably! I'd planned to give the docs another pass in the next PR.

@nik9000 nik9000 merged commit 8410356 into elastic:master Mar 11, 2020
nik9000 added a commit to nik9000/elasticsearch that referenced this pull request Mar 11, 2020
This changes the `top_metrics` aggregation to return metrics in their
original type. Since it only supports numerics, that means that dates,
longs, and doubles will come back as stored, with their appropriate
formatter applied.
nik9000 added a commit that referenced this pull request Mar 12, 2020
This changes the `top_metrics` aggregation to return metrics in their
original type. Since it only supports numerics, that means that dates,
longs, and doubles will come back as stored, with their appropriate
formatter applied.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants