diff --git a/dbms/src/Storages/StorageLiveView.cpp b/dbms/src/Storages/StorageLiveView.cpp index 77e95ac2e48..917d62baaa4 100644 --- a/dbms/src/Storages/StorageLiveView.cpp +++ b/dbms/src/Storages/StorageLiveView.cpp @@ -159,12 +159,25 @@ Block StorageLiveView::getHeader() const { if (!sample_block) { - auto storage = global_context.getTable(select_database_name, select_table_name); - sample_block = InterpreterSelectQuery(inner_query, global_context, storage).getSampleBlock(); - sample_block.insert({DataTypeUInt64().createColumnConst( - sample_block.rows(), 0)->convertToFullColumnIfConst(), - std::make_shared(), - "_version"}); + if (!(*blocks_ptr) || (*blocks_ptr)->empty()) + { + auto storage = global_context.getTable(select_database_name, select_table_name); + sample_block = InterpreterSelectQuery(inner_query, global_context, storage, SelectQueryOptions(QueryProcessingStage::Complete)).getSampleBlock(); + sample_block.insert({DataTypeUInt64().createColumnConst( + sample_block.rows(), 0)->convertToFullColumnIfConst(), + std::make_shared(), + "_version"}); + /// convert all columns to full columns + /// in case some of them are constant + for (size_t i = 0; i < sample_block.columns(); ++i) + { + sample_block.safeGetByPosition(i).column = sample_block.safeGetByPosition(i).column->convertToFullColumnIfConst(); + } + } + else + { + sample_block = (*blocks_ptr)->front().cloneEmpty(); + } } return sample_block; diff --git a/dbms/tests/queries/0_stateless/00958_live_view_watch_live.py b/dbms/tests/queries/0_stateless/00958_live_view_watch_live.py index cb6f1e95f7e..7cbea5fbff6 100755 --- a/dbms/tests/queries/0_stateless/00958_live_view_watch_live.py +++ b/dbms/tests/queries/0_stateless/00958_live_view_watch_live.py @@ -31,7 +31,7 @@ with client(name='client1>', log=log) as client1, client(name='client2>', log=lo client2.send('INSERT INTO test.mt VALUES (4),(5),(6)') client1.expect(r'21.*3' + end_of_block) # send Ctrl-C - os.kill(client1.process.pid,signal.SIGINT) + os.kill(client1.process.pid, signal.SIGINT) client1.expect(prompt) client1.send('DROP TABLE test.lv') client1.expect(prompt) diff --git a/dbms/tests/queries/0_stateless/00960_live_view_watch_events_live.py b/dbms/tests/queries/0_stateless/00960_live_view_watch_events_live.py index 414f9c1ad96..becf0335600 100755 --- a/dbms/tests/queries/0_stateless/00960_live_view_watch_events_live.py +++ b/dbms/tests/queries/0_stateless/00960_live_view_watch_events_live.py @@ -31,7 +31,7 @@ with client(name='client1>', log=log) as client1, client(name='client2>', log=lo client2.send('INSERT INTO test.mt VALUES (4),(5),(6)') client1.expect('3.*2186dbea325ee4c56b67e9b792e993a3' + end_of_block) # send Ctrl-C - os.kill(client1.process.pid,signal.SIGINT) + os.kill(client1.process.pid, signal.SIGINT) client1.expect(prompt) client1.send('DROP TABLE test.lv') client1.expect(prompt) diff --git a/dbms/tests/queries/0_stateless/00962_temporary_live_view_watch_live.py b/dbms/tests/queries/0_stateless/00962_temporary_live_view_watch_live.py index 1967284c38b..d4d35548d68 100755 --- a/dbms/tests/queries/0_stateless/00962_temporary_live_view_watch_live.py +++ b/dbms/tests/queries/0_stateless/00962_temporary_live_view_watch_live.py @@ -31,7 +31,7 @@ with client(name='client1>', log=log) as client1, client(name='client2>', log=lo client2.send('INSERT INTO test.mt VALUES (4),(5),(6)') client1.expect(r'21.*3' + end_of_block) # send Ctrl-C - os.kill(client1.process.pid,signal.SIGINT) + os.kill(client1.process.pid, signal.SIGINT) client1.expect(prompt) client1.send('DROP TABLE test.lv') client1.expect(prompt) diff --git a/dbms/tests/queries/0_stateless/00963_temporary_live_view_watch_live_timeout.py b/dbms/tests/queries/0_stateless/00963_temporary_live_view_watch_live_timeout.py index 581363cd796..2008368f12e 100755 --- a/dbms/tests/queries/0_stateless/00963_temporary_live_view_watch_live_timeout.py +++ b/dbms/tests/queries/0_stateless/00963_temporary_live_view_watch_live_timeout.py @@ -35,8 +35,8 @@ with client(name='client1>', log=log) as client1, client(name='client2>', log=lo client2.expect(prompt) client1.expect(r'21.*3' + end_of_block) # send Ctrl-C - os.kill(client1.process.pid,signal.SIGINT) - client1.expect(prompt, timeout=5) + os.kill(client1.process.pid, signal.SIGINT) + client1.expect(prompt) client1.send('SELECT sleep(1)') client1.expect(prompt) client1.send('DROP TABLE test.lv') diff --git a/dbms/tests/queries/0_stateless/00964_live_view_watch_events_heartbeat.py b/dbms/tests/queries/0_stateless/00964_live_view_watch_events_heartbeat.py index b624e0b7080..3ced5f6f315 100755 --- a/dbms/tests/queries/0_stateless/00964_live_view_watch_events_heartbeat.py +++ b/dbms/tests/queries/0_stateless/00964_live_view_watch_events_heartbeat.py @@ -33,7 +33,7 @@ with client(name='client1>', log=log) as client1, client(name='client2>', log=lo # wait for heartbeat client1.expect('Progress: 2.00 rows.*\)') # send Ctrl-C - os.kill(client1.process.pid,signal.SIGINT) + os.kill(client1.process.pid, signal.SIGINT) client1.expect(prompt) client1.send('DROP TABLE test.lv') client1.expect(prompt) diff --git a/dbms/tests/queries/0_stateless/00965_live_view_watch_heartbeat.py b/dbms/tests/queries/0_stateless/00965_live_view_watch_heartbeat.py index dfb46273f7c..b2bd84e0742 100755 --- a/dbms/tests/queries/0_stateless/00965_live_view_watch_heartbeat.py +++ b/dbms/tests/queries/0_stateless/00965_live_view_watch_heartbeat.py @@ -34,7 +34,7 @@ with client(name='client1>', log=log) as client1, client(name='client2>', log=lo # wait for heartbeat client1.expect('Progress: 2.00 rows.*\)') # send Ctrl-C - os.kill(client1.process.pid,signal.SIGINT) + os.kill(client1.process.pid, signal.SIGINT) client1.expect(prompt) client1.send('DROP TABLE test.lv') client1.expect(prompt)