OmniSciDB  085a039ca4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
anonymous_namespace{RelAlgDagBuilder.cpp}::RexWindowFuncReplacementVisitor Class Reference
+ Inheritance diagram for anonymous_namespace{RelAlgDagBuilder.cpp}::RexWindowFuncReplacementVisitor:
+ Collaboration diagram for anonymous_namespace{RelAlgDagBuilder.cpp}::RexWindowFuncReplacementVisitor:

Public Member Functions

 RexWindowFuncReplacementVisitor (std::unordered_set< size_t > &collected_window_func_hash, std::vector< std::unique_ptr< const RexScalar >> &new_rex_input_for_window_func, std::unordered_map< size_t, size_t > &window_func_to_new_rex_input_idx_map, RelProject *new_project, std::unordered_map< size_t, std::unique_ptr< const RexInput >> &new_rex_input_from_child_node)
 
- Public Member Functions inherited from RexVisitorBase< std::unique_ptr< const RexScalar > >
virtual std::unique_ptr< const
RexScalar
visit (const RexScalar *rex_scalar) const
 

Protected Member Functions

RetType visitInput (const RexInput *rex_input) const final
 
RetType visitOperator (const RexOperator *rex_operator) const final
 
RetType visitCase (const RexCase *rex_case) const final
 
- Protected Member Functions inherited from RexDeepCopyVisitor
RetType visitInput (const RexInput *input) const override
 
RetType visitLiteral (const RexLiteral *literal) const override
 
RetType visitSubQuery (const RexSubQuery *subquery) const override
 
RetType visitRef (const RexRef *ref) const override
 
RetType visitOperator (const RexOperator *rex_operator) const override
 
RetType visitWindowFunctionOperator (const RexWindowFunctionOperator *rex_window_function_operator) const
 
RetType visitCase (const RexCase *rex_case) const override
 

Private Member Functions

std::optional< size_t > is_collected_window_function (size_t rex_hash) const
 
std::unique_ptr< const RexScalarget_new_rex_input (size_t rex_idx) const
 

Private Attributes

std::unordered_set< size_t > & collected_window_func_hash_
 
std::vector< std::unique_ptr
< const RexScalar > > & 
new_rex_input_for_window_func_
 
std::unordered_map< size_t,
size_t > & 
window_func_to_new_rex_input_idx_map_
 
RelProjectnew_project_
 
std::unordered_map< size_t,
std::unique_ptr< const
RexInput > > & 
new_rex_input_from_child_node_
 
RexDeepCopyVisitor copier_
 

Additional Inherited Members

- Public Types inherited from RexDeepCopyVisitor
using RowValues = std::vector< std::unique_ptr< const RexScalar >>
 
- Static Public Member Functions inherited from RexDeepCopyVisitor
static std::vector< RowValuescopy (std::vector< RowValues > const &rhs)
 
- Protected Types inherited from RexDeepCopyVisitor
using RetType = std::unique_ptr< const RexScalar >
 

Detailed Description

Definition at line 2080 of file RelAlgDagBuilder.cpp.

Constructor & Destructor Documentation

anonymous_namespace{RelAlgDagBuilder.cpp}::RexWindowFuncReplacementVisitor::RexWindowFuncReplacementVisitor ( std::unordered_set< size_t > &  collected_window_func_hash,
std::vector< std::unique_ptr< const RexScalar >> &  new_rex_input_for_window_func,
std::unordered_map< size_t, size_t > &  window_func_to_new_rex_input_idx_map,
RelProject new_project,
std::unordered_map< size_t, std::unique_ptr< const RexInput >> &  new_rex_input_from_child_node 
)
inline

Definition at line 2082 of file RelAlgDagBuilder.cpp.

References CHECK, CHECK_EQ, and CHECK_LT.

2089  : collected_window_func_hash_(collected_window_func_hash)
2090  , new_rex_input_for_window_func_(new_rex_input_for_window_func)
2091  , window_func_to_new_rex_input_idx_map_(window_func_to_new_rex_input_idx_map)
2092  , new_project_(new_project)
2093  , new_rex_input_from_child_node_(new_rex_input_from_child_node) {
2096  for (auto hash : collected_window_func_hash_) {
2097  auto rex_it = window_func_to_new_rex_input_idx_map_.find(hash);
2099  CHECK_LT(rex_it->second, new_rex_input_for_window_func_.size());
2100  }
2102  }
#define CHECK_EQ(x, y)
Definition: Logger.h:231
std::unordered_map< size_t, std::unique_ptr< const RexInput > > & new_rex_input_from_child_node_
#define CHECK_LT(x, y)
Definition: Logger.h:233
#define CHECK(condition)
Definition: Logger.h:223
std::vector< std::unique_ptr< const RexScalar > > & new_rex_input_for_window_func_

