ClickHouse/src/Planner/PlannerActionsVisitor.h

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

79 lines
3.0 KiB
C++
Raw Normal View History

2022-08-24 09:21:03 +00:00
#pragma once
#include <Common/HashTable/Hash.h>
#include <Core/Names.h>
#include <Core/NamesAndTypes.h>
#include <Interpreters/Context_fwd.h>
#include <Analyzer/IQueryTreeNode.h>
#include <Interpreters/ActionsDAG.h>
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.
* 2. Sets for IN functions are already collected in planner global 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.
* 2. For function `in` and its variants, already collected sets from global context are used.
*/
2022-08-24 09:21:03 +00:00
class PlannerActionsVisitor
{
public:
explicit PlannerActionsVisitor(const PlannerContextPtr & planner_context_);
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.
*/
ActionsDAG::NodeRawConstPtrs visit(ActionsDAGPtr actions_dag, QueryTreeNodePtr expression_node);
2022-08-24 09:21:03 +00:00
private:
const PlannerContextPtr planner_context;
};
2022-08-25 14:19:35 +00:00
/** Calculate query tree expression node name action dag name and add them into node to name map.
* If node exists in map, name from map is used.
*
* For column node column node identifier from planner context is used.
*/
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);
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.
*/
2022-08-31 15:21:17 +00:00
String calculateActionNodeName(const QueryTreeNodePtr & node, const PlannerContext & planner_context);
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
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.
*/
String calculateWindowNodeActionName(const QueryTreeNodePtr & node, const PlannerContext & planner_context, QueryTreeNodeToName & node_to_name);
/** Calculate action node name for window node.
* Window node action name can only be part of window function action name.
*/
String calculateWindowNodeActionName(const QueryTreeNodePtr & node, const PlannerContext & planner_context);
2022-08-24 09:21:03 +00:00
}