ClickHouse/src/Planner/PlannerAggregation.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
2.1 KiB
C++
Raw Normal View History

2022-09-03 12:11:09 +00:00
#include <Planner/PlannerAggregation.h>
2022-11-29 11:35:05 +00:00
#include <Analyzer/ConstantNode.h>
2022-09-03 12:11:09 +00:00
#include <Analyzer/FunctionNode.h>
2022-11-29 11:35:05 +00:00
2022-09-03 12:11:09 +00:00
#include <Planner/PlannerActionsVisitor.h>
namespace DB
{
2022-09-05 10:24:54 +00:00
AggregateDescriptions extractAggregateDescriptions(const QueryTreeNodes & aggregate_function_nodes, const PlannerContext & planner_context)
{
QueryTreeNodeToName node_to_name;
NameSet unique_aggregate_action_node_names;
AggregateDescriptions aggregate_descriptions;
for (const auto & aggregate_function_node : aggregate_function_nodes)
{
2022-09-12 14:14:40 +00:00
const auto & aggregate_function_node_typed = aggregate_function_node->as<FunctionNode &>();
2022-09-05 10:24:54 +00:00
String node_name = calculateActionNodeName(aggregate_function_node, planner_context, node_to_name);
auto [_, inserted] = unique_aggregate_action_node_names.emplace(node_name);
if (!inserted)
continue;
AggregateDescription aggregate_description;
2022-09-12 14:14:40 +00:00
aggregate_description.function = aggregate_function_node_typed.getAggregateFunction();
2022-09-05 10:24:54 +00:00
2022-09-12 14:14:40 +00:00
const auto & parameters_nodes = aggregate_function_node_typed.getParameters().getNodes();
2022-09-05 10:24:54 +00:00
aggregate_description.parameters.reserve(parameters_nodes.size());
for (const auto & parameter_node : parameters_nodes)
{
/// Function parameters constness validated during analysis stage
2022-11-29 11:35:05 +00:00
aggregate_description.parameters.push_back(parameter_node->as<ConstantNode &>().getValue());
2022-09-05 10:24:54 +00:00
}
2022-09-12 14:14:40 +00:00
const auto & arguments_nodes = aggregate_function_node_typed.getArguments().getNodes();
2022-09-05 10:24:54 +00:00
aggregate_description.argument_names.reserve(arguments_nodes.size());
for (const auto & argument_node : arguments_nodes)
{
String argument_node_name = calculateActionNodeName(argument_node, planner_context, node_to_name);
aggregate_description.argument_names.emplace_back(std::move(argument_node_name));
}
2022-10-20 15:52:52 +00:00
aggregate_description.column_name = std::move(node_name);
2022-09-05 10:24:54 +00:00
aggregate_descriptions.push_back(std::move(aggregate_description));
}
return aggregate_descriptions;
}
2022-09-03 12:11:09 +00:00
}