Member Function Documentation

std::unique_ptr<const RexScalar> anonymous_namespace{RelAlgDagBuilder.cpp}::RexWindowFuncReplacementVisitor::get_new_rex_input ( size_t  rex_idx) const
inlineprivate

Definition at line 2195 of file RelAlgDagBuilder.cpp.

References CHECK, CHECK_GE, and CHECK_LT.

2195  {
2196  CHECK_GE(rex_idx, 0UL);
2197  CHECK_LT(rex_idx, new_rex_input_for_window_func_.size());
2198  auto& new_rex_input = new_rex_input_for_window_func_.at(rex_idx);
2199  CHECK(new_rex_input);
2200  auto copied_rex_input = copier_.visit(new_rex_input.get());
2201  return copied_rex_input;
2202  }
#define CHECK_GE(x, y)
Definition: Logger.h:236
virtual T visit(const RexScalar *rex_scalar) const
Definition: RexVisitor.h:27
#define CHECK_LT(x, y)
Definition: Logger.h:233
#define CHECK(condition)
Definition: Logger.h:223
std::vector< std::unique_ptr< const RexScalar > > & new_rex_input_for_window_func_
std::optional<size_t> anonymous_namespace{RelAlgDagBuilder.cpp}::RexWindowFuncReplacementVisitor::is_collected_window_function ( size_t  rex_hash) const
inlineprivate

Definition at line 2187 of file RelAlgDagBuilder.cpp.

2187  {
2188  auto rex_it = window_func_to_new_rex_input_idx_map_.find(rex_hash);
2189  if (rex_it != window_func_to_new_rex_input_idx_map_.end()) {
2190  return rex_it->second;
2191  }
2192  return std::nullopt;
2193  }
RetType anonymous_namespace{RelAlgDagBuilder.cpp}::RexWindowFuncReplacementVisitor::visitCase ( const RexCase rex_case) const
inlinefinalprotectedvirtual

Implements RexVisitorBase< std::unique_ptr< const RexScalar > >.

Definition at line 2156 of file RelAlgDagBuilder.cpp.

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

2156  {
2157  auto new_rex_idx = is_collected_window_function(rex_case->toHash());
2158  if (new_rex_idx) {
2159  return get_new_rex_input(*new_rex_idx);
2160  }
2161 
2162  std::vector<std::pair<RetType, RetType>> new_pair_list;
2163  for (size_t i = 0; i < rex_case->branchCount(); ++i) {
2164  auto when_operand = rex_case->getWhen(i);
2165  auto new_rex_idx_for_when_operand =
2166  is_collected_window_function(when_operand->toHash());
2167 
2168  auto then_operand = rex_case->getThen(i);
2169  auto new_rex_idx_for_then_operand =
2170  is_collected_window_function(then_operand->toHash());
2171 
2172  new_pair_list.emplace_back(
2173  new_rex_idx_for_when_operand ? get_new_rex_input(*new_rex_idx_for_when_operand)
2174  : visit(when_operand),
2175  new_rex_idx_for_then_operand ? get_new_rex_input(*new_rex_idx_for_then_operand)
2176  : visit(then_operand));
2177  }
2178  auto new_rex_idx_for_else_operand =
2180  auto new_else = new_rex_idx_for_else_operand
2181  ? get_new_rex_input(*new_rex_idx_for_else_operand)
2182  : visit(rex_case->getElse());
2183  return std::make_unique<RexCase>(new_pair_list, new_else);
2184  }
const RexScalar * getThen(const size_t idx) const
const RexScalar * getElse() const
const RexScalar * getWhen(const size_t idx) const
virtual std::unique_ptr< const RexScalar > visit(const RexScalar *rex_scalar) const
Definition: RexVisitor.h:27
std::unique_ptr< const RexScalar > get_new_rex_input(size_t rex_idx) const
size_t branchCount() const
size_t toHash() const override
virtual size_t toHash() const =0
std::optional< size_t > is_collected_window_function(size_t rex_hash) const

+ Here is the call graph for this function:

RetType anonymous_namespace{RelAlgDagBuilder.cpp}::RexWindowFuncReplacementVisitor::visitInput ( const RexInput rex_input) const
inlinefinalprotectedvirtual

Implements RexVisitorBase< std::unique_ptr< const RexScalar > >.

Definition at line 2105 of file RelAlgDagBuilder.cpp.

2105  {
2106  if (rex_input->getSourceNode() != new_project_) {
2107  const auto cur_index = rex_input->getIndex();
2108  auto cur_source_node = rex_input->getSourceNode();
2109  std::string field_name = "";
2110  if (auto cur_project_node = dynamic_cast<const RelProject*>(cur_source_node)) {
2111  field_name = cur_project_node->getFieldName(cur_index);
2112  }
2113  auto rex_input_hash = rex_input->toHash();
2114  auto rex_input_it = new_rex_input_from_child_node_.find(rex_input_hash);
2115  if (rex_input_it == new_rex_input_from_child_node_.end()) {
2116  auto new_rex_input =
2117  std::make_unique<RexInput>(new_project_, new_project_->size());
2118  new_project_->appendInput(field_name, rex_input->deepCopy());
2119  new_rex_input_from_child_node_.emplace(rex_input_hash, new_rex_input->deepCopy());
2120  return new_rex_input;
2121  } else {
2122  return rex_input_it->second->deepCopy();
2123  }
2124  } else {
2125  return rex_input->deepCopy();
2126  }
2127  }
size_t size() const override
size_t toHash() const override
unsigned getIndex() const
std::unordered_map< size_t, std::unique_ptr< const RexInput > > & new_rex_input_from_child_node_
std::unique_ptr< RexInput > deepCopy() const
const RelAlgNode * getSourceNode() const
RetType anonymous_namespace{RelAlgDagBuilder.cpp}::RexWindowFuncReplacementVisitor::visitOperator ( const RexOperator rex_operator) const
inlinefinalprotectedvirtual

Implements RexVisitorBase< std::unique_ptr< const RexScalar > >.

Definition at line 2129 of file RelAlgDagBuilder.cpp.

2129  {
2130  auto new_rex_idx = is_collected_window_function(rex_operator->toHash());
2131  if (new_rex_idx) {
2132  return get_new_rex_input(*new_rex_idx);
2133  }
2134 
2135  const auto rex_window_function_operator =
2136  dynamic_cast<const RexWindowFunctionOperator*>(rex_operator);
2137  if (rex_window_function_operator) {
2138  // Deep copy the embedded window function operator
2139  return visitWindowFunctionOperator(rex_window_function_operator);
2140  }
2141 
2142  const size_t operand_count = rex_operator->size();
2143  std::vector<RetType> new_opnds;
2144  for (size_t i = 0; i < operand_count; ++i) {
2145  const auto operand = rex_operator->getOperand(i);
2146  auto new_rex_idx_for_operand = is_collected_window_function(operand->toHash());
2147  if (new_rex_idx_for_operand) {
2148  new_opnds.push_back(get_new_rex_input(*new_rex_idx_for_operand));
2149  } else {
2150  new_opnds.emplace_back(visit(rex_operator->getOperand(i)));
2151  }
2152  }
2153  return rex_operator->getDisambiguated(new_opnds);
2154  }
size_t size() const
const RexScalar * getOperand(const size_t idx) const
RetType visitWindowFunctionOperator(const RexWindowFunctionOperator *rex_window_function_operator) const
Definition: RexVisitor.h:169
virtual std::unique_ptr< const RexOperator > getDisambiguated(std::vector< std::unique_ptr< const RexScalar >> &operands) const
virtual std::unique_ptr< const RexScalar > visit(const RexScalar *rex_scalar) const
Definition: RexVisitor.h:27
std::unique_ptr< const RexScalar > get_new_rex_input(size_t rex_idx) const
size_t toHash() const override
std::optional< size_t > is_collected_window_function(size_t rex_hash) const

Member Data Documentation

std::unordered_set<size_t>& anonymous_namespace{RelAlgDagBuilder.cpp}::RexWindowFuncReplacementVisitor::collected_window_func_hash_
private

Definition at line 2204 of file RelAlgDagBuilder.cpp.

RexDeepCopyVisitor anonymous_namespace{RelAlgDagBuilder.cpp}::RexWindowFuncReplacementVisitor::copier_
private

Definition at line 2212 of file RelAlgDagBuilder.cpp.

RelProject* anonymous_namespace{RelAlgDagBuilder.cpp}::RexWindowFuncReplacementVisitor::new_project_
private

Definition at line 2209 of file RelAlgDagBuilder.cpp.

std::vector<std::unique_ptr<const RexScalar> >& anonymous_namespace{RelAlgDagBuilder.cpp}::RexWindowFuncReplacementVisitor::new_rex_input_for_window_func_
private

Definition at line 2206 of file RelAlgDagBuilder.cpp.

std::unordered_map<size_t, std::unique_ptr<const RexInput> >& anonymous_namespace{RelAlgDagBuilder.cpp}::RexWindowFuncReplacementVisitor::new_rex_input_from_child_node_
private

Definition at line 2211 of file RelAlgDagBuilder.cpp.

std::unordered_map<size_t, size_t>& anonymous_namespace{RelAlgDagBuilder.cpp}::RexWindowFuncReplacementVisitor::window_func_to_new_rex_input_idx_map_
private

Definition at line 2208 of file RelAlgDagBuilder.cpp.


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