OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
anonymous_namespace{RelAlgDag.cpp}::RexWindowFuncReplacementVisitor Class Reference
+ Inheritance diagram for anonymous_namespace{RelAlgDag.cpp}::RexWindowFuncReplacementVisitor:
+ Collaboration diagram for anonymous_namespace{RelAlgDag.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 2280 of file RelAlgDag.cpp.

Constructor & Destructor Documentation

anonymous_namespace{RelAlgDag.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 2282 of file RelAlgDag.cpp.

References CHECK, CHECK_EQ, and CHECK_LT.

2289  : collected_window_func_hash_(collected_window_func_hash)
2290  , new_rex_input_for_window_func_(new_rex_input_for_window_func)
2291  , window_func_to_new_rex_input_idx_map_(window_func_to_new_rex_input_idx_map)
2292  , new_project_(new_project)
2293  , new_rex_input_from_child_node_(new_rex_input_from_child_node) {
2296  for (auto hash : collected_window_func_hash_) {
2297  auto rex_it = window_func_to_new_rex_input_idx_map_.find(hash);
2299  CHECK_LT(rex_it->second, new_rex_input_for_window_func_.size());
2300  }
2302  }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
std::vector< std::unique_ptr< const RexScalar > > & new_rex_input_for_window_func_
Definition: RelAlgDag.cpp:2406
std::unordered_map< size_t, std::unique_ptr< const RexInput > > & new_rex_input_from_child_node_
Definition: RelAlgDag.cpp:2411
#define CHECK_LT(x, y)
Definition: Logger.h:303
#define CHECK(condition)
Definition: Logger.h:291
std::unordered_map< size_t, size_t > & window_func_to_new_rex_input_idx_map_
Definition: RelAlgDag.cpp:2408

Member Function Documentation

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

Definition at line 2395 of file RelAlgDag.cpp.

References CHECK, CHECK_GE, and CHECK_LT.

2395  {
2396  CHECK_GE(rex_idx, 0UL);
2397  CHECK_LT(rex_idx, new_rex_input_for_window_func_.size());
2398  auto& new_rex_input = new_rex_input_for_window_func_.at(rex_idx);
2399  CHECK(new_rex_input);
2400  auto copied_rex_input = copier_.visit(new_rex_input.get());
2401  return copied_rex_input;
2402  }
#define CHECK_GE(x, y)
Definition: Logger.h:306
std::vector< std::unique_ptr< const RexScalar > > & new_rex_input_for_window_func_
Definition: RelAlgDag.cpp:2406
virtual T visit(const RexScalar *rex_scalar) const
Definition: RexVisitor.h:27
#define CHECK_LT(x, y)
Definition: Logger.h:303
#define CHECK(condition)
Definition: Logger.h:291
std::optional<size_t> anonymous_namespace{RelAlgDag.cpp}::RexWindowFuncReplacementVisitor::is_collected_window_function ( size_t  rex_hash) const
inlineprivate

Definition at line 2387 of file RelAlgDag.cpp.

2387  {
2388  auto rex_it = window_func_to_new_rex_input_idx_map_.find(rex_hash);
2389  if (rex_it != window_func_to_new_rex_input_idx_map_.end()) {
2390  return rex_it->second;
2391  }
2392  return std::nullopt;
2393  }
std::unordered_map< size_t, size_t > & window_func_to_new_rex_input_idx_map_
Definition: RelAlgDag.cpp:2408
RetType anonymous_namespace{RelAlgDag.cpp}::RexWindowFuncReplacementVisitor::visitCase ( const RexCase rex_case) const
inlinefinalprotectedvirtual

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

Definition at line 2356 of file RelAlgDag.cpp.

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

2356  {
2357  auto new_rex_idx = is_collected_window_function(rex_case->toHash());
2358  if (new_rex_idx) {
2359  return get_new_rex_input(*new_rex_idx);
2360  }
2361 
2362  std::vector<std::pair<RetType, RetType>> new_pair_list;
2363  for (size_t i = 0; i < rex_case->branchCount(); ++i) {
2364  auto when_operand = rex_case->getWhen(i);
2365  auto new_rex_idx_for_when_operand =
2366  is_collected_window_function(when_operand->toHash());
2367 
2368  auto then_operand = rex_case->getThen(i);
2369  auto new_rex_idx_for_then_operand =
2370  is_collected_window_function(then_operand->toHash());
2371 
2372  new_pair_list.emplace_back(
2373  new_rex_idx_for_when_operand ? get_new_rex_input(*new_rex_idx_for_when_operand)
2374  : visit(when_operand),
2375  new_rex_idx_for_then_operand ? get_new_rex_input(*new_rex_idx_for_then_operand)
2376  : visit(then_operand));
2377  }
2378  auto new_rex_idx_for_else_operand =
2380  auto new_else = new_rex_idx_for_else_operand
2381  ? get_new_rex_input(*new_rex_idx_for_else_operand)
2382  : visit(rex_case->getElse());
2383  return std::make_unique<RexCase>(new_pair_list, new_else);
2384  }
std::optional< size_t > is_collected_window_function(size_t rex_hash) const
Definition: RelAlgDag.cpp:2387
const RexScalar * getThen(const size_t idx) const
Definition: RelAlgDag.h:440
const RexScalar * getElse() const
Definition: RelAlgDag.h:445
std::unique_ptr< const RexScalar > get_new_rex_input(size_t rex_idx) const
Definition: RelAlgDag.cpp:2395
const RexScalar * getWhen(const size_t idx) const
Definition: RelAlgDag.h:435
virtual std::unique_ptr< const RexScalar > visit(const RexScalar *rex_scalar) const
Definition: RexVisitor.h:27
virtual size_t toHash() const override
Definition: RelAlgDag.h:461
size_t branchCount() const
Definition: RelAlgDag.h:433
virtual size_t toHash() const =0

+ Here is the call graph for this function:

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

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

Definition at line 2305 of file RelAlgDag.cpp.

2305  {
2306  if (rex_input->getSourceNode() != new_project_) {
2307  const auto cur_index = rex_input->getIndex();
2308  auto cur_source_node = rex_input->getSourceNode();
2309  std::string field_name = "";
2310  if (auto cur_project_node = dynamic_cast<const RelProject*>(cur_source_node)) {
2311  field_name = cur_project_node->getFieldName(cur_index);
2312  }
2313  auto rex_input_hash = rex_input->toHash();
2314  auto rex_input_it = new_rex_input_from_child_node_.find(rex_input_hash);
2315  if (rex_input_it == new_rex_input_from_child_node_.end()) {
2316  auto new_rex_input =
2317  std::make_unique<RexInput>(new_project_, new_project_->size());
2318  new_project_->appendInput(field_name, rex_input->deepCopy());
2319  new_rex_input_from_child_node_.emplace(rex_input_hash, new_rex_input->deepCopy());
2320  return new_rex_input;
2321  } else {
2322  return rex_input_it->second->deepCopy();
2323  }
2324  } else {
2325  return rex_input->deepCopy();
2326  }
2327  }
size_t size() const override
Definition: RelAlgDag.h:1320
unsigned getIndex() const
Definition: RelAlgDag.h:174
std::unordered_map< size_t, std::unique_ptr< const RexInput > > & new_rex_input_from_child_node_
Definition: RelAlgDag.cpp:2411
std::unique_ptr< RexInput > deepCopy() const
Definition: RelAlgDag.h:1070
const RelAlgNode * getSourceNode() const
Definition: RelAlgDag.h:1056
virtual size_t toHash() const override
Definition: RelAlgDag.h:1074
RetType anonymous_namespace{RelAlgDag.cpp}::RexWindowFuncReplacementVisitor::visitOperator ( const RexOperator rex_operator) const
inlinefinalprotectedvirtual

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

Definition at line 2329 of file RelAlgDag.cpp.

2329  {
2330  auto new_rex_idx = is_collected_window_function(rex_operator->toHash());
2331  if (new_rex_idx) {
2332  return get_new_rex_input(*new_rex_idx);
2333  }
2334 
2335  const auto rex_window_function_operator =
2336  dynamic_cast<const RexWindowFunctionOperator*>(rex_operator);
2337  if (rex_window_function_operator) {
2338  // Deep copy the embedded window function operator
2339  return visitWindowFunctionOperator(rex_window_function_operator);
2340  }
2341 
2342  const size_t operand_count = rex_operator->size();
2343  std::vector<RetType> new_opnds;
2344  for (size_t i = 0; i < operand_count; ++i) {
2345  const auto operand = rex_operator->getOperand(i);
2346  auto new_rex_idx_for_operand = is_collected_window_function(operand->toHash());
2347  if (new_rex_idx_for_operand) {
2348  new_opnds.push_back(get_new_rex_input(*new_rex_idx_for_operand));
2349  } else {
2350  new_opnds.emplace_back(visit(rex_operator->getOperand(i)));
2351  }
2352  }
2353  return rex_operator->getDisambiguated(new_opnds);
2354  }
std::optional< size_t > is_collected_window_function(size_t rex_hash) const
Definition: RelAlgDag.cpp:2387
std::unique_ptr< const RexScalar > get_new_rex_input(size_t rex_idx) const
Definition: RelAlgDag.cpp:2395
size_t size() const
Definition: RelAlgDag.h:364
const RexScalar * getOperand(const size_t idx) const
Definition: RelAlgDag.h:366
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
Definition: RelAlgDag.h:359
virtual std::unique_ptr< const RexScalar > visit(const RexScalar *rex_scalar) const
Definition: RexVisitor.h:27
virtual size_t toHash() const override
Definition: RelAlgDag.h:394

Member Data Documentation

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

Definition at line 2404 of file RelAlgDag.cpp.

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

Definition at line 2412 of file RelAlgDag.cpp.

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

Definition at line 2409 of file RelAlgDag.cpp.

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

Definition at line 2406 of file RelAlgDag.cpp.

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

Definition at line 2411 of file RelAlgDag.cpp.

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

Definition at line 2408 of file RelAlgDag.cpp.


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