mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 08:32:02 +00:00
Fix: throw error when column transformer use non-exsit column
This commit is contained in:
parent
9a9ad20c6d
commit
293d2f06fa
@ -12,6 +12,7 @@ namespace DB
|
||||
namespace ErrorCodes
|
||||
{
|
||||
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
|
||||
extern const int NO_SUCH_COLUMN_IN_TABLE;
|
||||
}
|
||||
|
||||
void IASTColumnsTransformer::transform(const ASTPtr & transformer, ASTs & nodes)
|
||||
@ -130,6 +131,7 @@ void ASTColumnsReplaceTransformer::transform(ASTs & nodes) const
|
||||
replace_map.emplace(replacement.name, replacement.expr);
|
||||
}
|
||||
|
||||
UInt8 replace_column_sucess = 0;
|
||||
for (auto & column : nodes)
|
||||
{
|
||||
if (const auto * id = column->as<ASTIdentifier>())
|
||||
@ -139,6 +141,7 @@ void ASTColumnsReplaceTransformer::transform(ASTs & nodes) const
|
||||
{
|
||||
column = replace_it->second;
|
||||
column->setAlias(replace_it->first);
|
||||
++replace_column_sucess;
|
||||
}
|
||||
}
|
||||
else if (auto * ast_with_alias = dynamic_cast<ASTWithAlias *>(column.get()))
|
||||
@ -151,9 +154,15 @@ void ASTColumnsReplaceTransformer::transform(ASTs & nodes) const
|
||||
replaceChildren(new_ast, column, replace_it->first);
|
||||
column = new_ast;
|
||||
column->setAlias(replace_it->first);
|
||||
}
|
||||
++replace_column_sucess;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (replace_column_sucess < replace_map.size())
|
||||
throw Exception(
|
||||
"Expressions in columns transformer REPLACE should use same column name as original column",
|
||||
ErrorCodes::NO_SUCH_COLUMN_IN_TABLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,7 +8,6 @@
|
||||
1970-04-11 1970-01-11 1970-11-21
|
||||
222 18 347
|
||||
111 11 173.5
|
||||
1970-04-11 1970-01-11 1970-11-21
|
||||
SELECT
|
||||
sum(i),
|
||||
sum(j),
|
||||
@ -51,11 +50,6 @@ SELECT
|
||||
avg(j + 2 AS j),
|
||||
avg(k)
|
||||
FROM columns_transformers
|
||||
SELECT
|
||||
toDate(any(i)),
|
||||
toDate(any(j)),
|
||||
toDate(any(k))
|
||||
FROM columns_transformers AS a
|
||||
SELECT
|
||||
(i + 1) + 1 AS i,
|
||||
j,
|
||||
|
@ -13,11 +13,12 @@ SELECT columns_transformers.* EXCEPT(j) APPLY(avg) from columns_transformers;
|
||||
-- EXCEPT after APPLY will not match anything
|
||||
SELECT a.* APPLY(toDate) EXCEPT(i, j) APPLY(any) from columns_transformers a;
|
||||
|
||||
SELECT * REPLACE(i + 1 AS col) from columns_transformers; -- { serverError 16 }
|
||||
SELECT * REPLACE(i + 1 AS i) APPLY(sum) from columns_transformers;
|
||||
SELECT columns_transformers.* REPLACE(j + 2 AS j, i + 1 AS i) APPLY(avg) from columns_transformers;
|
||||
SELECT columns_transformers.* REPLACE(j + 1 AS j, j + 2 AS j) APPLY(avg) from columns_transformers; -- { serverError 43 }
|
||||
-- REPLACE after APPLY will not match anything
|
||||
SELECT a.* APPLY(toDate) REPLACE(i + 1 AS i) APPLY(any) from columns_transformers a;
|
||||
SELECT a.* APPLY(toDate) REPLACE(i + 1 AS i) APPLY(any) from columns_transformers a; -- { serverError 16 }
|
||||
|
||||
EXPLAIN SYNTAX SELECT * APPLY(sum) from columns_transformers;
|
||||
EXPLAIN SYNTAX SELECT columns_transformers.* APPLY(avg) from columns_transformers;
|
||||
@ -28,7 +29,6 @@ EXPLAIN SYNTAX SELECT columns_transformers.* EXCEPT(j) APPLY(avg) from columns_t
|
||||
EXPLAIN SYNTAX SELECT a.* APPLY(toDate) EXCEPT(i, j) APPLY(any) from columns_transformers a;
|
||||
EXPLAIN SYNTAX SELECT * REPLACE(i + 1 AS i) APPLY(sum) from columns_transformers;
|
||||
EXPLAIN SYNTAX SELECT columns_transformers.* REPLACE(j + 2 AS j, i + 1 AS i) APPLY(avg) from columns_transformers;
|
||||
EXPLAIN SYNTAX SELECT a.* APPLY(toDate) REPLACE(i + 1 AS i) APPLY(any) from columns_transformers a;
|
||||
|
||||
-- Multiple REPLACE in a row
|
||||
EXPLAIN SYNTAX SELECT * REPLACE(i + 1 AS i) REPLACE(i + 1 AS i) from columns_transformers;
|
||||
|
Loading…
Reference in New Issue
Block a user