OpenSearch/x-pack/plugin/sql
Marios Trivyzas f373020349 SQL: Fix ORDER BY YEAR() function (#51562)
Previously, if YEAR() was used as and ORDER BY argument without being
wrapped with another scalar (e.g. YEAR(birth_date) + 10), no script
ordering was used but instead the underlying field (e.g. birth_date)
was used instead as a performance optimisation. This works correctly if
YEAR() is the only ORDER BY arg but if further args are used as tie
breakers for the ordering wrong results are produced. This is because
2 rows with the different birth_date but on the same year are not tied
as the underlying ordering is on birth_date and not on the
YEAR(birth_date), and the following ORDER BY args are ignored.

Remove this optimisation for YEAR() to avoid incorrect results in
such cases.

As a consequence another bug is revealed: scalar functions on top
of nested fields produce scripted sorting/filtering which is not yet
supported. In such cases no error was thrown but instead all values for
such nested fields were null and were passed to the script implementing
the sorting/filtering, producing incorrect results.

Detect such cases and throw a validation exception.

Fixes: #51224
(cherry picked from commit f41efd6753dc3650a7eabb3e07b02b3b32c5704c)
2020-01-30 15:29:36 +01:00
..
jdbc Handle NULL in ResultSet's getDate() method (#50184) 2019-12-17 10:03:23 +02:00
qa SQL: Fix ORDER BY YEAR() function (#51562) 2020-01-30 15:29:36 +01:00
sql-action SQL: add support for passing query parameters in REST API calls (#51029) (#51222) 2020-01-20 16:40:19 +02:00
sql-cli Apply 2-space indent to all gradle scripts (#49071) 2019-11-14 11:01:23 +00:00
sql-client Clean up static web server in sql-client tests (#49187) (#49197) 2019-11-15 13:02:21 -07:00
sql-proto QL: Backport project to 7.x (#51497) 2020-01-27 22:03:58 +02:00
src SQL: Fix ORDER BY YEAR() function (#51562) 2020-01-30 15:29:36 +01:00
build.gradle QL: Backport project to 7.x (#51497) 2020-01-27 22:03:58 +02:00