Merge pull request #32464 from ClickHouse/fix-31538

Fix crash in case of MATERIALIZE COLUMN with no default expression.
This commit is contained in:
tavplubix 2021-12-10 16:27:53 +03:00 committed by GitHub
commit 9867d75fec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -569,6 +569,12 @@ ASTPtr MutationsInterpreter::prepare(bool dry_run)
stages.emplace_back(context);
const auto & column = columns_desc.get(command.column_name);
if (!column.default_desc.expression)
throw Exception(
ErrorCodes::BAD_ARGUMENTS,
"Cannot materialize column `{}` because it doesn't have default expression", column.name);
auto materialized_column = makeASTFunction(
"_CAST", column.default_desc.expression->clone(), std::make_shared<ASTLiteral>(column.type->getName()));

View File

@ -5,6 +5,8 @@ SET mutations_sync = 2;
CREATE TABLE tmp (x Int64) ENGINE = MergeTree() ORDER BY tuple() PARTITION BY tuple();
INSERT INTO tmp SELECT * FROM system.numbers LIMIT 20;
ALTER TABLE tmp MATERIALIZE COLUMN x; -- { serverError 36 }
ALTER TABLE tmp ADD COLUMN s String DEFAULT toString(x);
SELECT groupArray(x), groupArray(s) FROM tmp;