diff --git a/src/Databases/DatabaseOnDisk.cpp b/src/Databases/DatabaseOnDisk.cpp index 9f56b5f7676..f12009cef1a 100644 --- a/src/Databases/DatabaseOnDisk.cpp +++ b/src/Databases/DatabaseOnDisk.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -55,6 +56,9 @@ std::pair createTableFromAST( ast_create_query.attach = true; ast_create_query.setDatabase(database_name); + if (ast_create_query.select && ast_create_query.isView()) + ApplyWithSubqueryVisitor().visit(*ast_create_query.select); + if (ast_create_query.as_table_function) { const auto & factory = TableFunctionFactory::instance(); diff --git a/tests/clickhouse-test b/tests/clickhouse-test index 863e061085a..5f9ab01cdcc 100755 --- a/tests/clickhouse-test +++ b/tests/clickhouse-test @@ -116,7 +116,7 @@ def clickhouse_execute_http(base_args, query, timeout=30, settings=None, default def clickhouse_execute(base_args, query, timeout=30, settings=None): return clickhouse_execute_http(base_args, query, timeout, settings).strip() -def clickhouse_execute_json(base_args, query, timeout=30, settings=None): +def clickhouse_execute_json(base_args, query, timeout=60, settings=None): data = clickhouse_execute_http(base_args, query, timeout, settings, 'JSONEachRow') if not data: return None diff --git a/tests/integration/test_materialized_view_restart_server/__init__.py b/tests/integration/test_materialized_view_restart_server/__init__.py new file mode 100755 index 00000000000..e69de29bb2d diff --git a/tests/integration/test_materialized_view_restart_server/test.py b/tests/integration/test_materialized_view_restart_server/test.py new file mode 100755 index 00000000000..bfadec5136b --- /dev/null +++ b/tests/integration/test_materialized_view_restart_server/test.py @@ -0,0 +1,25 @@ +import pytest +from helpers.cluster import ClickHouseCluster + +cluster = ClickHouseCluster(__file__) +node = cluster.add_instance("node", stay_alive=True) + + +@pytest.fixture(scope="module") +def start_cluster(): + try: + cluster.start() + yield cluster + finally: + cluster.shutdown() + + +def test_materialized_view_with_subquery(start_cluster): + node.query("create table test (x UInt32) engine=TinyLog()") + node.query( + "create materialized view mv engine = TinyLog() as with subquery as (select * from test) select * from subquery" + ) + node.restart_clickhouse(kill=True) + node.query("insert into test select 1") + result = node.query("select * from mv") + assert int(result) == 1 diff --git a/tests/queries/0_stateless/00417_kill_query.sh b/tests/queries/0_stateless/00417_kill_query.sh index 28f03fc9c37..e40eb5c3f80 100755 --- a/tests/queries/0_stateless/00417_kill_query.sh +++ b/tests/queries/0_stateless/00417_kill_query.sh @@ -21,3 +21,5 @@ $CLICKHOUSE_CLIENT -q "KILL QUERY WHERE 0 ASYNC" $CLICKHOUSE_CLIENT -q "KILL QUERY WHERE 0 FORMAT TabSeparated" $CLICKHOUSE_CLIENT -q "KILL QUERY WHERE 0 SYNC FORMAT TabSeparated" $CLICKHOUSE_CLIENT -q "KILL QUERY WHERE 1 TEST" &>/dev/null + +clickhouse_test_wait_queries 60 diff --git a/tests/queries/0_stateless/02152_http_external_tables_memory_tracking.sh b/tests/queries/0_stateless/02152_http_external_tables_memory_tracking.sh index 44de0e15370..4132ac91ae4 100755 --- a/tests/queries/0_stateless/02152_http_external_tables_memory_tracking.sh +++ b/tests/queries/0_stateless/02152_http_external_tables_memory_tracking.sh @@ -23,7 +23,7 @@ function run_and_check() echo "Checking $*" # Run query with external table (implicit StorageMemory user) - $CLICKHOUSE_CURL -sS -F "s=@$tmp_file;" "$CLICKHOUSE_URL&s_structure=key+Int&query=SELECT+count()+FROM+s&memory_profiler_sample_probability=1&query_id=$query_id&$*" -o /dev/null + $CLICKHOUSE_CURL -sS -F "s=@$tmp_file;" "$CLICKHOUSE_URL&s_structure=key+Int&query=SELECT+count()+FROM+s&memory_profiler_sample_probability=1&max_untracked_memory=0&query_id=$query_id&$*" -o /dev/null ${CLICKHOUSE_CURL} -sS "${CLICKHOUSE_URL}" --data-binary @- <<<'SYSTEM FLUSH LOGS' diff --git a/utils/tests-visualizer/index.html b/utils/tests-visualizer/index.html index 13f8daaa151..00076f683fa 100644 --- a/utils/tests-visualizer/index.html +++ b/utils/tests-visualizer/index.html @@ -84,14 +84,14 @@ let render_data_query = ` SELECT groupArray([d, n, fail]) FROM ( SELECT n, check_start_time::Date - start_date AS d, max(test_status LIKE 'F%' OR test_status LIKE 'E%') AS fail - FROM "gh-data".checks + FROM "default".checks INNER JOIN ( SELECT test_name, toUInt16(rowNumberInAllBlocks()) AS n FROM ( SELECT DISTINCT test_name - FROM "gh-data".checks + FROM "default".checks WHERE match(test_name, '^\\d+_') AND check_name ILIKE '%stateless%' AND check_start_time > now() - INTERVAL 1 DAY ORDER BY test_name ) @@ -112,7 +112,7 @@ let test_names_query = ` SELECT test_name, toUInt16(rowNumberInAllBlocks()) AS n FROM ( SELECT DISTINCT test_name - FROM "gh-data".checks + FROM "default".checks WHERE match(test_name, '^\\d+_') AND check_name ILIKE '%stateless%' AND check_start_time > now() - INTERVAL 1 DAY ORDER BY test_name ) FORMAT JSONCompact`;