From 1d44977ae21d8dab8d0d32f775bb2e583cdcbe53 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Fri, 3 Jan 2020 01:45:39 +0300 Subject: [PATCH 1/4] Avoid SIGSEGV on CREATE TABLE .. AS dictionary --- dbms/src/Interpreters/InterpreterCreateQuery.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/dbms/src/Interpreters/InterpreterCreateQuery.cpp b/dbms/src/Interpreters/InterpreterCreateQuery.cpp index f9e60e6e6e7..59ae2ada1df 100644 --- a/dbms/src/Interpreters/InterpreterCreateQuery.cpp +++ b/dbms/src/Interpreters/InterpreterCreateQuery.cpp @@ -524,6 +524,11 @@ void InterpreterCreateQuery::setEngine(ASTCreateQuery & create) const "Cannot CREATE a table AS " + as_database_name + "." + as_table_name + ", it is a Live View", ErrorCodes::INCORRECT_QUERY); + if (as_create.is_dictionary) + throw Exception( + "Cannot CREATE a table AS " + as_database_name + "." + as_table_name + ", it is a Dictionary", + ErrorCodes::INCORRECT_QUERY); + create.set(create.storage, as_create.storage->ptr()); } } From 487a05fae4294fd34e588ed560a1883f057f21b5 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Fri, 3 Jan 2020 01:48:28 +0300 Subject: [PATCH 2/4] Cover CREATE TABLE AS table/view/live-view/dictionary --- .../01056_create_table_as.reference | 0 .../0_stateless/01056_create_table_as.sql | 29 +++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 dbms/tests/queries/0_stateless/01056_create_table_as.reference create mode 100644 dbms/tests/queries/0_stateless/01056_create_table_as.sql diff --git a/dbms/tests/queries/0_stateless/01056_create_table_as.reference b/dbms/tests/queries/0_stateless/01056_create_table_as.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/dbms/tests/queries/0_stateless/01056_create_table_as.sql b/dbms/tests/queries/0_stateless/01056_create_table_as.sql new file mode 100644 index 00000000000..8646c978372 --- /dev/null +++ b/dbms/tests/queries/0_stateless/01056_create_table_as.sql @@ -0,0 +1,29 @@ +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (key Int) Engine=Memory(); +CREATE TABLE t2 AS t1; + +-- live view +SET allow_experimental_live_view=1; +CREATE LIVE VIEW v AS SELECT * FROM t1; +CREATE TABLE t3 AS v; -- { serverError 80; } + +-- view +CREATE VIEW lv AS SELECT * FROM t1; +CREATE TABLE t3 AS lv; -- { serverError 80; } + +-- dictionary +DROP DATABASE if exists test_01056_dict_data; +CREATE DATABASE test_01056_dict_data; +CREATE TABLE test_01056_dict_data.dict_data (key Int, value UInt16) Engine=Memory(); +CREATE DICTIONARY dict +( + `key` UInt64, + `value` UInt16 +) +PRIMARY KEY key +SOURCE(CLICKHOUSE( + HOST '127.0.0.1' PORT 9000 + TABLE 'dict_data' DB 'test_01056_dict_data' USER 'default' PASSWORD '')) +LIFETIME(MIN 0 MAX 0) +LAYOUT(SPARSE_HASHED()); +CREATE TABLE t3 AS dict; -- { serverError 80; } From 2aba254fb606d8935ccf6cbc8bc92f9275b48a61 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Fri, 3 Jan 2020 02:05:44 +0300 Subject: [PATCH 3/4] Add backQuoteIfNeed() in InterpreterCreateQuery::setEngine() --- dbms/src/Interpreters/InterpreterCreateQuery.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/dbms/src/Interpreters/InterpreterCreateQuery.cpp b/dbms/src/Interpreters/InterpreterCreateQuery.cpp index 59ae2ada1df..db48c3bed92 100644 --- a/dbms/src/Interpreters/InterpreterCreateQuery.cpp +++ b/dbms/src/Interpreters/InterpreterCreateQuery.cpp @@ -514,19 +514,21 @@ void InterpreterCreateQuery::setEngine(ASTCreateQuery & create) const ASTPtr as_create_ptr = context.getDatabase(as_database_name)->getCreateTableQuery(context, as_table_name); const auto & as_create = as_create_ptr->as(); + const String qualified_name = backQuoteIfNeed(as_database_name) + "." + backQuoteIfNeed(as_table_name); + if (as_create.is_view) throw Exception( - "Cannot CREATE a table AS " + as_database_name + "." + as_table_name + ", it is a View", + "Cannot CREATE a table AS " + qualified_name + ", it is a View", ErrorCodes::INCORRECT_QUERY); if (as_create.is_live_view) throw Exception( - "Cannot CREATE a table AS " + as_database_name + "." + as_table_name + ", it is a Live View", + "Cannot CREATE a table AS " + qualified_name + ", it is a Live View", ErrorCodes::INCORRECT_QUERY); if (as_create.is_dictionary) throw Exception( - "Cannot CREATE a table AS " + as_database_name + "." + as_table_name + ", it is a Dictionary", + "Cannot CREATE a table AS " + qualified_name + ", it is a Dictionary", ErrorCodes::INCORRECT_QUERY); create.set(create.storage, as_create.storage->ptr()); From 1dc14110774cb8e6d4ba1d2df873eab4dba8d88c Mon Sep 17 00:00:00 2001 From: alexey-milovidov Date: Fri, 3 Jan 2020 11:15:34 +0300 Subject: [PATCH 4/4] Update 01056_create_table_as.sql --- dbms/tests/queries/0_stateless/01056_create_table_as.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/dbms/tests/queries/0_stateless/01056_create_table_as.sql b/dbms/tests/queries/0_stateless/01056_create_table_as.sql index 8646c978372..a03bfb155f7 100644 --- a/dbms/tests/queries/0_stateless/01056_create_table_as.sql +++ b/dbms/tests/queries/0_stateless/01056_create_table_as.sql @@ -1,6 +1,7 @@ DROP TABLE IF EXISTS t1; CREATE TABLE t1 (key Int) Engine=Memory(); CREATE TABLE t2 AS t1; +DROP TABLE t2; -- live view SET allow_experimental_live_view=1;