OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RelRexDagVisitor Class Reference

#include <RelRexDagVisitor.h>

+ Inheritance diagram for RelRexDagVisitor:

Public Member Functions

virtual ~RelRexDagVisitor ()=default
 
virtual void visit (RelAlgNode const *)
 
virtual void visit (RexScalar const *)
 

Protected Member Functions

virtual void visit (RelAggregate const *)
 
virtual void visit (RelCompound const *)
 
virtual void visit (RelFilter const *)
 
virtual void visit (RelJoin const *)
 
virtual void visit (RelLeftDeepInnerJoin const *)
 
virtual void visit (RelLogicalUnion const *)
 
virtual void visit (RelLogicalValues const *)
 
virtual void visit (RelModify const *)
 
virtual void visit (RelProject const *)
 
virtual void visit (RelScan const *)
 
virtual void visit (RelSort const *)
 
virtual void visit (RelTableFunction const *)
 
virtual void visit (RelTranslatedJoin const *)
 
virtual void visit (RexAbstractInput const *)
 
virtual void visit (RexCase const *)
 
virtual void visit (RexFunctionOperator const *)
 
virtual void visit (RexInput const *)
 
virtual void visit (RexLiteral const *)
 
virtual void visit (RexOperator const *)
 
virtual void visit (RexRef const *)
 
virtual void visit (RexSubQuery const *)
 
virtual void visit (RexWindowFunctionOperator const *)
 
void castAndVisit (RelAlgNode const *)
 

Private Types

using Cache = robin_hood::unordered_set< void const * >
 
template<typename T , size_t N>
using Handlers = std::array< TypeHandler< RelRexDagVisitor, T >, N >
 

Private Member Functions

template<typename T , typename U >
void cast (T const *node)
 

Static Private Member Functions

template<typename T , typename... Ts>
static Handlers< T, sizeof...(Ts)> make_handlers ()
 

Private Attributes

Cache cache_
 

Detailed Description

Definition at line 37 of file RelRexDagVisitor.h.

Member Typedef Documentation

using RelRexDagVisitor::Cache = robin_hood::unordered_set<void const*>
private

Definition at line 71 of file RelRexDagVisitor.h.

template<typename T , size_t N>
using RelRexDagVisitor::Handlers = std::array<TypeHandler<RelRexDagVisitor, T>, N>
private

Definition at line 80 of file RelRexDagVisitor.h.

Constructor & Destructor Documentation

virtual RelRexDagVisitor::~RelRexDagVisitor ( )
virtualdefault

Member Function Documentation

template<typename T , typename U >
void RelRexDagVisitor::cast ( T const *  node)
inlineprivate

Definition at line 75 of file RelRexDagVisitor.h.

References visit().

75  {
76  visit(dynamic_cast<U const*>(node));
77  }
virtual void visit(RelAlgNode const *)

+ Here is the call graph for this function:

void RelRexDagVisitor::castAndVisit ( RelAlgNode const *  rel_alg_node)
protected

Definition at line 40 of file RelRexDagVisitor.cpp.

References RelRexToStringConfig::defaults(), logger::FATAL, LOG, gpu_enabled::lower_bound(), make_handlers(), and RelAlgNode::toString().

Referenced by visit().

40  {
41  // Array that pairs std::type_index(typeid(*rel_alg_node)) -> method pointer.
42  static auto const handlers = make_handlers<RelAlgNode,
45  RelFilter,
46  RelJoin,
50  RelModify,
51  RelProject,
52  RelScan,
53  RelSort,
56  static_assert(std::is_trivially_destructible_v<decltype(handlers)>);
57  // Will throw std::bad_typeid if rel_alg_node == nullptr.
58  auto const& type_index = std::type_index(typeid(*rel_alg_node));
59  auto const itr = std::lower_bound(handlers.cbegin(), handlers.cend(), type_index);
60  if (itr != handlers.cend() && itr->type_index == type_index) {
61  (this->*itr->handler)(rel_alg_node);
62  } else {
63  LOG(FATAL) << "Unhandled RelAlgNode type: "
64  << rel_alg_node->toString(RelRexToStringConfig::defaults());
65  }
66 }
#define LOG(tag)
Definition: Logger.h:285
static Handlers< T, sizeof...(Ts)> make_handlers()
DEVICE auto lower_bound(ARGS &&...args)
Definition: gpu_enabled.h:78
static RelRexToStringConfig defaults()
Definition: RelAlgDag.h:78

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T , typename... Ts>
RelRexDagVisitor::Handlers< T, sizeof...(Ts)> RelRexDagVisitor::make_handlers ( )
staticprivate

