OmniSciDB  a987f07e93
 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)
 
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

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 2501 of file RelAlgDag.cpp.

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

Referenced by need_pushdown_generic_expr().

2502  {
2503  for (auto const& partition_key : window_expr->getPartitionKeys()) {
2504  auto partition_input = dynamic_cast<RexInput const*>(partition_key.get());
2505  if (!partition_input) {
2506  return true;
2507  }
2508  }
2509  for (auto const& order_key : window_expr->getOrderKeys()) {
2510  auto order_input = dynamic_cast<RexInput const*>(order_key.get());
2511  if (!order_input) {
2512  return true;
2513  }
2514  }
2515  for (size_t k = 0; k < window_expr->size(); k++) {
2516  if (!shared::dynamic_castable_to_any<RexInput, RexLiteral>(
2517  window_expr->getOperand(k))) {
2518  has_generic_expr_in_window_func = true;
2519  return true;
2520  }
2521  }
2522  return false;
2523 }

+ 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 1899 of file RelAlgDag.cpp.

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

1901  {
1902  if (auto agg_node = dynamic_cast<const RelAggregate*>(parent_node)) {
1903  if (index == 0 && agg_node->getGroupByCount() > 0) {
1904  return true;
1905  } else {
1906  // Is an aggregated target, only allow the project to be elided if the aggregate
1907  // target is simply passed through (i.e. if the top level expression attached to
1908  // the project node is a RexInput expression)
1909  return first_rex_is_input;
1910  }
1911  }
1912  return first_rex_is_input;
1913 }

+ 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 1958 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().

1958  {
1959  const RexOperator* divide_operator = dynamic_cast<const RexOperator*>(rex);
1960  if (divide_operator && divide_operator->getOperator() == kDIVIDE) {
1961  CHECK_EQ(divide_operator->size(), size_t(2));
1962  const auto case_operator =
1963  dynamic_cast<const RexCase*>(divide_operator->getOperand(0));
1964  const auto second_window =
1965  dynamic_cast<const RexWindowFunctionOperator*>(divide_operator->getOperand(1));
1966  if (case_operator && second_window &&
1967  second_window->getKind() == SqlWindowFunctionKind::COUNT) {
1968  if (is_window_function_sum(case_operator)) {
1969  return true;
1970  }
1971  }
1972  }
1973  return false;
1974 }
#define CHECK_EQ(x, y)
Definition: Logger.h:297
size_t size() const
Definition: RelAlgDag.h:270
const RexScalar * getOperand(const size_t idx) const
Definition: RelAlgDag.h:272
SQLOps getOperator() const
Definition: RelAlgDag.h:282

+ 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 1978 of file RelAlgDag.cpp.

References CHECK_EQ, is_window_function_avg(), is_window_function_sum(), and kCAST.

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().

1978  {
1979  if (dynamic_cast<const RexWindowFunctionOperator*>(rex)) {
1980  return true;
1981  }
1982 
1983  // unwrap from casts, if they exist
1984  const auto rex_cast = dynamic_cast<const RexOperator*>(rex);
1985  if (rex_cast && rex_cast->getOperator() == kCAST) {
1986  CHECK_EQ(rex_cast->size(), size_t(1));
1987  return is_window_function_operator(rex_cast->getOperand(0));
1988  }
1989 
1991  return true;
1992  }
1993 
1994  return false;
1995 }
#define CHECK_EQ(x, y)
Definition: Logger.h:297
Definition: sqldefs.h:48

+ 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 1944 of file RelAlgDag.cpp.

References SUM_INTERNAL.

Referenced by is_window_function_avg(), and is_window_function_operator().

1944  {
1945  const auto case_operator = dynamic_cast<const RexCase*>(rex);
1946  if (case_operator && case_operator->branchCount() == 1) {
1947  const auto then_window =
1948  dynamic_cast<const RexWindowFunctionOperator*>(case_operator->getThen(0));
1949  if (then_window && then_window->getKind() == SqlWindowFunctionKind::SUM_INTERNAL) {
1950  return true;
1951  }
1952  }
1953  return false;
1954 }

+ 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 2525 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().

2526  {
2527  bool has_generic_expr_in_window_func = false;
2528  bool res = false;
2529  for (size_t i = 0; i < window_func_project_node->size(); ++i) {
2530  auto const projected_target = window_func_project_node->getProjectAt(i);
2531  if (auto const* window_expr =
2532  dynamic_cast<RexWindowFunctionOperator const*>(projected_target)) {
2533  res =
2534  find_generic_expr_in_window_func(window_expr, has_generic_expr_in_window_func);
2535  } else if (auto const* case_expr = dynamic_cast<RexCase const*>(projected_target)) {
2536  std::unordered_map<size_t, const RexScalar*> collected_window_func;
2537  WindowFunctionCollector collector(collected_window_func, true);
2538  collector.visit(case_expr);
2539  for (auto const& kv : collected_window_func) {
2540  auto const* candidate_window_expr =
2541  dynamic_cast<RexWindowFunctionOperator const*>(kv.second);
2542  CHECK(candidate_window_expr);
2543  res = find_generic_expr_in_window_func(candidate_window_expr,
2544  has_generic_expr_in_window_func);
2545  }
2546  }
2547  }
2548  return std::make_pair(has_generic_expr_in_window_func, res);
2549 }
bool find_generic_expr_in_window_func(RexWindowFunctionOperator const *window_expr, bool &has_generic_expr_in_window_func)
Definition: RelAlgDag.cpp:2501
#define CHECK(condition)
Definition: Logger.h:289

+ 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 1617 of file RelAlgDag.cpp.

References CHECK, CHECK_LT, and run_benchmark_import::result.

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

1619  {
1620  std::vector<const Rex*> result;
1621  for (size_t i = 0; i < simple_project->size(); ++i) {
1622  const auto input_rex = dynamic_cast<const RexInput*>(simple_project->getProjectAt(i));
1623  CHECK(input_rex);
1624  CHECK_LT(static_cast<size_t>(input_rex->getIndex()), target_exprs.size());
1625  result.push_back(target_exprs[input_rex->getIndex()]);
1626  }
1627  return result;
1628 }
size_t size() const override
Definition: RelAlgDag.h:1156
const RexScalar * getProjectAt(const size_t idx) const
Definition: RelAlgDag.h:1186
#define CHECK_LT(x, y)
Definition: Logger.h:299
#define CHECK(condition)
Definition: Logger.h:289

+ Here is the caller graph for this function: