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 <Interpreters/SubqueryForSet.h>
|
|
|
|
|
|
|
|
#include <Analyzer/IQueryTreeNode.h>
|
|
|
|
|
|
|
|
#include <Interpreters/ActionsDAG.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class PlannerContext;
|
|
|
|
using PlannerContextPtr = std::shared_ptr<PlannerContext>;
|
|
|
|
|
2022-08-24 14:50:53 +00:00
|
|
|
/** Planner actions visitor is responsible for adding necessary actions to calculate query tree expression node
|
|
|
|
* into actions dag.
|
|
|
|
*
|
|
|
|
* Column name to identifier map in planner context must be already initialized.
|
|
|
|
* Identifiers in this map are used as action dag node names for column query tree nodes.
|
|
|
|
*
|
|
|
|
* 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, planner context is populated with necessary table expressions to compute for sets,
|
|
|
|
* and prepared sets.
|
|
|
|
*/
|
2022-08-24 09:21:03 +00:00
|
|
|
class PlannerActionsVisitor
|
|
|
|
{
|
|
|
|
public:
|
2022-08-24 14:50:53 +00:00
|
|
|
explicit PlannerActionsVisitor(const PlannerContextPtr & planner_context_);
|
2022-08-24 09:21:03 +00:00
|
|
|
|
2022-08-24 14:50:53 +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.
|
|
|
|
*/
|
|
|
|
using QueryTreeNodeToName = std::unordered_map<const IQueryTreeNode *, String>;
|
|
|
|
String calculateActionsDAGNodeName(const IQueryTreeNode * node, const PlannerContext & planner_context, QueryTreeNodeToName & node_to_name);
|
|
|
|
|
|
|
|
/** Calculate query tree expression node name action dag name.
|
|
|
|
*
|
|
|
|
* For column node column node identifier from planner context is used.
|
|
|
|
*/
|
|
|
|
String calculateActionsDAGNodeName(const IQueryTreeNode * node, const PlannerContext & planner_context);
|
|
|
|
|
|
|
|
|
2022-08-24 09:21:03 +00:00
|
|
|
}
|