mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 15:42:02 +00:00
simplify codes
This commit is contained in:
parent
6e7bffa6ea
commit
b35dd3bc02
@ -237,19 +237,7 @@ public:
|
||||
|
||||
if (function_node.isWindowFunction())
|
||||
{
|
||||
auto get_window_frame = [&]() -> std::optional<WindowFrame>
|
||||
{
|
||||
auto & window_node = function_node.getWindowNode()->as<WindowNode &>();
|
||||
auto & window_frame = window_node.getWindowFrame();
|
||||
if (!window_frame.is_default)
|
||||
return window_frame;
|
||||
auto aggregate_function = function_node.getAggregateFunction();
|
||||
if (const auto * win_func = dynamic_cast<const IWindowFunction *>(aggregate_function.get()))
|
||||
{
|
||||
return win_func->getDefaultFrame();
|
||||
}
|
||||
return {};
|
||||
};
|
||||
auto get_window_frame = [&]() { return extractWindowFrame(function_node); };
|
||||
buffer << " OVER (";
|
||||
buffer << calculateWindowNodeActionName(function_node.getWindowNode(), get_window_frame);
|
||||
buffer << ')';
|
||||
@ -1040,6 +1028,22 @@ String calculateConstantActionNodeName(const Field & constant_literal)
|
||||
return ActionNodeNameHelper::calculateConstantActionNodeName(constant_literal);
|
||||
}
|
||||
|
||||
std::optional<WindowFrame> extractWindowFrame(const FunctionNode & node)
|
||||
{
|
||||
if (!node.isWindowFunction())
|
||||
return {};
|
||||
auto & window_node = node.getWindowNode()->as<WindowNode &>();
|
||||
const auto & window_frame = window_node.getWindowFrame();
|
||||
if (!window_frame.is_default)
|
||||
return window_frame;
|
||||
auto aggregate_function = node.getAggregateFunction();
|
||||
if (const auto * win_func = dynamic_cast<const IWindowFunction *>(aggregate_function.get()))
|
||||
{
|
||||
return win_func->getDefaultFrame();
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
String calculateWindowNodeActionName(const QueryTreeNodePtr & node, const PlannerContext & planner_context, std::function<std::optional<WindowFrame>()> get_window_frame, bool use_column_identifier_as_action_node_name)
|
||||
{
|
||||
QueryTreeNodeToName empty_map;
|
||||
|
@ -71,6 +71,7 @@ String calculateConstantActionNodeName(const Field & constant_literal, const Dat
|
||||
/// Calculate action node name for constant, data type will be derived from constant literal value
|
||||
String calculateConstantActionNodeName(const Field & constant_literal);
|
||||
|
||||
std::optional<WindowFrame> extractWindowFrame(const FunctionNode & node);
|
||||
/** Calculate action node name for window node.
|
||||
* Window node action name can only be part of window function action name.
|
||||
* For column node column node identifier from planner context is used, if use_column_identifier_as_action_node_name = true.
|
||||
|
@ -29,18 +29,7 @@ WindowDescription extractWindowDescriptionFromWindowNode(const FunctionNode & fu
|
||||
auto node = func_node.getWindowNode();
|
||||
auto & window_node = node->as<WindowNode &>();
|
||||
|
||||
auto get_window_frame = [&]() -> std::optional<WindowFrame>
|
||||
{
|
||||
auto frame = window_node.getWindowFrame();
|
||||
if (!frame.is_default)
|
||||
return frame;
|
||||
auto aggregate_function = func_node.getAggregateFunction();
|
||||
if (const auto * win_func = dynamic_cast<const IWindowFunction *>(aggregate_function.get()))
|
||||
{
|
||||
return win_func->getDefaultFrame();
|
||||
}
|
||||
return {};
|
||||
};
|
||||
auto get_window_frame = [&]() { return extractWindowFrame(func_node); };
|
||||
|
||||
WindowDescription window_description;
|
||||
window_description.window_name = calculateWindowNodeActionName(node, planner_context, get_window_frame);
|
||||
|
Loading…
Reference in New Issue
Block a user