2023-01-11 11:54:28 +00:00
|
|
|
#include <Planner/CollectColumnIdentifiers.h>
|
2022-12-23 19:34:56 +00:00
|
|
|
|
|
|
|
#include <Analyzer/InDepthQueryTreeVisitor.h>
|
|
|
|
#include <Analyzer/ColumnNode.h>
|
|
|
|
|
|
|
|
#include <Planner/PlannerContext.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2022-12-27 11:08:56 +00:00
|
|
|
class CollectTopLevelColumnIdentifiersVisitor : public InDepthQueryTreeVisitor<CollectTopLevelColumnIdentifiersVisitor, true>
|
2022-12-23 19:34:56 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2022-12-27 11:08:56 +00:00
|
|
|
explicit CollectTopLevelColumnIdentifiersVisitor(const PlannerContextPtr & planner_context_, ColumnIdentifierSet & used_identifiers_)
|
2022-12-23 19:34:56 +00:00
|
|
|
: used_identifiers(used_identifiers_)
|
|
|
|
, planner_context(planner_context_)
|
|
|
|
{}
|
|
|
|
|
2022-12-29 10:21:29 +00:00
|
|
|
static bool needChildVisit(VisitQueryTreeNodeType &, VisitQueryTreeNodeType & child)
|
2022-12-23 19:34:56 +00:00
|
|
|
{
|
|
|
|
const auto & node_type = child->getNodeType();
|
2023-01-11 11:54:28 +00:00
|
|
|
return node_type != QueryTreeNodeType::TABLE
|
|
|
|
&& node_type != QueryTreeNodeType::TABLE_FUNCTION
|
|
|
|
&& node_type != QueryTreeNodeType::QUERY
|
|
|
|
&& node_type != QueryTreeNodeType::UNION
|
|
|
|
&& node_type != QueryTreeNodeType::JOIN
|
|
|
|
&& node_type != QueryTreeNodeType::ARRAY_JOIN;
|
2022-12-23 19:34:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void visitImpl(const QueryTreeNodePtr & node)
|
|
|
|
{
|
|
|
|
if (node->getNodeType() != QueryTreeNodeType::COLUMN)
|
|
|
|
return;
|
|
|
|
|
2023-01-11 11:54:28 +00:00
|
|
|
const auto * column_identifier = planner_context->getColumnNodeIdentifierOrNull(node);
|
|
|
|
if (!column_identifier)
|
2022-12-23 19:34:56 +00:00
|
|
|
return;
|
|
|
|
|
2023-01-11 11:54:28 +00:00
|
|
|
used_identifiers.insert(*column_identifier);
|
2022-12-23 19:34:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ColumnIdentifierSet & used_identifiers;
|
|
|
|
const PlannerContextPtr & planner_context;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-12-27 11:08:56 +00:00
|
|
|
void collectTopLevelColumnIdentifiers(const QueryTreeNodePtr & node, const PlannerContextPtr & planner_context, ColumnIdentifierSet & out)
|
2022-12-23 19:34:56 +00:00
|
|
|
{
|
2022-12-27 11:08:56 +00:00
|
|
|
CollectTopLevelColumnIdentifiersVisitor visitor(planner_context, out);
|
2022-12-23 19:34:56 +00:00
|
|
|
visitor.visit(node);
|
|
|
|
}
|
|
|
|
|
2022-12-27 11:08:56 +00:00
|
|
|
ColumnIdentifierSet collectTopLevelColumnIdentifiers(const QueryTreeNodePtr & node, const PlannerContextPtr & planner_context)
|
2022-12-23 19:34:56 +00:00
|
|
|
{
|
|
|
|
ColumnIdentifierSet out;
|
2022-12-27 11:08:56 +00:00
|
|
|
collectTopLevelColumnIdentifiers(node, planner_context, out);
|
2022-12-23 19:34:56 +00:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|