mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
Fix alter default validation
This commit is contained in:
parent
38c7132c0f
commit
6732e5c217
@ -1109,24 +1109,21 @@ void AlterCommands::validate(const StorageInMemoryMetadata & metadata, const Con
|
|||||||
{
|
{
|
||||||
if (command.default_expression)
|
if (command.default_expression)
|
||||||
{
|
{
|
||||||
/// If we modify default, but not type
|
DataTypePtr data_type_ptr;
|
||||||
if (!command.data_type)
|
/// If we modify default, but not type.
|
||||||
{
|
if (!command.data_type) /// it's not ADD COLUMN, because we cannot add column without type
|
||||||
default_expr_list->children.emplace_back(setAlias(command.default_expression->clone(), column_name));
|
data_type_ptr = all_columns.get(column_name).type;
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
data_type_ptr = command.data_type;
|
||||||
|
|
||||||
const auto & final_column_name = column_name;
|
const auto & final_column_name = column_name;
|
||||||
const auto tmp_column_name = final_column_name + "_tmp";
|
const auto tmp_column_name = final_column_name + "_tmp";
|
||||||
const auto data_type_ptr = command.data_type;
|
|
||||||
|
|
||||||
|
|
||||||
default_expr_list->children.emplace_back(setAlias(
|
default_expr_list->children.emplace_back(setAlias(
|
||||||
addTypeConversionToAST(std::make_shared<ASTIdentifier>(tmp_column_name), data_type_ptr->getName()),
|
addTypeConversionToAST(std::make_shared<ASTIdentifier>(tmp_column_name), data_type_ptr->getName()),
|
||||||
final_column_name));
|
final_column_name));
|
||||||
|
|
||||||
default_expr_list->children.emplace_back(setAlias(command.default_expression->clone(), tmp_column_name));
|
default_expr_list->children.emplace_back(setAlias(command.default_expression->clone(), tmp_column_name));
|
||||||
}
|
|
||||||
} /// if we change data type for column with default
|
} /// if we change data type for column with default
|
||||||
else if (all_columns.has(column_name) && command.data_type)
|
else if (all_columns.has(column_name) && command.data_type)
|
||||||
{
|
{
|
||||||
@ -1139,7 +1136,6 @@ void AlterCommands::validate(const StorageInMemoryMetadata & metadata, const Con
|
|||||||
const auto tmp_column_name = final_column_name + "_tmp";
|
const auto tmp_column_name = final_column_name + "_tmp";
|
||||||
const auto data_type_ptr = command.data_type;
|
const auto data_type_ptr = command.data_type;
|
||||||
|
|
||||||
|
|
||||||
default_expr_list->children.emplace_back(setAlias(
|
default_expr_list->children.emplace_back(setAlias(
|
||||||
addTypeConversionToAST(std::make_shared<ASTIdentifier>(tmp_column_name), data_type_ptr->getName()), final_column_name));
|
addTypeConversionToAST(std::make_shared<ASTIdentifier>(tmp_column_name), data_type_ptr->getName()), final_column_name));
|
||||||
|
|
||||||
|
16
tests/queries/0_stateless/01522_validate_alter_default.sql
Normal file
16
tests/queries/0_stateless/01522_validate_alter_default.sql
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
DROP TABLE IF EXISTS table2;
|
||||||
|
CREATE TABLE table2
|
||||||
|
(
|
||||||
|
EventDate Date,
|
||||||
|
Id Int32,
|
||||||
|
Value Int32
|
||||||
|
)
|
||||||
|
Engine = MergeTree()
|
||||||
|
PARTITION BY toYYYYMM(EventDate)
|
||||||
|
ORDER BY Id;
|
||||||
|
|
||||||
|
ALTER TABLE table2 MODIFY COLUMN `Value` DEFAULT 'some_string'; --{serverError 6}
|
||||||
|
|
||||||
|
ALTER TABLE table2 ADD COLUMN `Value2` DEFAULT 'some_string'; --{serverError 36}
|
||||||
|
|
||||||
|
DROP TABLE IF EXISTS table2;
|
Loading…
Reference in New Issue
Block a user