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

Fix bug 94733 geo_line not respecting sort_order #94734

Merged

Conversation

craigtaverner
Copy link
Contributor

Fixes bug where geo_line did not support sort_order, silently ignoring the DESC option.

The documentation for geo_line claims that the option sort_order can be either ASC (default) or DESC:

This option accepts one of two values: "ASC", "DESC".
The line is sorted in ascending order by the sort key when set to "ASC", and in descending with "DESC".

However, when testing this, no matter which you choose the actual order of points in the result is always ASC by the value of the sort field.

Fixes #94733

The original geo_line PR included two yaml test files, one of which
was never used. This commit moves that test into the correct place,
and fixes a syntax error in the test.
The code was re-sorting to ASC explicitly in the reduce phase.
No explanation was given. Removing this extra sort causes the
new yaml test to pass. Two failing java tests were fixed by no
longer explicitly expected ASC data when order was DESC.
@craigtaverner craigtaverner added >bug :Analytics/Geo Indexing, search aggregations of geo points and shapes Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v8.8.0 labels Mar 24, 2023
@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine
Copy link
Collaborator

Hi @craigtaverner, I've created a changelog YAML for you.

@craigtaverner
Copy link
Contributor Author

@elasticmachine run elasticsearch-ci/docs

@craigtaverner
Copy link
Contributor Author

The original PR that created geo_line aggregation and added the explicit sort, has a feature description claiming that sort_order: DESC is supported (gives this as the first example). However, that PR was created in April 2019, and only merged in Nov 2020 with 34 commits, so there is a lot of hidden history. It is hard to see what the reasoning was for deliberately killing this behaviour. The code that forces ASC on the sort says:

        // the final reduce should always be in ascending order
        if (reduceContext.isFinalReduce() && SortOrder.DESC.equals(sortOrder)) {
            new PathArraySorter(mergedGeoLines.getFinalPoints(), mergedGeoLines.getFinalSortValues(), SortOrder.ASC).sort();
        }

See #41612

@craigtaverner
Copy link
Contributor Author

craigtaverner commented Mar 27, 2023

I've found the commit that added the final sort. It has the commit message:

add size param

baaea0e#diff-cc94b6c97b605e29bde7bb31a0d4af9b1a368818e7261c48a34590c93195ee8e

My suspicion is that when implementing the size parameter he either found it did not work correctly without re-sorting, or he suspected it would not work correctly. Either way there are no tests that fail if we do not sort like this, so either the necessary tests were never written, or this sort is genuinely not required. I suspect the latter.

@craigtaverner
Copy link
Contributor Author

The kibana team feel that this was not done for Kibana reasons. The most likely remaining reason was that it was something done during the work on add size param. My suspicion was that it was an unnecessary change based on a misunderstanding. Quite possibly a temporary situation during development. In any case as long as we have tests that assert correct behaviour of the combination of size and sort_order we should be good. I will verify and add any missing tests.

Copy link
Contributor

@iverase iverase left a comment

Choose a reason for hiding this comment

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

LGTM

@craigtaverner craigtaverner merged commit e5f03ad into elastic:main Mar 28, 2023
@craigtaverner craigtaverner deleted the fix94733_geo_line_sort_order branch March 28, 2023 15:26
saarikabhasi pushed a commit to saarikabhasi/elasticsearch that referenced this pull request Apr 10, 2023
* Move unused geoline tests into correct location

The original geo_line PR included two yaml test files, one of which
was never used. This commit moves that test into the correct place,
and fixes a syntax error in the test.

* Fix geo_line sort order (elastic#94733)

The code was re-sorting to ASC explicitly in the reduce phase.
No explanation was given. Removing this extra sort causes the
new yaml test to pass. Two failing java tests were fixed by no
longer explicitly expected ASC data when order was DESC.

* Update docs/changelog/94734.yaml

* Improve changelog text

* Added test for size in geo_line

* Add geo_line sort and limit test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/Geo Indexing, search aggregations of geo points and shapes >bug Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v8.8.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When running geo_line aggregation, the sort_order has no effect
3 participants