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

Support "_first" and "_last" ordering of missing values in composite aggs #76740

Conversation

Luegg
Copy link
Contributor

@Luegg Luegg commented Aug 20, 2021

Resolves #63523 and #34550

Extends the composite value source builders with a new missing_order parameter that additionally allows to always put missing buckets "first" or "last" independently of the sort order.

Example query:

{
  "size": 0,
  "_source": false,
  "aggregations": {
    "groupby": {
      "composite": {
        "size": 1000,
        "sources": [
          {
            "gen": {
              "terms": {
                "field": "gender",
                "missing_bucket": true,
                "missing_order": "first",
                "order": "asc"
              }
            }
          },
          {
            "lang": {
              "terms": {
                "field": "languages",
                "missing_bucket": true,
                "missing_order": "last",
                "order": "asc"
              }
            }
          }
        ]
      }
    }
  }
}

If missing_bucket is false or missing, the missing_order parameter will be ignored.

@Luegg Luegg changed the title Support _first and _last ordering for missing values in composite aggs Support "first" and "last" ordering of missing values in composite aggs Aug 20, 2021
@Luegg Luegg force-pushed the enhance/missingFirstLastInCompositeAggs branch 4 times, most recently from b937542 to 1d77b12 Compare August 20, 2021 14:35
@Luegg Luegg force-pushed the enhance/missingFirstLastInCompositeAggs branch from 1d77b12 to cfc69a6 Compare August 30, 2021 12:57
@Luegg Luegg force-pushed the enhance/missingFirstLastInCompositeAggs branch 2 times, most recently from 827f69f to e7db340 Compare August 30, 2021 14:48
@Luegg Luegg force-pushed the enhance/missingFirstLastInCompositeAggs branch 2 times, most recently from a13c500 to 53eecca Compare August 30, 2021 15:11
@Luegg Luegg force-pushed the enhance/missingFirstLastInCompositeAggs branch from 53eecca to 29d8b48 Compare August 30, 2021 16:04
@Luegg Luegg force-pushed the enhance/missingFirstLastInCompositeAggs branch from 29d8b48 to 3eabe92 Compare August 30, 2021 16:11
@Luegg Luegg requested a review from nik9000 August 31, 2021 08:49
@Luegg Luegg marked this pull request as ready for review August 31, 2021 08:49
@elasticmachine elasticmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Aug 31, 2021
@elasticmachine
Copy link
Collaborator

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

@Luegg Luegg changed the title Support "first" and "last" ordering of missing values in composite aggs Support "_first" and "_last" ordering of missing values in composite aggs Aug 31, 2021
Copy link
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

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

I think it's right though I'd do the BWC/backport differently.

@ywelsch and @not-napoleon have both recently looked more closely at this code than I have and might want to have a look too.

