def test_watch_live_view_sum(self, started_cluster, node, source): command = " ".join(node.client.command) args = dict(log=log, command=command) with client(name="client1> ", **args) as client1, client(name="client2> ", **args) as client2: client1.expect(prompt) client2.expect(prompt) client1.send("SET allow_experimental_live_view = 1") client1.expect(prompt) client2.send("SET allow_experimental_live_view = 1") client2.expect(prompt) client1.send("DROP TABLE IF EXISTS lv") client1.expect(prompt) client1.send( "CREATE LIVE VIEW lv AS SELECT sum(value) FROM distributed_table" ) client1.expect(prompt) client1.send("WATCH lv") client1.expect(r"22.*1" + end_of_block) client2.send( "INSERT INTO distributed_table VALUES ('node1', 2, 2)") client2.expect(prompt) client1.expect(r"24.*2" + end_of_block) client2.send( "INSERT INTO distributed_table VALUES ('node1', 3, 3), ('node1', 4, 4)" ) client2.expect(prompt) client1.expect(r"31.*3" + end_of_block)
def test_distributed_over_live_view_group_by_key(self, started_cluster, node, source): log = sys.stdout node0, node1 = NODES.values() select_query = "SELECT key, SUM(value) FROM distributed_over_lv GROUP BY key ORDER BY key FORMAT CSV" with client(name="client1> ", log=log, command=" ".join(node0.client.command)) as client1, \ client(name="client2> ", log=log, command=" ".join(node1.client.command)) as client2: client1.expect(prompt) client2.expect(prompt) client1.send("DROP TABLE IF EXISTS distributed_over_lv") client1.expect(prompt) client1.send( "CREATE TABLE distributed_over_lv AS lv_over_base_table ENGINE = Distributed(test_cluster, default, lv_over_base_table)" ) client1.expect(prompt) client1.send(select_query) client1.expect('0,10') client1.expect('1,12') client1.expect(prompt) client2.send( "INSERT INTO distributed_table VALUES ('node1', 2, 2)") client2.expect(prompt) poll_query(node0, "SELECT count() FROM (%s)" % select_query.rsplit("FORMAT")[0], "3\n", timeout=60) client1.send(select_query) client1.expect('0,10') client1.expect('1,12') client1.expect('2,2') client1.expect(prompt) client2.send( "INSERT INTO distributed_table VALUES ('node1', 1, 3), ('node1', 3, 3)" ) client2.expect(prompt) poll_query(node0, "SELECT count() FROM (%s)" % select_query.rsplit("FORMAT")[0], "4\n", timeout=60) client1.send(select_query) client1.expect('0,10') client1.expect('1,15') client1.expect('2,2') client1.expect('3,3') client1.expect(prompt)
def test_distributed_over_live_view_order_by_node(self, started_cluster, node, source): log = sys.stdout node0, node1 = NODES.values() select_query = "SELECT * FROM distributed_over_lv ORDER BY node, key FORMAT CSV" select_query_dist_table = "SELECT * FROM distributed_table ORDER BY node, key FORMAT CSV" select_count_query = "SELECT count() FROM distributed_over_lv" with client(name="client1> ", log=log, command=" ".join(node0.client.command)) as client1, \ client(name="client2> ", log=log, command=" ".join(node1.client.command)) as client2: client1.expect(prompt) client2.expect(prompt) client1.send("DROP TABLE IF EXISTS distributed_over_lv") client1.expect(prompt) client1.send( "CREATE TABLE distributed_over_lv AS lv_over_base_table ENGINE = Distributed(test_cluster, default, lv_over_base_table)" ) client1.expect(prompt) client1.send(select_query) client1.expect('"node1",0,0') client1.expect('"node1",1,1') client1.expect('"node2",0,10') client1.expect('"node2",1,11') client1.expect(prompt) client1.send( "INSERT INTO distributed_table VALUES ('node1', 1, 3), ('node1', 2, 3)" ) client1.expect(prompt) client2.send( "INSERT INTO distributed_table VALUES ('node1', 3, 3)") client2.expect(prompt) poll_query(node0, select_count_query, "7\n", timeout=60) print("\n--DEBUG1--") print(select_query) print(node0.query(select_query)) print("---------") print("\n--DEBUG2--") print(select_query_dist_table) print(node0.query(select_query_dist_table)) print("---------") client1.send(select_query) client1.expect('"node1",0,0') client1.expect('"node1",1,1') client1.expect('"node1",1,3') client1.expect('"node1",2,3') client1.expect('"node1",3,3') client1.expect('"node2",0,10') client1.expect('"node2",1,11') client1.expect(prompt)
def test_distributed_over_live_view_group_by_node(self, started_cluster, node, source): log = sys.stdout node0, node1 = NODES.values() select_query = "SELECT node, SUM(value) FROM distributed_over_lv GROUP BY node ORDER BY node FORMAT CSV" with client(name="client1> ", log=log, command=" ".join(node0.client.command)) as client1, \ client(name="client2> ", log=log, command=" ".join(node1.client.command)) as client2: client1.expect(prompt) client2.expect(prompt) client1.send("DROP TABLE IF EXISTS distributed_over_lv") client1.expect(prompt) client1.send( "CREATE TABLE distributed_over_lv AS lv_over_base_table ENGINE = Distributed(test_cluster, default, lv_over_base_table)" ) client1.expect(prompt) client1.send(select_query) client1.expect('"node1",1') client1.expect('"node2",21') client1.expect(prompt) client2.send( "INSERT INTO distributed_table VALUES ('node1', 2, 2)") client2.expect(prompt) poll_query(node0, select_query, '"node1",3\n"node2",21\n', timeout=60) client1.send(select_query) client1.expect('"node1",3') client1.expect('"node2",21') client1.expect(prompt) client1.send( "INSERT INTO distributed_table VALUES ('node1', 1, 3), ('node1', 3, 3)" ) client1.expect(prompt) client2.send( "INSERT INTO distributed_table VALUES ('node1', 3, 3)") client2.expect(prompt) poll_query(node0, select_query, '"node1",12\n"node2",21\n', timeout=60) client1.send(select_query) client1.expect('"node1",12') client1.expect('"node2",21') client1.expect(prompt)
def test_watch_live_view_order_by_node(self, started_cluster, node, source): log = sys.stdout command = " ".join(node.client.command) args = dict(log=log, command=command) with client(name="client1> ", **args) as client1, client(name="client2> ", **args) as client2: client1.expect(prompt) client2.expect(prompt) client1.send("SET allow_experimental_live_view = 1") client1.expect(prompt) client2.send("SET allow_experimental_live_view = 1") client2.expect(prompt) client1.send("DROP TABLE IF EXISTS lv") client1.expect(prompt) client1.send( "CREATE LIVE VIEW lv AS SELECT * FROM distributed_table ORDER BY node, key" ) client1.expect(prompt) client1.send("WATCH lv FORMAT CSV") client1.expect('"node1",0,0,1') client1.expect('"node1",1,1,1') client1.expect('"node2",0,10,1') client1.expect('"node2",1,11,1') client2.send( "INSERT INTO distributed_table VALUES ('node1', 2, 2)") client2.expect(prompt) client1.expect('"node1",0,0,2') client1.expect('"node1",1,1,2') client1.expect('"node1",2,2,2') client1.expect('"node2",0,10,2') client1.expect('"node2",1,11,2') client2.send( "INSERT INTO distributed_table VALUES ('node1', 0, 3), ('node3', 3, 3)" ) client2.expect(prompt) client1.expect('"node1",0,0,3') client1.expect('"node1",0,3,3') client1.expect('"node1",1,1,3') client1.expect('"node1",2,2,3') client1.expect('"node2",0,10,3') client1.expect('"node2",1,11,3') client1.expect('"node3",3,3,3')
def test_distributed_over_live_view_order_by_key(self, started_cluster, node, source): log = sys.stdout node0, node1 = NODES.values() select_query = "SELECT * FROM distributed_over_lv ORDER BY key, node FORMAT CSV" with client(name="client1> ", log=log, command=" ".join(node0.client.command)) as client1, \ client(name="client2> ", log=log, command=" ".join(node1.client.command)) as client2: client1.expect(prompt) client2.expect(prompt) client1.send("DROP TABLE IF EXISTS distributed_over_lv") client1.expect(prompt) client1.send( "CREATE TABLE distributed_over_lv AS lv_over_base_table ENGINE = Distributed(test_cluster, default, lv_over_base_table)" ) client1.expect(prompt) client1.send(select_query) client1.expect('"node1",0,0') client1.expect('"node2",0,10') client1.expect('"node1",1,1') client1.expect('"node2",1,11') client1.expect(prompt) client1.send( "INSERT INTO distributed_table VALUES ('node1', 1, 3), ('node1', 2, 3)" ) client1.expect(prompt) client2.send( "INSERT INTO distributed_table VALUES ('node1', 3, 3)") client2.expect(prompt) time.sleep(2) client1.send(select_query) client1.expect('"node1",0,0') client1.expect('"node2",0,10') client1.expect('"node1",1,1') client1.expect('"node1",1,3') client1.expect('"node2",1,11') client1.expect('"node1",2,3') client1.expect('"node1",3,3') client1.expect(prompt)
def test_watch_live_view_group_by_key(self, started_cluster, node, source): log = sys.stdout command = " ".join(node.client.command) args = dict(log=log, command=command) sep = ' \xe2\x94\x82' with client(name="client1> ", **args) as client1, client(name="client2> ", **args) as client2: client1.expect(prompt) client2.expect(prompt) client1.send("SET allow_experimental_live_view = 1") client1.expect(prompt) client2.send("SET allow_experimental_live_view = 1") client2.expect(prompt) client1.send("DROP TABLE IF EXISTS lv") client1.expect(prompt) client1.send( "CREATE LIVE VIEW lv AS SELECT key, SUM(value) FROM distributed_table GROUP BY key ORDER BY key" ) client1.expect(prompt) client1.send("WATCH lv FORMAT CSV") client1.expect('0,10,1') client1.expect('1,12,1') client2.send( "INSERT INTO distributed_table VALUES ('node1', 2, 2)") client2.expect(prompt) client1.expect('0,10,2') client1.expect('1,12,2') client1.expect('2,2,2') client2.send( "INSERT INTO distributed_table VALUES ('node1', 0, 3), ('node1', 3, 3)" ) client2.expect(prompt) client1.expect('0,13,3') client1.expect('1,12,3') client1.expect('2,2,3') client1.expect('3,3,3')
def test_distributed_over_live_view_sum(self, started_cluster, node, source): log = sys.stdout node0, node1 = NODES.values() with client(name="client1> ", log=log, command=" ".join(node0.client.command)) as client1, \ client(name="client2> ", log=log, command=" ".join(node1.client.command)) as client2: client1.expect(prompt) client2.expect(prompt) client1.send("DROP TABLE IF EXISTS distributed_over_lv") client1.expect(prompt) client1.send( "CREATE TABLE distributed_over_lv AS lv_over_base_table ENGINE = Distributed(test_cluster, default, lv_over_base_table)" ) client1.expect(prompt) client1.send("SELECT sum(value) FROM distributed_over_lv") client1.expect(r"22" + end_of_block) client1.expect(prompt) client2.send( "INSERT INTO distributed_table VALUES ('node1', 2, 2)") client2.expect(prompt) time.sleep(2) client1.send("SELECT sum(value) FROM distributed_over_lv") client1.expect(r"24" + end_of_block) client1.expect(prompt) client2.send( "INSERT INTO distributed_table VALUES ('node1', 3, 3), ('node1', 4, 4)" ) client2.expect(prompt) time.sleep(2) client1.send("SELECT sum(value) FROM distributed_over_lv") client1.expect(r"31" + end_of_block) client1.expect(prompt)
def test_distributed_over_live_view_group_by_key(self, started_cluster, node, source): log = sys.stdout node0, node1 = NODES.values() select_query = "SELECT key, SUM(value) FROM distributed_over_lv GROUP BY key ORDER BY key FORMAT CSV" with client(name="client1> ", log=log, command=" ".join(node0.client.command)) as client1, \ client(name="client2> ", log=log, command=" ".join(node1.client.command)) as client2: client1.expect(prompt) client2.expect(prompt) client1.send("DROP TABLE IF EXISTS distributed_over_lv") client1.expect(prompt) client1.send( "CREATE TABLE distributed_over_lv AS lv_over_base_table ENGINE = Distributed(test_cluster, default, lv_over_base_table)" ) client1.expect(prompt) client1.send(select_query) client1.expect("0,10\r\n1,12\r\n") client1.expect(prompt) client2.send( "INSERT INTO distributed_table VALUES ('node1', 2, 2)") client2.expect(prompt) time.sleep(2) client1.send(select_query) client1.expect("0,10\r\n1,12\r\n2,2\r\n") client1.expect(prompt) client2.send( "INSERT INTO distributed_table VALUES ('node1', 1, 3), ('node1', 3, 3)" ) client2.expect(prompt) time.sleep(2) client1.send(select_query) client1.expect("0,10\r\n.*1,15\r\n.*2,2\r\n.*3,3\r\n") client1.expect(prompt)