ddl_check_query(instance,"DROP DATABASE IF EXISTS default ON CLUSTER cluster{}".format(cluster_num))
ddl_check_query(instance,"CREATE DATABASE IF NOT EXISTS default ON CLUSTER cluster{}".format(cluster_num))
ddl_check_query(instance,"CREATE TABLE hits ON CLUSTER cluster0 (d UInt64, d1 UInt64 MATERIALIZED d+1) ENGINE=ReplicatedMergeTree('/clickhouse/tables/cluster_{cluster}/{shard}/hits', '{replica}') PARTITION BY d % 3 ORDER BY d SETTINGS index_granularity = 16")
ddl_check_query(instance,"DROP DATABASE IF EXISTS default ON CLUSTER cluster{}".format(cluster_num))
ddl_check_query(instance,"CREATE DATABASE IF NOT EXISTS default ON CLUSTER cluster{}".format(cluster_num))
ddl_check_query(instance,"CREATE TABLE a ON CLUSTER cluster0 (date Date, d UInt64, d1 UInt64 ALIAS d+1) ENGINE=ReplicatedMergeTree('/clickhouse/tables/cluster_{cluster}/{shard}/a', '{replica}', date, intHash64(d), (date, intHash64(d)), 8192)")
ddl_check_query(instance,"CREATE TABLE a_all ON CLUSTER cluster0 (date Date, d UInt64) ENGINE=Distributed(cluster0, default, a, d)")
instance.query("INSERT INTO a_all SELECT toDate(17581 + number) AS date, number AS d FROM system.numbers LIMIT 85",settings={"insert_distributed_sync":1})
defcheck(self):
assertTSV(self.cluster.instances['s0_0_0'].query("SELECT count() FROM cluster(cluster0, default, a)"))==TSV("85\n")
assertTSV(self.cluster.instances['s1_0_0'].query("SELECT count(), uniqExact(date) FROM cluster(cluster1, default, b)"))==TSV("85\t85\n")
assertTSV(self.cluster.instances['s1_0_0'].query("SELECT DISTINCT d % 2 FROM b"))==TSV("1\n")
assertTSV(self.cluster.instances['s1_1_0'].query("SELECT DISTINCT d % 2 FROM b"))==TSV("0\n")
assertTSV(self.cluster.instances['s1_0_0'].query("SELECT uniqExact(partition) IN (12, 13) FROM system.parts WHERE active AND database='default' AND table='b'"))==TSV("1\n")
assertTSV(self.cluster.instances['s1_1_0'].query("SELECT uniqExact(partition) IN (12, 13) FROM system.parts WHERE active AND database='default' AND table='b'"))==TSV("1\n")
instance=cluster.instances['s0_0_0']
ddl_check_query(instance,"DROP TABLE a ON CLUSTER cluster0")
ddl_check_query(instance,"DROP TABLE b ON CLUSTER cluster1")