Definition at line 32 of file RelRexDagVisitor.cpp.

References gpu_enabled::sort(), and heavydb.dtypes::T.

Referenced by castAndVisit(), and visit().

32  {
33  RelRexDagVisitor::Handlers<T, sizeof...(Ts)> handlers{
34  {{std::type_index(typeid(Ts)), &RelRexDagVisitor::cast<T, Ts>}...}};
35  std::sort(handlers.begin(), handlers.end());
36  return handlers;
37 }
DEVICE void sort(ARGS &&...args)
Definition: gpu_enabled.h:105
std::array< TypeHandler< RelRexDagVisitor, T >, N > Handlers

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void RelRexDagVisitor::visit ( RelAlgNode const *  rel_alg_node)
virtual

Definition at line 68 of file RelRexDagVisitor.cpp.

References cache_, castAndVisit(), RelAlgNode::getInput(), and RelAlgNode::inputCount().

Referenced by cast(), QueryPlanDagChecker::check(), SQLOperatorDetector::visit(), RexSubQueryIdCollector::visit(), visit(), QueryPlanDagChecker::visit(), and ScanNodeTableKeyCollector::visit().

68  {
69  if (cache_.emplace(static_cast<Cache::value_type>(rel_alg_node)).second) {
70  castAndVisit(rel_alg_node);
71  for (size_t i = 0; i < rel_alg_node->inputCount(); ++i) {
72  visit(rel_alg_node->getInput(i));
73  }
74  }
75 }
virtual void visit(RelAlgNode const *)
void castAndVisit(RelAlgNode const *)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void RelRexDagVisitor::visit ( RexScalar const *  rex_scalar)
virtual

Definition at line 132 of file RelRexDagVisitor.cpp.

References cache_, RelRexToStringConfig::defaults(), logger::FATAL, LOG, gpu_enabled::lower_bound(), make_handlers(), and RelAlgDagNode::toString().

132  {
133  // Array that pairs std::type_index(typeid(*rex_scalar)) -> method pointer.
134  static auto const handlers = make_handlers<RexScalar,
136  RexCase,
138  RexInput,
139  RexLiteral,
140  RexOperator,
141  RexRef,
142  RexSubQuery,
144  static_assert(std::is_trivially_destructible_v<decltype(handlers)>);
145  if (cache_.emplace(static_cast<Cache::value_type>(rex_scalar)).second) {
146  // Will throw std::bad_typeid if rex_scalar == nullptr.
147  auto const& type_index = std::type_index(typeid(*rex_scalar));
148  auto const itr = std::lower_bound(handlers.cbegin(), handlers.cend(), type_index);
149  if (itr != handlers.cend() && itr->type_index == type_index) {
150  (this->*itr->handler)(rex_scalar);
151  } else {
152  LOG(FATAL) << "Unhandled RexScalar type: "
153  << rex_scalar->toString(RelRexToStringConfig::defaults());
154  }
155  }
156 }
#define LOG(tag)
Definition: Logger.h:285
static Handlers< T, sizeof...(Ts)> make_handlers()
DEVICE auto lower_bound(ARGS &&...args)
Definition: gpu_enabled.h:78
static RelRexToStringConfig defaults()
Definition: RelAlgDag.h:78

+ Here is the call graph for this function:

virtual void RelRexDagVisitor::visit ( RelAggregate const *  )
inlineprotectedvirtual

Definition at line 44 of file RelRexDagVisitor.h.

44 {}
void RelRexDagVisitor::visit ( RelCompound const *  rel_compound)
protectedvirtual

Reimplemented in QueryPlanDagChecker.

Definition at line 77 of file RelRexDagVisitor.cpp.

References RelCompound::getFilterExpr(), RelCompound::getScalarSource(), RelCompound::getScalarSourcesSize(), and visit().

77  {
78  if (rel_compound->getFilterExpr()) {
79  visit(rel_compound->getFilterExpr());
80  }
81  for (size_t i = 0; i < rel_compound->getScalarSourcesSize(); ++i) {
82  visit(rel_compound->getScalarSource(i));
83  }
84 }
virtual void visit(RelAlgNode const *)

+ Here is the call graph for this function:

