Merge pull request #64031 from ClickHouse/backport/24.3/63864

Backport #63864 to 24.3: Update lambda execution name
This commit is contained in:
robot-clickhouse 2024-05-17 18:21:37 +02:00 committed by GitHub
commit a2ddf783c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 41 additions and 2 deletions

View File

@ -243,8 +243,34 @@ public:
}
case QueryTreeNodeType::LAMBDA:
{
auto lambda_hash = node->getTreeHash();
result = "__lambda_" + toString(lambda_hash);
/// Initially, the action name was `"__lambda_" + toString(node->getTreeHash());`.
/// This is not a good idea because:
/// * hash is different on initiator and shard if the default database is changed in cluster
/// * hash is reliable only within one node; any change will break queries in between versions
///
/// Now, we calculate execution name as (names + types) for lambda arguments + action name (expression)
/// and this should be more reliable (as long as we trust the calculation of action name for functions)
WriteBufferFromOwnString buffer;
const auto & lambda_node = node->as<LambdaNode &>();
const auto & lambda_arguments_nodes = lambda_node.getArguments().getNodes();
size_t lambda_arguments_nodes_size = lambda_arguments_nodes.size();
for (size_t i = 0; i < lambda_arguments_nodes_size; ++i)
{
const auto & lambda_argument_node = lambda_arguments_nodes[i];
buffer << calculateActionNodeName(lambda_argument_node);
buffer << ' ';
buffer << lambda_argument_node->as<ColumnNode &>().getResultType()->getName();
if (i + 1 != lambda_arguments_nodes_size)
buffer << ", ";
}
buffer << " -> " << calculateActionNodeName(lambda_node.getExpression());
result = buffer.str();
break;
}
default:

View File

@ -8,3 +8,14 @@
7 1
8 1
9 1
[0]
[0]
[1]
[2]
[3]
[4]
[5]
[6]
[7]
[8]
[9]

View File

@ -23,6 +23,8 @@ set max_bytes_before_external_group_by = 16;
select x, count() from ma_dist group by x order by x;
select arrayFilter(y -> y = x, [x]) as f from ma_dist order by f;
drop table if exists shard_0.shard_01231_distributed_aggregation_memory_efficient;
drop table if exists shard_1.shard_01231_distributed_aggregation_memory_efficient;