'How to execute "with" query locally in ClickHouse?

We meet a case in ClickHouse query which can be simplified as:

SET load_balancing='in_order';
WITH (
        SELECT hostName() AS h
        FROM system.one
    ) AS x
SELECT
    x,
    hostName() AS h,
    sum(1) AS pv
FROM cluster({cluster}, system.one)
GROUP BY
    x,
    h

we get result:

x h pv
cluster_s1_r1 cluster_s1_r1 1
cluster_s1_r1 cluster_s1_r2 1
cluster_s1_r1 cluster_s2_r1 1
cluster_s1_r1 cluster_s2_r2 1

what we want is to execute with query locally, the desired result:

x h pv
cluster_s1_r1 cluster_s1_r1 1
cluster_s1_r2 cluster_s1_r2 1
cluster_s2_r1 cluster_s2_r1 1
cluster_s2_r2 cluster_s2_r2 1

thanks all.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source