ClickHouse/src/Planner/PlannerActionsVisitor.h

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

89 lines
3.7 KiB
C++
Raw Normal View History

2022-08-24 09:21:03 +00:00
#pragma once
2024-08-02 07:20:49 +00:00
#include <optional>
2022-08-24 09:21:03 +00:00
#include <Core/Names.h>
#include <Core/NamesAndTypes.h>
#include <Interpreters/Context_fwd.h>
#include <Analyzer/IQueryTreeNode.h>
#include <Interpreters/ActionsDAG.h>
2024-08-02 07:20:49 +00:00
#include <Interpreters/WindowDescription.h>
2022-08-24 09:21:03 +00:00
namespace DB
{
class PlannerContext;
using PlannerContextPtr = std::shared_ptr<PlannerContext>;
/** Planner actions visitor is responsible for adding necessary actions to calculate query tree expression node
* into actions dag.
*
* Preconditions:
2022-09-10 20:06:41 +00:00
* 1. Table expression data for table expression nodes is collected in planner context.
* For column node, that has column table expression source, identifier for column name in table expression data
* is used as action dag node name, if use_column_identifier_as_action_node_name = true.
2022-10-20 15:52:52 +00:00
* 2. Sets for IN functions are already collected in planner context.
*
* During actions build, there is special handling for following functions:
* 1. Aggregate functions are added in actions dag as INPUT nodes. Aggregate functions arguments are not added.
2022-10-20 15:52:52 +00:00
* 2. For function `in` and its variants, already collected sets from planner context are used.
*/
2022-08-24 09:21:03 +00:00
class PlannerActionsVisitor
{
public:
explicit PlannerActionsVisitor(const PlannerContextPtr & planner_context_, bool use_column_identifier_as_action_node_name_ = true);
2022-08-24 09:21:03 +00:00
/** Add actions necessary to calculate expression node into expression dag.
* Necessary actions are not added in actions dag output.
* Returns query tree expression node actions dag nodes.
*/
2024-06-12 16:53:32 +00:00
ActionsDAG::NodeRawConstPtrs visit(ActionsDAG & actions_dag, QueryTreeNodePtr expression_node);
2022-08-24 09:21:03 +00:00
private:
const PlannerContextPtr planner_context;
bool use_column_identifier_as_action_node_name = true;
2022-08-24 09:21:03 +00:00
};
2022-10-20 15:52:52 +00:00
/** Calculate query tree expression node action dag name and add them into node to name map.
2022-08-25 14:19:35 +00:00
* If node exists in map, name from map is used.
*
* For column node column node identifier from planner context is used, if use_column_identifier_as_action_node_name = true.
2022-08-25 14:19:35 +00:00
*/
2022-08-31 15:21:17 +00:00
using QueryTreeNodeToName = std::unordered_map<QueryTreeNodePtr, String>;
String calculateActionNodeName(const QueryTreeNodePtr & node,
const PlannerContext & planner_context,
QueryTreeNodeToName & node_to_name,
bool use_column_identifier_as_action_node_name = true);
2022-08-25 14:19:35 +00:00
2022-09-12 14:14:40 +00:00
/** Calculate query tree expression node action dag name.
2022-08-25 14:19:35 +00:00
*
* For column node column node identifier from planner context is used, if use_column_identifier_as_action_node_name = true.
2022-08-25 14:19:35 +00:00
*/
String calculateActionNodeName(const QueryTreeNodePtr & node,
const PlannerContext & planner_context,
bool use_column_identifier_as_action_node_name = true);
2022-08-25 14:19:35 +00:00
2022-09-10 20:06:41 +00:00
/// Calculate action node name for constant
String calculateConstantActionNodeName(const Field & constant_literal, const DataTypePtr & constant_type);
/// Calculate action node name for constant, data type will be derived from constant literal value
String calculateConstantActionNodeName(const Field & constant_literal);
2022-08-25 14:19:35 +00:00
2024-08-02 22:29:22 +00:00
/// If the window frame is not set in sql, try to use the default frame from window function
2024-08-02 22:33:10 +00:00
/// if it have any one. Otherwise return empty.
2024-08-02 22:29:22 +00:00
/// If the window frame is set in sql, use it anyway.
2024-08-02 08:22:36 +00:00
std::optional<WindowFrame> extractWindowFrame(const FunctionNode & node);
2024-08-02 22:29:22 +00:00
2022-09-12 14:14:40 +00:00
/** 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.
2022-09-12 14:14:40 +00:00
*/
2024-08-02 07:20:49 +00:00
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 = true);
2022-09-12 14:14:40 +00:00
2022-08-24 09:21:03 +00:00
}