@@ -52,7 +53,11 @@
if (in.readBoolean()) {
this.userValueTypeHint = ValueType.readFromStream(in);
}
this.missingBucket = in.readBoolean();
if (in.getVersion().onOrAfter(Version.V_7_16_0)) {
Copy link
Member

Choose a reason for hiding this comment

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

I tend to set this to 8_0_0 when I introduce these changes so that CI runs the bwc tests before I merge. I'll prepare the backport PR and a separate PR to disable bwc. Once both pass i merged the disabling first, wait a bit, and merge the backport. Then merge a final thing to master to undo it. It's a bunch of work but it keeps the BWC tests running as long as possible.

Copy link
Contributor Author

@Luegg Luegg Sep 2, 2021

Choose a reason for hiding this comment

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

👍 The fact that all the bwc tests passed despite that I've been using 7.16 here also made me think that maybe I'm missing some tests. So I added some more rest tests and adjusted the versions.

@not-napoleon not-napoleon self-requested a review August 31, 2021 18:55
@Luegg Luegg added the auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Sep 13, 2021
@elasticsearchmachine elasticsearchmachine merged commit c62d8e2 into elastic:master Sep 13, 2021
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
7.x Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 76740

Luegg pushed a commit to Luegg/elasticsearch that referenced this pull request Sep 13, 2021
…aggs (elastic#76740)

* Support "first" and "last" ordering of missing values in composite aggs

* skip API compat tests for 7.16

* use proper versions for bwc

* use "missing_order" parameter instead of "missing"

* address review comments
# Conflicts:
#	server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesSourceBuilder.java
@Luegg Luegg deleted the enhance/missingFirstLastInCompositeAggs branch September 13, 2021 12:39
elasticsearchmachine pushed a commit that referenced this pull request Sep 13, 2021
…osite aggs (#76740) (#77620)

* Support "_first" and "_last" ordering of missing values in composite aggs (#76740)

* Support "first" and "last" ordering of missing values in composite aggs

* skip API compat tests for 7.16

* use proper versions for bwc

* use "missing_order" parameter instead of "missing"

* address review comments
# Conflicts:
#	server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeValuesSourceBuilder.java

* adjust versions for BWC
nik9000 added a commit that referenced this pull request Sep 13, 2021
They have started failing about 0.3% of the time each. And there are a
couple dozen of them so yay.

Relates to #77650 and probably #76740
nik9000 added a commit that referenced this pull request Sep 13, 2021
They have started failing about 0.3% of the time each. And there are a
couple dozen of them so yay.

Relates to #77650 and probably #76740
Luegg pushed a commit that referenced this pull request Sep 15, 2021
Follow up of #77650.

Looks like two issues caused occasional failures:

missingOrder has not been considered in InternalComposite.InternalBucket#compareKey
reverseMul has been ignored in one case in OrdinalValuesSource#compareInternal
The first problem has clearly been introduced by #76740 but the second point is more interesting. As far as I understand, this might have caused problems before but I couldn't find any according test failures in Gradle before yesterday.

In order to preclude further rare test failures I've run the whole CompositeAggregatorTests 3000 times and all tests turned green.
Luegg pushed a commit to Luegg/elasticsearch that referenced this pull request Sep 15, 2021
…77691)

Follow up of elastic#77650.

Looks like two issues caused occasional failures:

missingOrder has not been considered in InternalComposite.InternalBucket#compareKey
reverseMul has been ignored in one case in OrdinalValuesSource#compareInternal
The first problem has clearly been introduced by elastic#76740 but the second point is more interesting. As far as I understand, this might have caused problems before but I couldn't find any according test failures in Gradle before yesterday.

In order to preclude further rare test failures I've run the whole CompositeAggregatorTests 3000 times and all tests turned green.
# Conflicts:
#	server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/InternalComposite.java
Luegg pushed a commit to Luegg/elasticsearch that referenced this pull request Sep 15, 2021
elasticsearchmachine pushed a commit that referenced this pull request Sep 15, 2021
Follow up of #77650.

Looks like two issues caused occasional failures:

missingOrder has not been considered in InternalComposite.InternalBucket#compareKey
reverseMul has been ignored in one case in OrdinalValuesSource#compareInternal
The first problem has clearly been introduced by #76740 but the second point is more interesting. As far as I understand, this might have caused problems before but I couldn't find any according test failures in Gradle before yesterday.

In order to preclude further rare test failures I've run the whole CompositeAggregatorTests 3000 times and all tests turned green.
# Conflicts:
#	server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/InternalComposite.java
@Luegg
Copy link
Contributor Author

Luegg commented Sep 16, 2021

Closes #34221

@Luegg Luegg linked an issue Sep 16, 2021 that may be closed by this pull request
Luegg added a commit that referenced this pull request Sep 27, 2021
Documents the missing_order parameter for composite aggregations introduced in #76740
Luegg added a commit to Luegg/elasticsearch that referenced this pull request Sep 27, 2021
Documents the missing_order parameter for composite aggregations introduced in elastic#76740
elasticsearchmachine pushed a commit that referenced this pull request Sep 27, 2021
)

Documents the missing_order parameter for composite aggregations introduced in #76740
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Automatically create backport pull requests when merged auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) >enhancement Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v7.16.0 v8.0.0-beta1
Projects
None yet
7 participants