OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
anonymous_namespace{RelAlgDag.cpp}::anonymous_namespace{RelAlgDag.cpp} Namespace Reference

Classes

class  RexInputReplacementVisitor
 
class  CoalesceSecondaryProjectVisitor
 

Functions

std::vector< const Rex * > reproject_targets (const RelProject *simple_project, const std::vector< const Rex * > &target_exprs) noexcept
 
bool input_can_be_coalesced (const RelAlgNode *parent_node, const size_t index, const bool first_rex_is_input)
 
bool is_window_function_sum (const RexScalar *rex)
 
bool is_window_function_avg (const RexScalar *rex)
 
bool is_window_function_operator (const RexScalar *rex)
 
void create_rex_input_for_new_project_node (RelAlgNode const *node, std::vector< std::unique_ptr< const RexScalar >> &scalar_exprs, std::vector< std::string > &fields)
 
bool find_generic_expr_in_window_func (RexWindowFunctionOperator const *window_expr, bool &has_generic_expr_in_window_func)
 
std::pair< bool, bool > need_pushdown_generic_expr (RelProject const *window_func_project_node)
 

Function Documentation

void anonymous_namespace{RelAlgDag.cpp}::anonymous_namespace{RelAlgDag.cpp}::create_rex_input_for_new_project_node ( RelAlgNode const *  node,
std::vector< std::unique_ptr< const RexScalar >> &  scalar_exprs,
std::vector< std::string > &  fields 
)

Definition at line 2121 of file RelAlgDag.cpp.

References RelAlgNode::size().

Referenced by anonymous_namespace{RelAlgDag.cpp}::handle_agg_over_join().

