Merge pull request #41281 from ClickHouse/fix-key-condition-with-actions-dag-literal-name

Fix wrong literal name in KeyCondition using ActionsDAG.
This commit is contained in:
Nikolai Kochetov 2022-09-16 16:06:38 +02:00 committed by GitHub
commit 16f78eb804
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 2 deletions

View File

@ -116,10 +116,20 @@ static void appendColumnNameWithoutAlias(const ActionsDAG::Node & node, WriteBuf
{
switch (node.type)
{
case (ActionsDAG::ActionType::INPUT): [[fallthrough]];
case (ActionsDAG::ActionType::COLUMN):
case (ActionsDAG::ActionType::INPUT):
writeString(node.result_name, out);
break;
case (ActionsDAG::ActionType::COLUMN):
{
/// If it was created from ASTLiteral, then result_name can be an alias.
/// We need to convert value back to string here.
if (const auto * column_const = typeid_cast<const ColumnConst *>(node.column.get()))
writeString(applyVisitor(FieldVisitorToString(), column_const->getField()), out);
/// It may be possible that column is ColumnSet
else
writeString(node.result_name, out);
break;
}
case (ActionsDAG::ActionType::ALIAS):
appendColumnNameWithoutAlias(*node.children.front(), out, legacy);
break;

View File

@ -0,0 +1,10 @@
create table tba (event_id Int64, event_dt Int64) Engine =MergeTree order by event_id ;
insert into tba select number%500, 20220822 from numbers(1e6);
select count() from (
SELECT event_dt FROM (
select event_dt, 403 AS event_id from (
select event_dt from tba as tba
where event_id = 9 and ((tba.event_dt >= 20220822 and tba.event_dt <= 20220822))
)
) tba WHERE tba.event_dt >= 20220822 and tba.event_dt <= 20220822 and event_id = 403 );