void RelRexDagVisitor::visit ( RelFilter const *  rel_filter)
protectedvirtual

Definition at line 86 of file RelRexDagVisitor.cpp.

References RelFilter::getCondition(), and visit().

86  {
87  visit(rel_filter->getCondition());
88 }
virtual void visit(RelAlgNode const *)

+ Here is the call graph for this function:

void RelRexDagVisitor::visit ( RelJoin const *  rel_join)
protectedvirtual

Definition at line 90 of file RelRexDagVisitor.cpp.

References RelJoin::getCondition(), and visit().

90  {
91  visit(rel_join->getCondition());
92 }
virtual void visit(RelAlgNode const *)

+ Here is the call graph for this function:

void RelRexDagVisitor::visit ( RelLeftDeepInnerJoin const *  rel_left_deep_inner_join)
protectedvirtual

Definition at line 94 of file RelRexDagVisitor.cpp.

References RelLeftDeepInnerJoin::getInnerCondition(), RelLeftDeepInnerJoin::getOuterCondition(), RelAlgNode::inputCount(), and visit().

94  {
95  visit(rel_left_deep_inner_join->getInnerCondition());
96  for (size_t level = 1; level < rel_left_deep_inner_join->inputCount(); ++level) {
97  if (auto* outer_condition = rel_left_deep_inner_join->getOuterCondition(level)) {
98  visit(outer_condition);
99  }
100  }
101 }
virtual void visit(RelAlgNode const *)

+ Here is the call graph for this function:

virtual void RelRexDagVisitor::visit ( RelLogicalUnion const *  )
inlineprotectedvirtual

Reimplemented in QueryPlanDagChecker.

Definition at line 49 of file RelRexDagVisitor.h.

49 {}
void RelRexDagVisitor::visit ( RelLogicalValues const *  rel_logical_values)
protectedvirtual

Reimplemented in anonymous_namespace{QueryPhysicalInputsCollector.cpp}::RelAlgPhysicalTableInputsVisitor, and QueryPlanDagChecker.

Definition at line 103 of file RelRexDagVisitor.cpp.

References RelLogicalValues::getNumRows(), RelLogicalValues::getRowsSize(), RelLogicalValues::getValueAt(), and visit().

103  {
104  for (size_t row_idx = 0; row_idx < rel_logical_values->getNumRows(); ++row_idx) {
105  for (size_t col_idx = 0; col_idx < rel_logical_values->getRowsSize(); ++col_idx) {
106  visit(rel_logical_values->getValueAt(row_idx, col_idx));
107  }
108  }
109 }
virtual void visit(RelAlgNode const *)

+ Here is the call graph for this function:

virtual void RelRexDagVisitor::visit ( RelModify const *  )
inlineprotectedvirtual

Reimplemented in QueryPlanDagChecker.

Definition at line 51 of file RelRexDagVisitor.h.

51 {}
void RelRexDagVisitor::visit ( RelProject const *  rel_projection)
protectedvirtual

Reimplemented in QueryPlanDagChecker.

Definition at line 111 of file RelRexDagVisitor.cpp.

References RelProject::getProjectAt(), RelProject::size(), and visit().

111  {
112  for (size_t i = 0; i < rel_projection->size(); ++i) {
113  visit(rel_projection->getProjectAt(i));
114  }
115 }
virtual void visit(RelAlgNode const *)

+ Here is the call graph for this function:

virtual void RelRexDagVisitor::visit ( RelScan const *  )
inlineprotectedvirtual
virtual void RelRexDagVisitor::visit ( RelSort const *  )
inlineprotectedvirtual

Definition at line 54 of file RelRexDagVisitor.h.

54 {}
void RelRexDagVisitor::visit ( RelTableFunction const *  rel_table_function)
protectedvirtual

Definition at line 117 of file RelRexDagVisitor.cpp.

References RelTableFunction::getTableFuncInputAt(), RelTableFunction::getTableFuncInputsSize(), and visit().

117  {
118  for (size_t i = 0; i < rel_table_function->getTableFuncInputsSize(); ++i) {
119  visit(rel_table_function->getTableFuncInputAt(i));
120  }
121 }
virtual void visit(RelAlgNode const *)

+ Here is the call graph for this function:

void RelRexDagVisitor::visit ( RelTranslatedJoin const *  rel_translated_join)
protectedvirtual

Definition at line 123 of file RelRexDagVisitor.cpp.

References RelTranslatedJoin::getLHS(), RelTranslatedJoin::getOuterJoinCond(), RelTranslatedJoin::getRHS(), and visit().

123  {
124  visit(rel_translated_join->getLHS());
125  visit(rel_translated_join->getRHS());
126  if (auto* outer_join_condition = rel_translated_join->getOuterJoinCond()) {
127  visit(outer_join_condition);
128  }
129 }
virtual void visit(RelAlgNode const *)

+ Here is the call graph for this function:

virtual void RelRexDagVisitor::visit ( RexAbstractInput const *  )
inlineprotectedvirtual

Definition at line 58 of file RelRexDagVisitor.h.

58 {}
void RelRexDagVisitor::visit ( RexCase const *  rex_case)
protectedvirtual

Definition at line 168 of file RelRexDagVisitor.cpp.

References RexCase::branchCount(), RexCase::getElse(), RexCase::getThen(), RexCase::getWhen(), and visit().

168  {
169  for (size_t i = 0; i < rex_case->branchCount(); ++i) {
170  visit(rex_case->getWhen(i));
171  visit(rex_case->getThen(i));
172  }
173  if (rex_case->getElse()) {
174  visit(rex_case->getElse());
175  }
176 }
virtual void visit(RelAlgNode const *)

+ Here is the call graph for this function:

void RelRexDagVisitor::visit ( RexFunctionOperator const *  rex_function_operator)
protectedvirtual

Reimplemented in QueryPlanDagChecker.

Definition at line 178 of file RelRexDagVisitor.cpp.

References RexOperator::getOperand(), RexOperator::size(), and visit().

178  {
179  for (size_t i = 0; i < rex_function_operator->size(); ++i) {
180  visit(rex_function_operator->getOperand(i));
181  }
182 }
virtual void visit(RelAlgNode const *)

+ Here is the call graph for this function:

void RelRexDagVisitor::visit ( RexInput const *  rex_input)
protectedvirtual

Definition at line 194 of file RelRexDagVisitor.cpp.

References RexInput::getSourceNode(), and visit().

194  {
195  visit(rex_input->getSourceNode());
196 }
virtual void visit(RelAlgNode const *)

+ Here is the call graph for this function:

virtual void RelRexDagVisitor::visit ( RexLiteral const *  )
inlineprotectedvirtual

Definition at line 62 of file RelRexDagVisitor.h.

62 {}
void RelRexDagVisitor::visit ( RexOperator const *  rex_operator)
protectedvirtual

Reimplemented in QueryPlanDagChecker, and SQLOperatorDetector.

Definition at line 184 of file RelRexDagVisitor.cpp.

References RexOperator::getOperand(), RexOperator::size(), and visit().

184  {
185  for (size_t i = 0; i < rex_operator->size(); ++i) {
186  visit(rex_operator->getOperand(i));
187  }
188 }
virtual void visit(RelAlgNode const *)

+ Here is the call graph for this function:

virtual void RelRexDagVisitor::visit ( RexRef const *  )
inlineprotectedvirtual

Definition at line 64 of file RelRexDagVisitor.h.

64 {}
void RelRexDagVisitor::visit ( RexSubQuery const *  rex_sub_query)
protectedvirtual

Reimplemented in RexSubQueryIdCollector.

Definition at line 190 of file RelRexDagVisitor.cpp.

References visit().

190  {
191  visit(rex_sub_query->getRelAlg());
192 }
virtual void visit(RelAlgNode const *)

+ Here is the call graph for this function:

void RelRexDagVisitor::visit ( RexWindowFunctionOperator const *  rex_window_function_operator)
protectedvirtual

Definition at line 158 of file RelRexDagVisitor.cpp.

References RexWindowFunctionOperator::getOrderKeys(), RexWindowFunctionOperator::getPartitionKeys(), and visit().

159  {
160  for (const auto& partition_key : rex_window_function_operator->getPartitionKeys()) {
161  visit(partition_key.get());
162  }
163  for (const auto& order_key : rex_window_function_operator->getOrderKeys()) {
164  visit(order_key.get());
165  }
166 }
virtual void visit(RelAlgNode const *)

+ Here is the call graph for this function:

Member Data Documentation

Cache RelRexDagVisitor::cache_
private

Definition at line 72 of file RelRexDagVisitor.h.

Referenced by visit().


The documentation for this class was generated from the following files: