From 41dd39382447ff4dd88f3af8c8fda72965af551a Mon Sep 17 00:00:00 2001 From: Alexander Tokmakov Date: Tue, 1 Sep 2020 20:55:35 +0300 Subject: [PATCH] fixes --- src/Databases/DatabaseOrdinary.cpp | 7 +++++-- src/Interpreters/ya.make | 1 + src/Storages/StorageTableFunction.h | 1 + .../0_stateless/01461_alter_table_function.reference | 9 ++++----- tests/queries/0_stateless/01461_alter_table_function.sql | 4 +--- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Databases/DatabaseOrdinary.cpp b/src/Databases/DatabaseOrdinary.cpp index 0512a155418..3f536f7c995 100644 --- a/src/Databases/DatabaseOrdinary.cpp +++ b/src/Databases/DatabaseOrdinary.cpp @@ -254,9 +254,12 @@ void DatabaseOrdinary::alterTable(const Context & context, const StorageID & tab auto & ast_create_query = ast->as(); - if (ast_create_query.as_table_function) - throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Cannot alter table {} because it was created AS table function", backQuote(table_name)); + bool has_structure = ast_create_query.columns_list && ast_create_query.columns_list->columns; + if (ast_create_query.as_table_function && !has_structure) + throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Cannot alter table {} because it was created AS table function" + " and doesn't have structure in metadata", backQuote(table_name)); + assert(has_structure); ASTPtr new_columns = InterpreterCreateQuery::formatColumns(metadata.columns); ASTPtr new_indices = InterpreterCreateQuery::formatIndices(metadata.secondary_indices); ASTPtr new_constraints = InterpreterCreateQuery::formatConstraints(metadata.constraints); diff --git a/src/Interpreters/ya.make b/src/Interpreters/ya.make index 23cde61a744..cc3b63778f9 100644 --- a/src/Interpreters/ya.make +++ b/src/Interpreters/ya.make @@ -58,6 +58,7 @@ SRCS( ExtractExpressionInfoVisitor.cpp FillingRow.cpp getClusterName.cpp + getHeaderForProcessingStage.cpp getTableExpressions.cpp HashJoin.cpp IdentifierSemantic.cpp diff --git a/src/Storages/StorageTableFunction.h b/src/Storages/StorageTableFunction.h index 87af3a49a5c..4a0afdd5fb1 100644 --- a/src/Storages/StorageTableFunction.h +++ b/src/Storages/StorageTableFunction.h @@ -37,6 +37,7 @@ public: auto nested_storage = get_nested(); nested_storage->startup(); + nested_storage->renameInMemory(getStorageID()); nested = nested_storage; get_nested = {}; return nested; diff --git a/tests/queries/0_stateless/01461_alter_table_function.reference b/tests/queries/0_stateless/01461_alter_table_function.reference index 395155967a9..b552dd81b77 100644 --- a/tests/queries/0_stateless/01461_alter_table_function.reference +++ b/tests/queries/0_stateless/01461_alter_table_function.reference @@ -1,7 +1,6 @@ -CREATE TABLE default.table_from_remote AS remote(\'localhost\', \'system\', \'numbers\') -CREATE TABLE default.table_from_remote AS remote(\'localhost\', \'system\', \'numbers\') -CREATE TABLE default.table_from_numbers AS numbers(1000) -CREATE TABLE default.table_from_numbers AS numbers(1000) +CREATE TABLE default.table_from_remote\n(\n `number` UInt64\n) AS remote(\'localhost\', \'system\', \'numbers\') +CREATE TABLE default.table_from_remote\n(\n `number` UInt64,\n `col` UInt8\n) AS remote(\'localhost\', \'system\', \'numbers\') +CREATE TABLE default.table_from_numbers\n(\n `number` UInt64\n) AS numbers(1000) +CREATE TABLE default.table_from_numbers\n(\n `number` UInt64\n) AS numbers(1000) CREATE TABLE default.table_from_select\n(\n `number` UInt64\n)\nENGINE = MergeTree()\nORDER BY tuple()\nSETTINGS index_granularity = 8192 CREATE TABLE default.table_from_select\n(\n `number` UInt64,\n `col` UInt8\n)\nENGINE = MergeTree()\nORDER BY tuple()\nSETTINGS index_granularity = 8192 -1 diff --git a/tests/queries/0_stateless/01461_alter_table_function.sql b/tests/queries/0_stateless/01461_alter_table_function.sql index e242d1f0b7b..11f643f1e3e 100644 --- a/tests/queries/0_stateless/01461_alter_table_function.sql +++ b/tests/queries/0_stateless/01461_alter_table_function.sql @@ -6,7 +6,7 @@ CREATE TABLE table_from_remote AS remote('localhost', 'system', 'numbers'); SHOW CREATE TABLE table_from_remote; -ALTER TABLE table_from_remote ADD COLUMN col UInt8; --{serverError 48} +ALTER TABLE table_from_remote ADD COLUMN col UInt8; SHOW CREATE TABLE table_from_remote; @@ -26,8 +26,6 @@ ALTER TABLE table_from_select ADD COLUMN col UInt8; SHOW CREATE TABLE table_from_select; -SELECT 1; - DROP TABLE IF EXISTS table_from_remote; DROP TABLE IF EXISTS table_from_select; DROP TABLE IF EXISTS table_from_numbers;