Merge pull request #14326 from ClickHouse/fix_crash_alter_table_function

Throw exception on alter for storages created from table functions
This commit is contained in:
tavplubix 2020-09-01 15:03:09 +03:00 committed by GitHub
commit cb4644ea6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 0 deletions

View File

@ -33,6 +33,11 @@ static constexpr size_t PRINT_MESSAGE_EACH_N_OBJECTS = 256;
static constexpr size_t PRINT_MESSAGE_EACH_N_SECONDS = 5;
static constexpr size_t METADATA_FILE_BUFFER_SIZE = 32768;
namespace ErrorCodes
{
extern const int NOT_IMPLEMENTED;
}
namespace
{
void tryAttachTable(
@ -249,6 +254,9 @@ void DatabaseOrdinary::alterTable(const Context & context, const StorageID & tab
auto & ast_create_query = ast->as<ASTCreateQuery &>();
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));
ASTPtr new_columns = InterpreterCreateQuery::formatColumns(metadata.columns);
ASTPtr new_indices = InterpreterCreateQuery::formatIndices(metadata.secondary_indices);
ASTPtr new_constraints = InterpreterCreateQuery::formatConstraints(metadata.constraints);

View File

@ -0,0 +1,7 @@
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_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

View File

@ -0,0 +1,33 @@
DROP TABLE IF EXISTS table_from_remote;
DROP TABLE IF EXISTS table_from_select;
DROP TABLE IF EXISTS table_from_numbers;
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}
SHOW CREATE TABLE table_from_remote;
CREATE TABLE table_from_numbers AS numbers(1000);
SHOW CREATE TABLE table_from_numbers;
ALTER TABLE table_from_numbers ADD COLUMN col UInt8; --{serverError 48}
SHOW CREATE TABLE table_from_numbers;
CREATE TABLE table_from_select ENGINE = MergeTree() ORDER BY tuple() AS SELECT number from system.numbers LIMIT 1;
SHOW CREATE TABLE table_from_select;
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;