2124  {
2125  for (size_t i = 0; i < node->size(); i++) {
2126  auto new_rex_input = std::make_unique<RexInput>(node, i);
2127  scalar_exprs.emplace_back(std::move(new_rex_input));
2128  fields.emplace_back("");
2129  }
2130 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool anonymous_namespace{RelAlgDag.cpp}::anonymous_namespace{RelAlgDag.cpp}::find_generic_expr_in_window_func ( RexWindowFunctionOperator const *  window_expr,
bool &  has_generic_expr_in_window_func 
)

Definition at line 2591 of file RelAlgDag.cpp.

References RexOperator::getOperand(), RexWindowFunctionOperator::getOrderKeys(), RexWindowFunctionOperator::getPartitionKeys(), and RexOperator::size().

Referenced by need_pushdown_generic_expr().

2592  {
2593  for (auto const& partition_key : window_expr->getPartitionKeys()) {
2594  auto partition_input = dynamic_cast<RexInput const*>(partition_key.get());
2595  if (!partition_input) {
2596  return true;
2597  }
2598  }
2599  for (auto const& order_key : window_expr->getOrderKeys()) {
2600  auto order_input = dynamic_cast<RexInput const*>(order_key.get());
2601  if (!order_input) {
2602  return true;
2603  }
2604  }
2605  for (size_t k = 0; k < window_expr->size(); k++) {
2606  if (!shared::dynamic_castable_to_any<RexInput, RexLiteral>(
2607  window_expr->getOperand(k))) {
2608  has_generic_expr_in_window_func = true;
2609  return true;
2610  }
2611  }
2612  return false;
2613 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool anonymous_namespace{RelAlgDag.cpp}::anonymous_namespace{RelAlgDag.cpp}::input_can_be_coalesced ( const RelAlgNode parent_node,
const size_t  index,
const bool  first_rex_is_input 
)

Definition at line 1925 of file RelAlgDag.cpp.

Referenced by anonymous_namespace{RelAlgDag.cpp}::coalesce_nodes(), and anonymous_namespace{RelAlgDag.cpp}::anonymous_namespace{RelAlgDag.cpp}::CoalesceSecondaryProjectVisitor::visitInput().

1927  {
1928  if (auto agg_node = dynamic_cast<const RelAggregate*>(parent_node)) {
1929  if (index == 0 && agg_node->getGroupByCount() > 0) {
1930  return true;
1931  } else {
1932  // Is an aggregated target, only allow the project to be elided if the aggregate
1933  // target is simply passed through (i.e. if the top level expression attached to
1934  // the project node is a RexInput expression)
1935  return first_rex_is_input;
1936  }
1937  }
1938  return first_rex_is_input;
1939 }

+ Here is the caller graph for this function:

bool anonymous_namespace{RelAlgDag.cpp}::anonymous_namespace{RelAlgDag.cpp}::is_window_function_avg ( const RexScalar rex)

Definition at line 1984 of file RelAlgDag.cpp.

References CHECK_EQ, COUNT, RexOperator::getOperand(), RexOperator::getOperator(), is_window_function_sum(), kDIVIDE, and RexOperator::size().

Referenced by is_window_function_operator().

1984  {
1985  const RexOperator* divide_operator = dynamic_cast<const RexOperator*>(rex);
1986  if (divide_operator && divide_operator->getOperator() == kDIVIDE) {
1987  CHECK_EQ(divide_operator->size(), size_t(2));
1988  const auto case_operator =
1989  dynamic_cast<const RexCase*>(divide_operator->getOperand(0));
1990  const auto second_window =
1991  dynamic_cast<const RexWindowFunctionOperator*>(divide_operator->getOperand(1));
1992  if (case_operator && second_window &&
1993  second_window->getKind() == SqlWindowFunctionKind::COUNT) {
1994  if (is_window_function_sum(case_operator)) {
1995  return true;
1996  }
1997  }
1998  }
1999  return false;
2000 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
size_t size() const
Definition: RelAlgDag.h:364
const RexScalar * getOperand(const size_t idx) const
Definition: RelAlgDag.h:366
SQLOps getOperator() const
Definition: RelAlgDag.h:376

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool anonymous_namespace{RelAlgDag.cpp}::anonymous_namespace{RelAlgDag.cpp}::is_window_function_operator ( const RexScalar rex)

Definition at line 2004 of file RelAlgDag.cpp.

References is_window_function_avg(), and is_window_function_sum().

Referenced by RelProject::hasWindowFunctionExpr(), anonymous_namespace{RelAlgDag.cpp}::separate_window_function_expressions(), anonymous_namespace{RelAlgDag.cpp}::WindowFunctionCollector::visitCase(), and anonymous_namespace{RelAlgDag.cpp}::WindowFunctionCollector::visitOperator().

2004  {
2005  return dynamic_cast<const RexWindowFunctionOperator*>(rex) ||
2007 }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool anonymous_namespace{RelAlgDag.cpp}::anonymous_namespace{RelAlgDag.cpp}::is_window_function_sum ( const RexScalar rex)

Definition at line 1970 of file RelAlgDag.cpp.

References SUM_INTERNAL.

Referenced by is_window_function_avg(), and is_window_function_operator().

1970  {
1971  const auto case_operator = dynamic_cast<const RexCase*>(rex);
1972  if (case_operator && case_operator->branchCount() == 1) {
1973  const auto then_window =
1974  dynamic_cast<const RexWindowFunctionOperator*>(case_operator->getThen(0));
1975  if (then_window && then_window->getKind() == SqlWindowFunctionKind::SUM_INTERNAL) {
1976  return true;
1977  }
1978  }
1979  return false;
1980 }

+ Here is the caller graph for this function:

std::pair<bool, bool> anonymous_namespace{RelAlgDag.cpp}::anonymous_namespace{RelAlgDag.cpp}::need_pushdown_generic_expr ( RelProject const *  window_func_project_node)

Definition at line 2615 of file RelAlgDag.cpp.

References CHECK, find_generic_expr_in_window_func(), RelProject::getProjectAt(), run_benchmark_import::res, and RelProject::size().

Referenced by anonymous_namespace{RelAlgDag.cpp}::add_window_function_pre_project().

2616  {
2617  bool has_generic_expr_in_window_func = false;
2618  bool res = false;
2619  for (size_t i = 0; i < window_func_project_node->size(); ++i) {
2620  auto const projected_target = window_func_project_node->getProjectAt(i);
2621  if (auto const* window_expr =
2622  dynamic_cast<RexWindowFunctionOperator const*>(projected_target)) {
2623  res =
2624  find_generic_expr_in_window_func(window_expr, has_generic_expr_in_window_func);
2625  } else if (auto const* case_expr = dynamic_cast<RexCase const*>(projected_target)) {
2626  std::unordered_map<size_t, const RexScalar*> collected_window_func;
2627  WindowFunctionCollector collector(collected_window_func, true);
2628  collector.visit(case_expr);
2629  for (auto const& kv : collected_window_func) {
2630  auto const* candidate_window_expr =
2631  dynamic_cast<RexWindowFunctionOperator const*>(kv.second);
2632  CHECK(candidate_window_expr);
2633  res = find_generic_expr_in_window_func(candidate_window_expr,
2634  has_generic_expr_in_window_func);
2635  }
2636  }
2637  }
2638  return std::make_pair(has_generic_expr_in_window_func, res);
2639 }
bool find_generic_expr_in_window_func(RexWindowFunctionOperator const *window_expr, bool &has_generic_expr_in_window_func)
Definition: RelAlgDag.cpp:2591
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::vector<const Rex*> anonymous_namespace{RelAlgDag.cpp}::anonymous_namespace{RelAlgDag.cpp}::reproject_targets ( const RelProject simple_project,
const std::vector< const Rex * > &  target_exprs 
)
noexcept

Definition at line 1642 of file RelAlgDag.cpp.

References CHECK, CHECK_LT, and run_benchmark_import::result.

Referenced by anonymous_namespace{RelAlgDag.cpp}::create_compound().

1644  {
1645  std::vector<const Rex*> result;
1646  for (size_t i = 0; i < simple_project->size(); ++i) {
1647  const auto input_rex = dynamic_cast<const RexInput*>(simple_project->getProjectAt(i));
1648  CHECK(input_rex);
1649  CHECK_LT(static_cast<size_t>(input_rex->getIndex()), target_exprs.size());
1650  result.push_back(target_exprs[input_rex->getIndex()]);
1651  }
1652  return result;
1653 }
size_t size() const override
Definition: RelAlgDag.h:1320
const RexScalar * getProjectAt(const size_t idx) const
Definition: RelAlgDag.h:1352
#define CHECK_LT(x, y)
Definition: Logger.h:303
#define CHECK(condition)
Definition: Logger.h:291

+ Here is the caller graph for this function: