Merge pull request #8508 from azat/create-table-as-dict-fix

Avoid SIGSEGV on CREATE TABLE .. AS dictionary
This commit is contained in:
alexey-milovidov 2020-01-03 11:15:46 +03:00 committed by GitHub
commit 50cc3092b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 2 deletions

View File

@ -514,14 +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<ASTCreateQuery &>();
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 " + qualified_name + ", it is a Dictionary",
ErrorCodes::INCORRECT_QUERY);
create.set(create.storage, as_create.storage->ptr());

View File

@ -0,0 +1,30 @@
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;
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; }