ClickHouse/tests/queries/0_stateless/02281_limit_by_distributed.sql
Azat Khuzhin c6ffec1fec Fix "Cannot find column" error for distributed queries with LIMIT BY
Consider the following example:

    SELECT k FROM (SELECT materialize('foo') AS k, -1 AS v) ORDER BY abs(v) AS _v ASC LIMIT 1 BY k

The problem here is that in case of query has LIMIT BY for
WithMergeableState* (which is the final state on the remote shard for
distributd queries) it returns the following columns:
- k
- v

While it should return:
- k
- abs(v)

So as query w/o LIMIT BY, so that initiator will be able to do the sorting

Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
2022-04-20 15:23:24 +03:00

9 lines
174 B
SQL

SELECT k
FROM (
SELECT k, abs(v) AS _v
FROM remote('127.{1,2}', view(select materialize('foo') as k, -1 as v))
ORDER BY _v ASC
LIMIT 1 BY k
)
GROUP BY k;